Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem of div width. first div width is 100%. now into this div there are two div one is 60% width and float is left and if I set another div with 40% width and float: left then it comes on the lower side of the first div. but if I set the width 39.60% then it is on left side. my question is how can I set the percentage in whole number so that two div is remain side by side?

What I have tried:

HTML
<div style="float: left; width: 100%;height: 40%; border: solid 1px yellow;">
            <div style="float: left; width: 60%; height: 100%; border: solid 1px red;">
            </div>
            <div style="float: left; width: 39.60%; height: 100%; border: solid 1px red;">
            </div>
        </div>
Posted
Updated 29-Mar-16 6:43am
v2

1 solution

This is due to the default box-sizing[^], which is content-box. The width you specify excludes the padding, margin and border. Your two boxes have 1px borders on either side, so their total width is 100% + 4px.

If you change the box-sizing to border-box, the width includes the padding and border, so your boxes will fit on one line.
CSS
*, :before, :after 
{
    box-sizing: border-box;
}

Example[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Mar-16 23:45pm    
5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900