显示时如何使子链接/文本水平?
我有一个带有下拉菜单的导航栏,运行良好。我唯一想要改变的是,当您将鼠标悬停在主链接上时,子链接/文本相互重叠。我希望它们水平显示。我尝试过各种浮动和内联显示等...
这是 HTML 的一部分:
<ul id="top_main_nav" style="float:left;">
<li><a href="Profile.php?id=<?php echo $auth->id; ?>">Me</a>
<ul>
<li><a href="Profile.php?id=<?php echo $auth->id; ?>"><?php echo ($auth->first_name); ?> <?php if(strlen($auth->last_name) > 6) { echo substr(strtoupper($auth->last_name),0,6) . "..."; }else{ echo ($auth->last_name); } ?></a></li>
<li><a href="EditProfile.php">Edit My Profile</a></li>
<li><a href="MySettings.php">Settings</a></li>
<li><a href="EmailSettings.php">Email Settings</a></li>
</ul>
</li>
</ul>
这是 css:
#user_nav_future {
margin: 0 auto;
font: bold 12px Arial,Helvetica, sans-serif;
color: #fff;
}
#user_nav_future ul li {
list-style: none;
float: left;
}
#user_nav_future ul li a {
color: #fff;
padding: 10px;
display: block;
text-decoration: none;
}
#user_nav_future li ul {
display: none;
position: absolute;
top: 35px;
right: 160px;
z-index: 1001;
margin: 0;
padding: 0;
}
#user_nav_future li ul a {
color: #666;
display: inline;
float: left;
}
#user_nav_future ul li a:hover {
color: #FF4800;
}
#user_nav_future ul {
padding:0;
margin:0;
list-style:none;
}
#user_nav_future li {
float:left;
position:relative;
text-align:center;
}
#user_nav_future li ul {
display:none;
position:absolute;
top:34px;
left:0;
}
#user_nav_future li ul li {
width:160px;
}
#user_nav_future li:hover ul,#user_nav li.over ul {
display:block;
}
I have a nav bar with a drop down that is working beautifully. The only thing I am trying to change, is when you hover over the main links, the sub-links/text are on top of eachother. I want them to display horizontally. I have tried all sorts of floats and display inline etc...
Here is a portion of the HTML:
<ul id="top_main_nav" style="float:left;">
<li><a href="Profile.php?id=<?php echo $auth->id; ?>">Me</a>
<ul>
<li><a href="Profile.php?id=<?php echo $auth->id; ?>"><?php echo ($auth->first_name); ?> <?php if(strlen($auth->last_name) > 6) { echo substr(strtoupper($auth->last_name),0,6) . "..."; }else{ echo ($auth->last_name); } ?></a></li>
<li><a href="EditProfile.php">Edit My Profile</a></li>
<li><a href="MySettings.php">Settings</a></li>
<li><a href="EmailSettings.php">Email Settings</a></li>
</ul>
</li>
</ul>
Here is the css:
#user_nav_future {
margin: 0 auto;
font: bold 12px Arial,Helvetica, sans-serif;
color: #fff;
}
#user_nav_future ul li {
list-style: none;
float: left;
}
#user_nav_future ul li a {
color: #fff;
padding: 10px;
display: block;
text-decoration: none;
}
#user_nav_future li ul {
display: none;
position: absolute;
top: 35px;
right: 160px;
z-index: 1001;
margin: 0;
padding: 0;
}
#user_nav_future li ul a {
color: #666;
display: inline;
float: left;
}
#user_nav_future ul li a:hover {
color: #FF4800;
}
#user_nav_future ul {
padding:0;
margin:0;
list-style:none;
}
#user_nav_future li {
float:left;
position:relative;
text-align:center;
}
#user_nav_future li ul {
display:none;
position:absolute;
top:34px;
left:0;
}
#user_nav_future li ul li {
width:160px;
}
#user_nav_future li:hover ul,#user_nav li.over ul {
display:block;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些更改应该可以解决问题:
他们正在做的是设置所有导致下拉菜单向下移动的内联元素,以便菜单是水平的。
我还将定位控制转移到
元素。这样,链接的整个区域都可以单击,而不仅仅是文本。
如果上述方法对您不起作用,请发布一些 HTML 或开发链接,以便我们了解发生了什么情况。
These changes should do the trick:
What they're doing is setting all the block elements that are causing your drop downs to go down to inline elements that float so the menu is horizontal.
I've also transferred positioning control over to the
<a>
elements. That way the entire area of the link will be clickable, rather than just the text.If the above doesn't work for you, post some of your HTML or a dev link so we can see what's going on.