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,045
  • 5
  • 34
  • 71

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,246
  • 20
  • 88
  • 102
Bert
  • 1,019
  • 2
  • 14
  • 25
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,090
  • 3
  • 19
  • 21