如何在没有额外 div 的情况下实现浮动/对齐?
我试图获得一个导航栏,其中包含一个导航栏,其中有一个无序列表,以与页面宽度的右侧对齐。导航本身应该跨越整个宽度(它是横跨整个页面的黑条),但链接本身应该与内容宽度的右侧对齐,如下所示:
| home | about | etc. |
| |
| This is content with a fixed with in the center |
| of the page. |
我有的 HTML:
<nav>
<ul id="navlist">
<li><a href="#">Home</a></li>
<li><a href="#">about</a></li>
<li><a href="#">etc,</a></li>
</ul>
</nav>
CSS:
nav {
display:block;
background:#000;
}
nav ul {
margin: 0 auto;
width: 777px;
}
nav ul li {
float:left;
}
但当然这是在左侧页面的一侧,如果不添加额外的 div 元素,我似乎无法将其移至右侧...唯一的选择是将
有人吗?
I'm trying to get a navigation bar that consists of a nav with an unordered list in it to align to the right side of the page's width. The nav itself should span the entire width (it's a black bar across the entire page) but the links itself should be aligned to the right of the contents width, like so:
| home | about | etc. |
| |
| This is content with a fixed with in the center |
| of the page. |
The HTML I have:
<nav>
<ul id="navlist">
<li><a href="#">Home</a></li>
<li><a href="#">about</a></li>
<li><a href="#">etc,</a></li>
</ul>
</nav>
CSS:
nav {
display:block;
background:#000;
}
nav ul {
margin: 0 auto;
width: 777px;
}
nav ul li {
float:left;
}
But of course that's on the left side of the page, and I can't seem to get it to the right without adding an extra div element... The only option is to float the <li>
's right, but that would mean my navigation is in reverse order and I really don't want that... It's an auto generated list of pages in a wordpress install, so I could then order the pages reversely in the admin panel but having to alter backend stuff is not really a good way to handle a design.
Anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)