【发布时间】:2012-10-17 19:23:57
【问题描述】:
为什么跟随 CSS 代码没有填满 100% 的屏幕?我有 5 列,宽度为 20%,向左浮动。
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<style type="text/css" media="screen">
body {
padding: 0;
margin: 0;
}
#container {
width: 100%;
background-color: red;
height: 42px;
}
ul {
padding: 0;
margin: 0;
width: 100%;
overflow: hidden;
list-style-type: none;
float: left;
white-space: nowrap;
display: inline;
height: 42px;
}
li {
float: left;
width: 20%;
padding: 0;
background-color: #000000;
display: inline;
}
a {
text-decoration: none;
color: #333;
text-align: center;
display: block;
height: 42px;
line-height: 42px;
white-space: nowrap;
overflow: hidden;
font-size: 0.9em;
width: auto;
}
a:hover {
background-color: #ccc;
color: #FFF;
}
</style>
</head>
<body>
<div id="container">
<ul>
<li>
<a href="#">Home</a>
</li>
<li>
<a href="#">Services</a>
</li>
<li>
<a href="#">Portfolio</a>
</li>
<li>
<a href="#">Clients</a>
</li>
<li>
<a href="#">Articles</a>
</li>
</ul>
</div>
</body>
右侧总是有一个红色区域,但 5*20% = 100% 所以不可能。怎么了?
亲切的问候, 聚丙烯
【问题讨论】:
-
它适用于我:jsfiddle.net/vs5s5
-
你能在这里显示你的错误页面吗?
-
关于这个已经写了很多,但没有找到真正的解决方案:ejohn.org/blog/sub-pixel-problems-in-css 和 css-tricks.com/percentage-bugs-in-webkit
标签: html css html-lists