[英]Left and right align links in <nav>
Is there a prettier and/or better way to align some a
-elements in a nav
to the right, while keeping others on the left, than using floats? 有没有对齐一些更漂亮的和/或更好的办法
a
-elements在nav
的权利,同时保持在左侧别人,比使用浮动?
float:right
moves the floated elements to the top of the nav
instead of keeping them where they used to be, height-wise. float:right
将浮动元素移动到nav
的顶部,而不是将它们保持在原来的高度上。
This has to be a common enough problem to have a good solution. 这必须是一个足够普遍的问题,才能找到一个好的解决方案。
clear:both;
-divs or css to fix the damages aren't really pretty solutions. -divs或css修复损害并不是真正的解决方案。
This is basically the code I have. 这基本上是我的代码。
<nav>
<!-- left-aligned -->
<a href="#"><img src="img/logo.svg" /></a>
<a href="#">Foo</a>
<a href="#">Bar</a>
<!-- right-aligned -->
<a href="#">Potato</a>
<a href="#">Tomato</a>
</nav>
Add classes to your a's, like shown in html. 将类添加到您的类中,如html中所示。
html: 的HTML:
<nav>
<!-- left-aligned -->
<a class="left" href="#"><img src="img/logo.svg" /></a>
<a class="left" href="#">Foo</a>
<a class="left" href="#">Bar</a>
<!-- right-aligned -->
<a class="right" href="#">Potato</a>
<a class="right" href="#">Tomato</a>
</nav>
and css: 和CSS:
nav .left {
float: left;
}
nav .right {
float: right;
}
Also, after you do that, and if doesn't work, you may want to make sure your nav's width is long enough, so they don't all scrunch together. 另外,在执行此操作后,如果它不起作用,则可能需要确保导航的宽度足够长,以使它们不会紧缩在一起。 Like
nav { width: 100%; }
像
nav { width: 100%; }
nav { width: 100%; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.