【发布时间】:2014-09-06 05:47:38
【问题描述】:
我对百分比有一些奇怪的行为。
我的布局是 1366 像素宽,我有一个 div 应该是流畅的。
它的宽度为 200 像素,这意味着它的宽度应为 14.64%。
当布局以 1366 像素测试时,div 看起来很好,没有问题,但是当我扩展到 1920 时,div 不够宽。
以下是一些代码示例:
HTML:
<header>
<div class="top-bar">
<div class="fill"></div>
<div class="container">
<nav>
</nav>
</div>
</div>
<div class="bottom-bar">
</div>
</header>
和 CSS
.container{
width: 1004px;
margin: 0px auto 0px auto;
}
header{
width: 100%;
height: 95px;
}
header div.top-bar{
background: #ffffff;
width: 100%;
height: 50px;
}
header div.fill{
background: #000000;
width: 14.64%;
height: 50px;
float: left;
}
nav{
height: 50px;
float: left;
}
header.main div.bottom-bar{
background: url("header-bottom.png") repeat-x;
width: 100%;
height: 45px;
}
我以前编写过液体设计,但从来没有遇到过这样的问题,也许我的数学是错误的,或者问题是其他所有内容都是以像素为单位硬编码的,这是液体?
【问题讨论】:
-
如果我错了,请纠正我您是否使用填充来设置容器然后添加标题 div.fill{ 背景:#000000;最小宽度:14.64%;宽度:14.64%;高度:50px;向左飘浮; }
-
容器有边距:0px auto;它在页面中间对齐。填充 div 的想法是在容器之前填充左侧部分 - 从左侧页面边框到容器(导航)。
-
jsfiddle.net/0ow7hm9w 在这里看到改变屏幕大小填充大小也改变
-
你说你想要的东西是
1366px宽...我在你的 css 中的任何地方都看不到1366。您是否期望 1366 和 1920 的14.64%相同?如果某些东西需要200px宽,为什么不能指定200px而不是14.64%?对我来说,你的问题完全不清楚。 -
我建议您对所有元素使用百分比值,而不是使用像素。对于容器类也是如此。