3

I have 2 block-inline divs.

I don't wan't to specify the width of the first one but, I would like the second takes 100% of the remaining space. The container of the two divs take 100% of my screen.

It seems to be possible using jQuery to determine the width of the first div and to set the second value, but I would like to do it in pure css.

How can I do that ?

Pier-Alexandre Bouchard
  • 5,135
  • 5
  • 37
  • 72

2 Answers2

7

div.box {
  background: #EEE;
  height: 100px;
  width: 600px;
}

div.div1 {
  background: #999;
  float: left;
  height: 100%;
  width: auto;
}

div.div2 {
  background: #666;
  height: 100%;
}

div.clear {
  clear: both;
  height: 1px;
  overflow: hidden;
  font-size: 0pt;
  margin-top: -1px;
}
<div class="box">
   <div class="div1">1st</div>
   <div class="div2">2nd</div>
   <div class="clear">
</div>

Hope it helped.

JJJ
  • 32,902
  • 20
  • 89
  • 102
Bert
  • 1,019
  • 3
  • 14
  • 25
  • yes to obtain the width of the content and also the height in div2 to that it will not create a nextline or go down. – Bert Feb 28 '12 at 03:29
  • Can someone help me.. why is the class clear used in this case? – Zohair Apr 27 '16 at 07:58
0

If you don't want to use jquery then this might worth doing

<div style="width:100%;"> 
        <div style="float:left; display:inline-block;" class="div1">left div</div> 
        <div style="float:right; display:inline-block;" class="div2">right div</div> 
    </div> ​
Dips
  • 3,220
  • 3
  • 20
  • 21