Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div side by side like table cell

Tags:

html

css

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

Then, the other div would auto-fit the parent container. How do I do that?

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.

like image 206
Maurício Giordano Avatar asked Feb 18 '23 10:02

Maurício Giordano


1 Answers

Don't float the second div. Only the first one needs to be floated.

http://jsfiddle.net/zLef8/

like image 123
Explosion Pills Avatar answered Feb 26 '23 20:02

Explosion Pills