Div side by side as a table cell

I want to have two divs side by side and define the width for only one div.

Then another div will automatically set the parent container. How to do it?

HTML:

<div class="parent"> <div class="first"></div> <div class="last"></div> </div> 

CSS

 .parent { width: 100%; } .parent .first { width: 300px; float: left; background-color: red; } .parent .last { width: auto; float: right; background-color: blue; } 

Thanks.

+4
source share
2 answers

Not a float second div. Only the first should be posted.

http://jsfiddle.net/zLef8/

+6
source

Try this one

 <div class="parent"> <div class="first">test</div> <div class="last">test2</div> </div> 

Css

 .parent { width: 100%; } .parent > .first { width: 300px; float: left; background-color: red; } .parent > .last { width: auto; float: right; background-color: blue; text-align:left } 

example jsfiddle

+2
source

All Articles