Skip to content Skip to sidebar Skip to footer

Four Divs Of Equal Height And Width

The question seems to be simple but I am not getting it done. I have a web project I am working on with body's overflow set to hidden. So I cannot put contents in the page with mor

Solution 1:

You can use a list:

<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
</ul>

CSS:

html, body, ul {
    width: 100%;
    height: 100%;
}

li {
    float: left;
    width: 50%;
    height: 50%;
}

Live demo: http://jsfiddle.net/U7WJ4/1/show/light/


Solution 2:

SOLUTION - adjust to your own need.

<style type="text/css">
    #container {
        height:200px;
        width:400px;
        overflow:hidden;
        border:1px solid #000;
    }
    .item {
        float:left;
        height:100px;
        width:50%
    }
    .item-a { background-color: #CCC; }
    .item-b { background-color: #AAA; }
    .item-c { background-color: #900; }
    .item-d { background-color: #9CC; }
    .clear {
        clear:left;
    }
</style>

<div id="container">
    <div class="item item-a">abc</div>
    <div class="item item-b">abc</div>
    <div class="item item-c">abc</div>
    <div class="item item-d">abc</div>
    <div class="clear"></div>
</div>

here is the equivalent table method with the same CSS as the div method

<div id="container">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td class="item item-a">a</td>
            <td class="item item-b">b</td>
        </tr>
        <tr>
            <td class="item item-c">c</td>
            <td class="item item-d">d</td>
        </tr>
    </table>
</div>

Post a Comment for "Four Divs Of Equal Height And Width"