2

如何在导航栏上方和下方添加规则?我尝试了一个 HR 标签,但这似乎在导航栏周围腾出了很多空间。这是我的 html,这里是我想要做的例子。

http://matthewtbrown.com/jeffandcricketquilt/

http://matthewtbrown.com/jeffandcricketquilt/rule.png

4

6 回答 6

1

If you do not want to change your html at all, you can add this to your css

nav ul:before {
    border-bottom: 1px solid white;
    border-top: 1px solid white;
    bottom: 5px;
    content: "";
    left: 5px;
    position: absolute;
    right: 5px;
    top: 5px;
    z-index:0;
}
nav ul {
    overflow: auto;
    position: relative;
    background-color:#000;
}
nav ul li{
    position:relative;
    z-index:10;
}

and remove the background-color from the li elements (since i added it to the ul)

于 2013-04-21T14:48:56.323 回答
0

使用边框和填充:

* {
    margin: 0;
    padding: 0;
}

nav {
    text-align: center;
    background: black;
    color: white;
    padding: .2em;
}

ul {
    padding: .5em;
    border: 1px solid white;
    border-left: none;
    border-right: none;
}



nav li {
    display: inline;
    list-style-type: none;
    padding: 0 2em;
}

演示

于 2013-04-21T14:36:03.157 回答
0

我会为 ul 标签应用一个大纲,所以 css 应该是:

nav ul{
  outline-color: white;
  outline-style: solid;
  outline-width: 2px;
  outline-offset: -7px;
  height: 60px;
  width: 848px;
}
于 2013-04-21T14:38:26.847 回答
0

最简单的方法是为 nav 元素添加一个内边距,4px 适合 li 元素的宽度。还添加浮动:左

现在将border-top 和border-bottom 添加到ul 元素。添加 float: left here 为好。这将切换您的 li 元素,因为它们具有固定的宽度。将它们的宽度降低到 210px,应该没问题。

CSS 添加到您的代码中:

nav {
  padding: 4px
  float: left;
}

nav ul {
  border-top: 1px solid white;
  border-bottom: 1px solid white;
  float: left;
}

nav li {
  width: 210px;
}
于 2013-04-21T14:38:34.800 回答
0

尝试将此 CSS 应用于导航栏:

border-top: 1px solid #eee
border-bottom: 1px solid #eee
于 2013-04-21T14:33:09.103 回答
0

如果line-height与您可以通过更改列表元素 font-size来操纵边框距离相同,这是我的示例:padding-bottom

.headerSection ul.navigation li  a {
    font-size: 12px;
    line-height: 12px;
    text-decoration: none ;
    padding-bottom: 10px; 
    border-bottom-color: transparent;
    border-bottom-width: 5px;
    border-bottom-style: solid;
} 

.headerSection ul.navigation li a:hover {
    border-bottom-color: #e8bf5d;
}
于 2018-02-12T10:54:04.880 回答