0

I have a page with a header and a content section

 ------------------
|       Header     |
 ------------------
|                  |
|     Content      |
|                  |
|                  |
 ------------------

I have used flex: 1 1 auto; overflow:hidden; on the content and overflow:display; flex: 0 1 auto; on the header. This all is working fine.

Next in the content i have created 4 <div> each with 25% height.

<div class="content">
            <!--first row-->
            <div class="myrow">
                <div class="colsolid">Johnson </div><!--
                --><div class="col">Coke</div><!--
                --><div class="colsolid">Nissan</div><!--
                --><div class="col">Pepsi</div>
            </div>

            <!--second row-->
            <div class="myrow">
              <div class="colsolid">Johnson </div><!--
                --><div class="col">Coke</div><!--
                --><div class="colsolid">Nissan</div><!--
                --><div class="col">Pepsi</div>
            </div>

            <!--third row-->
            <div class="myrow">
              <div class="colsolid">Johnson </div><!--
                --><div class="col">Coke</div><!--
                --><div class="colsolid">Nissan</div><!--
                --><div class="col">Pepsi</div>
            </div>

            <!--forth row-->
            <div class="myrow">
              <div class="colsolid">Johnson </div><!--
                --><div class="col">Coke</div><!--
                --><div class="colsolid">Nissan</div><!--
                --><div class="col">Pepsi</div>
            </div>          
        </div>

relevant css

.myrow{
height:25%;
background-color: red;
align-items: center;
border-width: 1px;
border-style: solid;
}

.col{
    background-color: green;
    display:inline-block;
    border-style: solid;
    border-width: 1px;
    width: -webkit-calc(25% - 2px);
    width:    -moz-calc(25% - 2px);
    width:         calc(25% - 2px);
}

.colsolid{
    background-color: black;
    color: white;
    display:inline-block;
    border-style: solid;
    border-width: 1px;
    text-align: center;
    width: -webkit-calc(25% - 2px);
    width:    -moz-calc(25% - 2px);
    width:         calc(25% - 2px);
}

The issue is that the myrow are not limiting to be 25% of the content div. Instead its 25% of the full page height. Any ideas?

Here is the fiddle link

codeNinja
  • 1,442
  • 3
  • 25
  • 61

1 Answers1

2

There's no such thing as overflow: display. That value doesn't exist (MDN).

Also, when you give an element a percentage height, Chrome and Safari require that a height be specified on the parent element. Several containers in your HTML structure are missing a defined height, so height: 25% on .myrow elements may not work.

More details here:


UPDATE (based on feedback in the comments):

On your live site, try this:

  • Remove height: 100% from .content. (height: 100% on .content plus the navbar height exceed 100% and will cause overflow.)
  • Make .content a flex container: give it display: flex and flex-direction: column. This will make all .myrow elements flex items.
  • Remove height: 8.33% from .myrow flex items. This isn't necessary anymore. Just give .myrow a flex: 1 rule. This will distribute container height equally among the 12 items.
  • Finally, add min-height: 0 to .myrow. This overrides the default min-height: auto on flex items, which prevents them from shrinking past the size of their content (details).
Community
  • 1
  • 1
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701