<div id="wrapper" style="width:90%;height:100px;background-color:Gray;"> <div id="one" style="height:100px;background-color:Green;float:left;"></div> <div id="two" style="height:100px;background-color:blue;float:left;"></div> <div id="three" style="height:100px;background-color:Red;float:left;"></div> </div>
I have a parent div which will contain 2 or 3 child divs. I want child divs to take equal widths automatically.
Thank You
The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.
Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.
Using width, max-width and margin: auto; Then, you can set the margins to auto, to horizontally center the element within its container. The element will take up the specified width, and the remaining space will be split equally between the two margins: This <div> element has a width of 500px, and margin set to auto.
You can use display: inline to put the two div elements inline. Explanation: div elements are block elements, so their display style is usually display: block . You can wrap both the div elements in a span tag. Explanation: span works the same way as the div , to organize and group elements.
It's not impossible. It's not even particularly hard, with the use of display: table
.
This solution will work in modern browsers. It won't work in IE7.
http://jsfiddle.net/g4dGz/ (three div
s)
http://jsfiddle.net/g4dGz/1/ (two div
s)
CSS:
#wrapper { display: table; table-layout: fixed; width:90%; height:100px; background-color:Gray; } #wrapper div { display: table-cell; height:100px; }
HTML:
<div id="wrapper"> <div id="one">one one one one one one one one one one one one one one one one one one one one one</div> <div id="two">two two two two two two</div> <div id="three">three</div> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With