[英]Two-column layout with overlay column - is flexbox usable here or do I need to work around display: inline-block?
I am building a two-column layout and I only need to support modern browsers. 我正在建立一个两列的布局,我只需要支持现代的浏览器。 The two columns should fill 100% of the width of their container.
两列应填充其容器宽度的100%。 Additionally, I have a third column which needs to be the same width as the left-side column and lay ontop of it.
另外,我还有第三列,其宽度必须与左侧列相同,并位于其顶部。
If I did not have the need for an overlaying column then this problem would be easily solved with the use of flexbox. 如果我不需要覆盖列,那么使用flexbox可以轻松解决此问题。 However, I'm not sure it is possible to tell the overlay column that it should be the same width as the flexible column underneath it.
但是,我不确定是否可以告诉叠加层的宽度应该与它下面的柔性柱的宽度相同。 So, I am using percent-width columns which are
display: inline-block
and apply font-size: 0
to the parent element to prevent additional spacing between the columns. 因此,我正在使用显示为百分比的宽度百分比列
display: inline-block
并将font-size: 0
应用于父元素,以防止列之间出现额外的间距。
My questions are: 我的问题是:
display: inline-block
with font-size: 0
display: inline-block
的隐式间距工作display: inline-block
font-size: 0
display: inline-block
Is there a more appropriate way to achieve my effect in modern browsers? 在现代浏览器中,是否有更合适的方法来达到我的效果?
Here's my JSFiddle 这是我的JSFiddle
<div class='page'>
<div class='left column'>
</div>
<div class='left column overlay'>
</div>
<div class='right column'>
</div>
</div>
.page {
width: 400px;
height: 400px;
font-size: 0;
position: relative;
}
.column {
height: 100%;
display: inline-block;
}
.left {
width: 60%;
background-color: green;
}
.right {
width: 40%;
background-color: blue;
}
.overlay {
display: none;
background-color: yellow;
position: absolute;
left: 0;
}
Something like this? 像这样吗 http://jsfiddle.net/bluedao/su28zxea/
http://jsfiddle.net/bluedao/su28zxea/
Code from fiddle 小提琴的代码
<div class="row-outer">
<div class="row-inner">
<div class="col col1">
<div class="overlay">
<span>Overlay</span>
</div>
<div>some text</div>
<div>some more text</div>
</div>
<div class="col col2">
<div>Content</div>
</div>
</div>
</div>
.row-outer {
position: absolute;
background: gray;
width: 100%;
}
.row-inner {
background: purple;
position: relative;
}
.col {
float: left;
}
.col1 {
background: red;
width: 40%;
}
.col2 {
background: blue;
width: 60%;
}
.overlay {
position: absolute;
background: green;
width: 40%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.