Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position two divs side by side where the second width is 100%?

Tags:

html

css

I want to achieve this:

width=60px         width = remaining space
|------|    |-----------------------------------|
| div1 |    | Loren ipsun...                    |
|------|    |                                   |
            |                            div2   |
            |-----------------------------------|

Sample html on jsFiddle.

Is it possible to place two divs side-by-side leaving the second div with all remaining space?

like image 902
BrunoLM Avatar asked Dec 01 '10 19:12

BrunoLM


People also ask

How do I align two divs side by side?

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 keep two side by side divs the same height?

Basically what you do is make both divs/columns very tall by adding a padding-bottom: 100% and then "trick the browser" into thinking they aren't that tall using margin-bottom: -100% .

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 place 2 divs?

With CSS properties, you can easily put two <div> next to each other in HTML. Use the CSS property float to achieve this. With that, add height:100px and set margin.


2 Answers

Just float the first div, and set the margin-left of the second div to accommodate the width of the first div. Something like this:

div.one {
  width: 60px;
  float: left;
}

div.two {
  margin-left: 60px;
}

Keep in mind that the width CSS property on the div only applies to the content, so you need to set the margin-left to be the sum of the width, border, margin, and padding properties of the first div.

Here is the updated version of your jsfiddle. Let me know if you have any questions about it.

like image 90
AgentConundrum Avatar answered Oct 04 '22 16:10

AgentConundrum


Here it is:

CSS:

#container { background: silver; width: 100% }


.image
{
    background: green; color: green;
    width: 60px; height: 60px;
    float: left;

}
.content
{
    background: blue; color: white;
   margin-left: 60px;


}

And on jsFiddle (It's playing up at the moment)

Hope this helps!

like image 41
ryryan Avatar answered Oct 04 '22 15:10

ryryan