我怎样才能width:50%
与panel-default
padding
,但在计算中包括margin
或panel-default
(不确定哪一个更合适),以便{{} 1}}完全填充100%的宽度?
代码
.testing-here {
padding: 2.5px;
display: inline;
box-sizing: border-box;
}
body {
box-sizing: border-box;
}
.panel-default {
box-sizing: border-box;
border-style: none;
position: relative;
width: 50%;
padding-bottom: 40%;
/* = width for a 1:1 aspect ratio */
overflow: hidden;
background-color: #446CB3;
border-radius: 0px;
display: inline-block;
}
.panel-body {
color: white;
position: absolute;
}

<div class="testing-here">
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
</div>
&#13;
更新
现在,如果我将width
设置为50%
所有面板垂直下拉,因为它们不能并排放置。
答案 0 :(得分:3)
你需要:
box-sizing:border-box
添加到*,*:before,*:after
inline-block
间隔,您可以通过重置父字体font-size:0
display:inline
.testing-here
border
添加到.panel-default
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
margin: 0
}
.testing-here {
padding: 2.5px;
font-size: 0
}
.panel-default {
box-sizing: border-box;
border-style: none;
position: relative;
width: 50%;
padding-bottom: 40%;
/* = width for a 1:1 aspect ratio */
overflow: hidden;
background-color: #446CB3;
border-radius: 0;
display: inline-block;
font-size: 16px;
border: 5px white solid
}
.panel-body {
color: white;
position: absolute;
}
&#13;
<div class="testing-here">
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
</div>
&#13;
答案 1 :(得分:0)
将box-sizing: border-box;
添加到元素