CSS 3 col template 100% same height

断了今生、忘了曾经 提交于 2020-01-03 04:14:11

问题


I'm trying to do the next:

html > body > div-wrapper > div-left, div-separator, div-content

  1. The three div will have the same height
  2. If they are empty ( or no overflow), the height will be the 100% of the page (without scrolls).
  3. If some of they overflows, I will have only 1 scroll that scrolls down/up the three divs at the same time (scrolling the wrapper i think).

It's this possible? I spent 7 hours thinking about it but I can't solve only with HTML + CSS (without using flexbox).

Thanks,


回答1:


That's a great question! It took me quite a while to create a graceful solution for you.

What you need is the dynamic sticky footer technique with an extra container for columns.

HTML

<div id="container">
    <header class="section">
      foo
    </header>

    <div class="section expand">
        <div class="columns-container">
            <div class="column" id="a">
                <p>Contents A</p>
            </div><div class="column" id="b">
                <p>Contents B</p>
            </div><div class="column" id="c">
                <p>Contents C</p>
            </div>
        </div>
    </div>

    <footer class="section">
        bar
    </footer>
</div>

CSS

/*************************
 * Sticky footer hack
 * Source: http://pixelsvsbytes.com/blog/2011/09/sticky-css-footers-the-flexible-way/
 ************************/

/* Stretching all container's parents to full height */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

/* Setting the container to be a table with maximum width and height */
#container {
    display: table;
    height: 100%;
    width: 100%;
}

/* All sections (container's children) should be table rows with minimal height */
.section {
    display: table-row;
    height: 1px;
}

/* The last-but-one section should be stretched to automatic height */
.section.expand {
    height: auto;
}


/*************************
 * Full height columns
 ************************/

/* We need one extra container, setting it to full width */
.columns-container {
    display: table-cell;
    height: 100%;
}

/* Creating columns */
.column {
    /* The float:left won't work for Chrome for some reason, so inline-block */
    display: inline-block; /* for this to work, the .column elements should have NO SPACE BETWEEN THEM */
    vertical-align: top;
    height: 100%;
    width: 33.3333%;
}


/****************************************************************
 * Just some coloring so that we're able to see height of columns
 ****************************************************************/
header { background-color: yellow; }
#a { background-color: pink; }
#b { background-color: lightgreen; }
#c { background-color: lightblue; }
footer { background-color: purple; }

Demo

  • Compact columns content: http://jsfiddle.net/hsX5q/19/
  • One of the column's content overflows window height: http://jsfiddle.net/hsX5q/20/

PS

You've got a wrong CSS selector in your question. The correct would be:

html > body > div-wrapper > div-left, 
html > body > div-wrapper > div-separator,
html > body > div-wrapper > div-content {



回答2:


<style type="text/css">
.wrap {
    border: 1px solid #f00;
    height: 100%;
    width: 100%;
}
.wrap div {
    border: 1px solid #00f;
    overflow: auto;
    height: 100%;
    width: 33%;
    float: left;
    margin: 0px;
}
</style>
<div class="wrap">
    <div>Contents A</div>
    <div>Contents B</div>
    <div>Contents C</div>
</div>

or

<frameset cols="33%,*,33%">
   <frame src="frame_a.htm">
   <frame src="frame_b.htm">
   <frame src="frame_c.htm">
 </frameset>



回答3:


Just do that :

.col{
   display:block;
   height:100%;
}

It's Simple, it's fast, it's css.



来源:https://stackoverflow.com/questions/15693817/css-3-col-template-100-same-height

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!