Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3 divs with percentage width

Tags:

html

css

Lets say, I have div which is 65% in width, inside that div I need to create 3 more divs which are in same line, same size but size should be in % and there should be 10px gap between side divs and center div. Any suggestions?

So far I have the following code:

    <div style="width: 65%; margin: 0 auto; text-align:left; margin-bottom: 10px;">
<div style="float:left; margin-right: 10px;">1</div>
<div style="float:left; margin-right: 10px;">2</div>
<div style="float:left;">3</div>
</div>
like image 444
Tautvydas Avatar asked Jan 14 '23 23:01

Tautvydas


1 Answers

This is a bit more HTML, but it's worked quite well for me.

HTML

<div id="hold">
    <div class="innerHold"><div class="inner col1">
        Column won
    </div></div>
    <div class="innerHold"><div class="inner col2">
        Col Two
    </div></div>
    <div class="innerHold"><div class="inner col3">
        Col 3
    </div></div>
    <div class="clear"></div>
</div>

CSS

#hold{
    width: 65%;
    margin: 0px auto;
}
.innerHold{
    float: left;
    width:33.33333%;
    /* make sure left/right margins or left/right padding are 0px here
            - it'll mess with the width otherwise*/
    margin-left:0px;
    margin-right:0px;
    padding-left:0px;
    padding-right:0px;
}
.inner{
    /* Here set your columns padding, borders, and margin 
            - or in the class names as I do below */
    margin:0px;
}
.col1, .col2{
    margin-right:10px;
}
.clear{
    clear:both;
}

http://jsfiddle.net/daCrosby/NR2kX/1/

like image 188
DACrosby Avatar answered Jan 19 '23 12:01

DACrosby