【发布时间】:2014-10-10 19:14:50
【问题描述】:
在正则框模型下:
Ethan Marcotte 在响应式网页设计第 35 页中写道:
在元素上设置灵活填充时,您的上下文是 宽度 元素本身。
请看下面的例子:
.main-wrapper {
width: 98%; /*960px - to give some space on the viewport*/
}
.box-one,
.box-two {
width: 44.791666666667%; /* 430 / 960 */
float: left;
margin: 30px 0 20px 0;
padding: 2.083333333333%; /* padding should be 20px*/
text-align: center;
}
.box-one {
margin-right: 2.083333333333%;
/*margin is relative to the container (here 960px), so:
20/960
*/
background-color: red;
}
.box-two {
background-color: blue;
}
<div class="main-wrapper">
<div class="box-one">
<p>box one here</p>
</div>
<div class="box-two">
<p>box two here</p>
</div>
</div>
我的问题是:
根据那本书上写的内容,填充设置为: 不应该是正确的(但它是!)。
padding: 2.083333333333%;
相反:
我们应该考虑元素宽度本身,即430px。但如果我们将该值用作上下文,我们会得到 4.x %。
我没有得到什么?
【问题讨论】:
-
如果你不明白我的问题,我可以努力澄清。只需发表评论。谢谢。
-
主要的包装是元素,不是吗?嵌套 div 受父 div 约束。
-
你能解释一下“上下文”是什么意思吗?
-
Gary Hayes,据我所知,根据我的阅读,元素本身不应该是
main-wrapper,而是.box-one和@ 987654327@具体? -
@web-tiki:根据我对作者文字的理解,上下文是您作为参考的价值。 IE。如果您希望将 20px 的
margin转换为灵活的,在给定的布局上,您应该将该值除以容器宽度。在这种情况下,container width是context。
标签: css