简体   繁体   English

使用CSS相等的色谱柱流体高度和流体宽度色谱柱布局

[英]Equal column fluid height and fluid width column layout using CSS

I'm wanting to create an equal fluid height, equal fluid width two column layout panel. 我想创建相等的流体高度,相等的流体宽度两列布局面板。

At the moment I'm using the psuedo-element solution proposed here: http://webdesign.tutsplus.com/tutorials/quick-tip-solving-the-equal-height-column-conundrum--cms-20403 to create the equal height columns which works perfect. 目前,我正在使用此处提出的伪元素解决方案: http ://webdesign.tutsplus.com/tutorials/quick-tip-solving-the-equal-height-column-conundrum--cms-20403创建等高的柱子,完美的作品。 And I'm using a width of 50% for each of the columns, floated to create the column layout. 我为每列使用50%的宽度,浮动以创建列布局。

The site I'm building has content set at a max-width of 1200px, so I need a container within each column to be set at a max-width of 600px. 我正在构建的网站的内容设置为最大宽度为1200px,因此我需要在每列内设置一个容器,最大宽度为600px。 At the moment I'm floating a container inside the left-hand column right, and one in the right-hand column left but it doesn't seem to be working. 目前,我在左栏中向右浮动一个容器,在右栏中向左浮动一个容器,但它似乎没有用。 The max-width is being ignored, so the containers don't have a width at all. 最大宽度被忽略,因此容器根本没有宽度。

I'm wanting to keep the overall content of the columns in center of the page aligning with the content at max-width: 1200px above and below. 我想使页面中心的列的整体内容与最大宽度(上下1200px)处的内容对齐。

Please note I want the column wrapper to fill the full width of the screen, not a max-width. 请注意,我希望列包装器填充屏幕的整个宽度,而不是最大宽度。

HTML: HTML:

<div class="col-wrapper">
    <div class="half-col-1">
        <div class="cta-content">
            <p>Column 1</p>
        </div>
    </div>
    <div class="half-col-2">
        <div class="cta-content">
            <p>Column 2</p>
        </div>
    </div>
</div>

CSS: CSS:

.content {
    max-width: 1200px;
    height: 30px;
    margin: 0 auto 20px;
    background: green;
}

.col-wrapper {
    overflow: hidden;
    position: relative;
    margin: 0 auto 20px;
}

.half-col-1 {
    width: 50%;
    float: left;
}

.half-col-2 {
    width: 50%;
    float: right;
}

.half-col-1:before, .half-col-2:before {
    width: 50%;
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: -1;
}

.half-col-1:before {
    background: blue;
    left: 0;
}

.half-col-2:before {
    background: red;
    left: 50%;
}

.cta-content {
    max-width: 600px;
    color: white;
    background: rgba(255,255,255,0.1); 
}

.half-col-1 .cta-content {
    float: right;
}

.half-col-2 .cta-content {
    float: left;
}

I have a fiddle here that show's where I am at the minute: http://jsfiddle.net/dr4up5q3/4/ 我在这里有一个小提琴,显示了我现在的位置: http : //jsfiddle.net/dr4up5q3/4/

Any help would be greafully received. 任何帮助将不胜感激。

It seems by adding the styles below .cta-content does the trick. 通过在.cta-content下面添加样式似乎可以解决问题。

width: 100%;
max-width: 600px;

Updated fiddle here for those who need a similar solution: http://jsfiddle.net/dr4up5q3/6/ 这里为需要类似解决方案的人更新了小提琴: http : //jsfiddle.net/dr4up5q3/6/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM