Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 divs aligned side by side, how to make right div fill width 100%?

I'm wondering what the best way to go about doing this is...

I have 3 divs:

  • a div#container with width=100%; that holds 2 inner divs

  • a div#inner_left with width changing dynamically, but no wider than 200px (will hold a product image)

  • an div#inner_right where the width should fill the rest of the space in the container (will contain text to describe the product shown)

    #container {    width:100% }  #inner_left {     display:inline-block:     max-width:200px; }  #inner_right {     display:inline-block;     width:100%;  } 

The problem is that the div#inner_right creates a line break and fills the entire width. How can I make them align next to each other, with the right div accounting for the width taken by the left div (which changes dynamically?). I've gotten this to work other ways, but I'm looking for a clean solution...

Any help for a CSS noob is much appreciated!

like image 509
thedeepfield Avatar asked Feb 09 '11 06:02

thedeepfield


People also ask

How do you make a div 100 width?

What you could do is set your div to be position: absolute so your div is independent of the rest of the layout. Then say width: 100% to have it fill the screen width. Now just use margin-left: 30px (or whatever px you need) and you should be done.

How do I make a div fill full width?

The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent. Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.

How do I align two divs side by side in a div?

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.

How do I make a div auto adjust width?

Set display to inline-block to make the div width fit to its content. Use position: relative and left: 50% to position its left edge to 50% of its containing element. Use transform: translateX(-50%) which will "shift" the element to the left by half its own width.


1 Answers

I haven't really seen a good solution in the answers here. So I'll share mine.

Best way to do this is by using the table-cell option in CSS. One important thing to add is a 'min-width' to the element that has a pixel width.

Example:

<div id="left">     Left </div> <div id="right">     right </div> 

CSS:

#left {     display: table-cell;     min-width: 160px; } #right {     display: table-cell;     width: 100%;     vertical-align: top; } 
like image 180
w00 Avatar answered Oct 18 '22 02:10

w00