【发布时间】:2014-12-02 13:16:42
【问题描述】:
我有一个包含在 div 中的 css 菜单(我下载的源代码,因为我对 css 不了解)
<div id='cssmenu' style='float:right;'>
<ul>
<li id='index'><a href='index.php'><span>Home</span></a></li>
<li id='aboutus'><a href='aboutus.php'><span>About Us</span></a></li>
<li id='gallery'><a href='gallery.php'><span>Galley</span></a></li>
<li id='videos'><a href='videos.php'><span>Videos</span></a></li>
<li id='links'><a href='links.php'><span>Links</span></a></li>
<li id='contact'><a href='contact.php'><span>Contact</span></a></li>
</ul>
</div>
我在 <td> 内部有一个固定宽度(为简单起见,假设为 500 像素)。我调整了css中的填充以使宽度很好地适应……至少在Firefox中。当我在 Chrome 中查看它时,最后一个菜单项超出了表格单元格的宽度,最终位于菜单其余部分的下方。
我的问题是,如何使菜单项在表格宽度上等距分布?将 padding 设置为 0px 会使所有东西看起来都很小而且被压扁,我仍然想要垂直填充。
这是我的 css(对不起,我知道它很长)
#cssmenu,
#cssmenu ul,
#cssmenu ul li,
#cssmenu ul li a {
margin: 0;
padding: 0;
border: 0;
list-style: none;
line-height: 1;
display: block;
position: relative;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#cssmenu {
width: 100%;
font-family: Helvetica, Arial, sans-serif;
color: #ffffff;
padding:0px;
display:table;
}
#cssmenu.align-right ul li {
float: right;
border-right: 0;
border-left: 1px solid rgba(0, 0, 0, 0.22);
}
#cssmenu.align-right ul li a {
border-right: 0;
border-left: 1px solid rgba(255, 255, 255, 0.15);
}
#cssmenu ul {
background: #222222;
/* Old browsers */
background: -moz-linear-gradient(bottom, #000000 0%, #222222 50%, #3c3c3c 51%, #393939 78%, #888888 100%);
background: -webkit-linear-gradient(bottom, #000000 0%, #222222 50%, #3c3c3c 51%, #393939 78%, #888888 100%);
background: -o-linear-gradient(bottom, #000000 0%, #222222 50%, #3c3c3c 51%, #393939 78%, #888888 100%);
background: -ms-linear-gradient(bottom, #000000 0%, #222222 50%, #3c3c3c 51%, #393939 78%, #888888 100%);
background: linear-gradient(to top, #000000 0%, #222222 50%, #3c3c3c 51%, #393939 78%, #888888 100%);
width: 100%;
display:table-row-group;
}
#cssmenu:after
#cssmenu ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#cssmenu ul li {
float: left;
display: table-cell;
vertical-align: middle;
/*width: auto; */
border-right: 1px solid rgba(0, 0, 0, 0.22);
z-index: 1;
}
#cssmenu ul li::after {
content: "";
width: 100%;
height: 8px;
position: absolute;
border-top-left-radius: 50% 4px;
border-top-right-radius: 50% 4px;
background: -webkit-linear-gradient(bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0) 60%, #222222 61%, #222222 100%);
background: -o-linear-gradient(bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0) 60%, #222222 61%, #222222 100%);
background: -ms-linear-gradient(bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0) 60%, #222222 61%, #222222 100%);
background: linear-gradient(to top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0) 60%, #222222 61%, #222222 100%);
background: -moz-linear-gradient(bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0));
z-index: 2;
bottom: 10px;
}
#cssmenu ul li a {
display: block;
padding: 10px 11px;
text-decoration: none;
font-size: 11px;
text-transform: uppercase;
color: #ffffff;
border-right: 1px solid rgba(255, 255, 255, 0.15);
z-index: 3;
}
#cssmenu ul li a:hover,
#cssmenu ul li.active a {
color: #ffffff;
}
#cssmenu ul li:hover,
#cssmenu ul li.active {
background: #1275ae;
/* Old browsers */
background: -moz-linear-gradient(bottom, #0b4669 0%, #1275ae 50%, #1794dc 51%, #1691d8 78%, #98d2f4 100%);
background: -webkit-linear-gradient(bottom, #0b4669 0%, #1275ae 50%, #1794dc 51%, #1691d8 78%, #98d2f4 100%);
background: -o-linear-gradient(bottom, #0b4669 0%, #1275ae 50%, #1794dc 51%, #1691d8 78%, #98d2f4 100%);
background: -ms-linear-gradient(bottom, #0b4669 0%, #1275ae 50%, #1794dc 51%, #1691d8 78%, #98d2f4 100%);
background: linear-gradient(to top, #0b4669 0%, #1275ae 50%, #1794dc 51%, #1691d8 78%, #98d2f4 100%);
}
#cssmenu ul li:hover::after,
#cssmenu ul li.active::after {
background: -webkit-linear-gradient(bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0) 60%, #1275ae 61%, #1275ae 100%);
background: -o-linear-gradient(bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0) 60%, #1275ae 61%, #1275ae 100%);
background: -ms-linear-gradient(bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0) 60%, #1275ae 61%, #1275ae 100%);
background: linear-gradient(to top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0) 60%, #1275ae 61%, #1275ae 100%);
background: -moz-linear-gradient(bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0));
}
【问题讨论】: