Please enable Javascript for better experience...
Setting height of chlid divs 100 percent to its parent element
By Big | Jul 5, 2016 | In Articles | Total Views [ 1096 ]
Taged In
(0 Like)

You can set height of chlid divs 100% to its parent element using display: table and display:table-cell.


Many times I foudn situation where I want to adjust heights of inner div elements equal to out div or say all innner divs should be equal in height regardless of their contents. You can achieve this is using display attribute of css.


In above example it can clearly seen that all inner divs are not equal because of content they have.

display: table and display: table-cell

Display attribute has many options like block, inline, inline-block etc. You can achieve above requirement using display: table and display:table-cell combinations.


Below code illustrates the same.


    display: table;
    background-color: gray;
    color: #fff;
    width: 33.33%;
    background-color: red;
    display: table-cell;
    padding: 20px;
    width: 33.33%;
    background-color: green;
    display: table-cell;
    padding: 20px;
    width: 33.33%;
    background-color: blue;
    display: table-cell;
    padding: 20px;


<div class="mainCol">
                    <div class="col1">
                    This is the first paragraph.
                    <div class="col2">
                    This is the second paragraph. Content is larger than other divs.
                    I am paragraph. I am paragraph. I am paragraph. I am paragraph. I am paragraph. I am paragraph. I am paragraph. I am paragraph. I am paragraph.
                    <div class="col3">
                    This is the third paragraph.

Hope it helps you. Display attribute is simple but very important.You can use other options also like block, inline to style your pages. I will explain them some other time.

Share this

About the Author

Rahul Jha (Big)
Founder, Developer
Has working experience in different phases of Software Development Life Cycle (SDLC) in CMS, Gaming, Health Care and Financial Services domain using Agile pattern. Working experience in Design patterns, ASP.NET, MVC, Windows application, WCF, ADO.NET, SQL Server and Test Driven Development (TDD) environment with JQuery, JavaScript, N-Unit, Entity Frameworks, LINQ, Code Refactoring and Business Objects Models.

User's Comments

Please SignUp/Login to comment...

Or comment as anonymous...
* Name
* Email ID