【发布时间】:2023-03-11 12:00:01
【问题描述】:
我有一个工作正常的顶级菜单栏页面。我使用#nav 的 CSS 类作为顶部菜单栏。
我正在尝试实现一个仅包含两个项目的第二行菜单栏:Back 和 Home。我试图让第二个菜单项向右浮动。我正在尝试使用 last-child 这样做,但我无法让 last-child last-of-type 工作。
#nav_row2 {
position:fixed; /* used to render menu bar fixed on top and not scroll up ALSO ALLOWS MENUS TO STAY ON TOP OF SLIDESHOW*/
}
#nav_row2 li {
background-color: #BDB76B; /* menu background color */
font-family: Arial, Helvetica, sans-serif;
font-size:14px;
text-align:center;
float:left; /* For the menu buttons to float left */
width:150px; /* Width of the buttons */
line-height:25px; /* this is the text height of the menu items */
margin-left:140px; /*Left margin to line up with the parent menu line */
margin-right: 0; /* */
list-style-type:none; /* no underscores, etc. */
}
#nav_row2 li:last-child {
float:right; /* For the menu button to float right */
margin-left: 0; /* */
margin-right:140px; /*Right margin to line up with the parent menu line */
}
<div style="clear:both" ></div>
<br />
<ul id="nav_row2">
<li><a href="#" onclick="history.go(-1)">Back</a></li>
<li><a href="http://www.saintsusanna.org/">Home</a></li>
</ul>
<br />
<div style="clear:both" ></div>
【问题讨论】:
-
你想让 home 和 back 对齐吗?还是返回左侧,首页在右侧?
-
如果您将上面的代码插入到代码 sn-p 中,您会注意到您的
nth选择器实际上正在工作。您是否检查过浏览器中的元素以确认没有其他元素(例如任意br)被放置在您的无序列表中? -
上没有右斜线。不要在 CSS 中使用
代替边距。 -
嗨,瑞秋。我想要左边的返回和右边的主页。感谢您的提问。
标签: html css css-selectors