【发布时间】:2015-01-12 15:48:36
【问题描述】:
对不起,这个模糊的标题,措辞这个问题很难。 观察下面的代码:
<!DOCTYPE html>
<html>
<head>
<style>
.float
{
float:left;
display:inline-block;
height:50px;
}
#a
{
width:80%;
background-color:lightgrey;
}
#b
{
width:20%;
background-color:lightblue;
}
</style>
</head>
<body>
<div class="float" id="a">The width of this div should adjust depending on the screen size.</div>
<div class="float" id="b">The width of this div should stay the same regardless of screen size.</div>
</body>
</html>
当我运行此程序时,DIV“a”和“b”的宽度会根据屏幕大小而变化,正如您对百分比所期望的那样,但我想要 DIV "b" 保持固定宽度(如 50 像素),同时仍允许 DIV "a" 填充屏幕左侧和 DIV 左边缘之间的空间“b”。
有什么想法吗?
【问题讨论】:
标签: html css width percentage