我正在进行水平导航,其中列表项需要跨越整个宽度,和‘活动’列表项需要比其他项目高。
成功地使列表项跨越整个宽度,方法是将ul设置为display: table,并将列表项设置为: table-cell。
#l-primary-nav ul {
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
display: table;
}
#l-primary-nav li {
display: table-cell;
text-align: center;
line-height: 40px;
}我想不出的是,如何使“活动”列表项比其他列表项目高一点。我想我应该设置一个边距顶:5 5px到#l-主导航器(上图),并从活动的li (下面)中移除边距顶,但是表格单元格项不接受边距。
#l-primary-nav li.active {
background: #fff;
border-left: 1px solid #c2c2c2;
border-right: 1px solid #c2c2c2;
}以下是到目前为止导航栏的链接:小提琴
我希望‘关于’的导航项目是约5个像素比其他。希望使用CSS唯一的解决方案。任何洞察力都将不胜感激。
谢谢!
发布于 2013-12-26 04:17:21
这可能对你有帮助
#l-primary-nav li {
display:block;
width:140px;
float:left;
text-align: center;
margin-top:4px;
border: 1px solid #c2c2c2;
}我给出了显示: li元素的块,并添加了宽度:
演示:http://jsfiddle.net/ggbhat/af82E/1/
发布于 2013-12-26 15:19:40
在上面提出的解决方案中,我能够保持列表项跨越整个宽度,同时给活动列表项一个更高的高度。链接到代码:http://jsfiddle.net/melcsweeney/xc5Y2/
#l-primary-nav {
width: 600px;
margin: 0 auto;
}
.l-inline li {
display: inline-block;
}
#l-primary-nav ul {
width: 99.8%;
margin: 0;
padding: 0;
border-left: 1px solid #c2c2c2;
border-right: 1px solid #c2c2c2;
border-bottom: 1px solid #c2c2c2;
float: left;
display: table;
}
#l-primary-nav li {
text-align: center;
display: table-cell;
vertical-align: bottom;
border-top: 1px solid #c2c2c2;
}
#l-primary-nav li a{
line-height: 40px;
height: 41px;
border-top: 1px transparent;
display: block;
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.18, #FBFBFB), color-stop(1, #D1D1D1));
background-image: -o-linear-gradient(bottom, #FBFBFB 0%, #D1D1D1 100%);
background-image: -moz-linear-gradient(bottom, #FBFBFB 0%, #D1D1D1 100%);
background-image: -webkit-linear-gradient(bottom, #FBFBFB 0%, #D1D1D1 100%);
background-image: -ms-linear-gradient(bottom, #FBFBFB 0%, #D1D1D1 100%);
background-image: linear-gradient(to bottom, #FBFBFB 0%, #D1D1D1 100%);
}
#l-primary-nav li a:hover {
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #E1E3E6), color-stop(1, #BABCBF));
background-image: -o-linear-gradient(bottom, #E1E3E6 0%, #BABCBF 100%);
background-image: -moz-linear-gradient(bottom, #E1E3E6 0%, #BABCBF 100%);
background-image: -webkit-linear-gradient(bottom, #E1E3E6 0%, #BABCBF 100%);
background-image: -ms-linear-gradient(bottom, #E1E3E6 0%, #BABCBF 100%);
background-image: linear-gradient(to bottom, #E1E3E6 0%, #BABCBF 100%);
}
#l-primary-nav li.active a{
margin-top: -5px;
height: 45px;
position: relative;
background: #fff;
border-left: 1px solid #c2c2c2;
border-right: 1px solid #c2c2c2;
border-top: 1px solid #c2c2c2;
}https://stackoverflow.com/questions/20778758
复制相似问题