0

So, I'm in a situation where I have to use 'floated' divs. Two child divs next to each other inside a parent div. The right div is fixed width and taller, and I want the left div to expand to be the same height as the right one.

Here's the sample. I want the left div to be the same height as the right div. And I have to use floats. No changing to absolute positioning or display:table or anything.

Anyone know if this is possible?

html, body {
  height: 100%;
}

div {
  font-family: Tahoma, Verdana sans-serif;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
}

.container {
  width: 100%;
  background-color: rgba(255, 255, 0, 1);
  overflow: auto;
}

.left {
  height: 100%;
  width: calc(100% - 100px);
  background-color: rgba(0, 0, 255, 0.6);
  float: left;
  padding: 20px;
  border: dashed thick blue;
}

.right {
  float: right;
  width: 100px;
  padding: 20px;
  border: dashed thick green;
}
<div class="container">
  <div class="left">
    LEFT
  </div>
  <div class="right">
    RIGHT RIGHT RIGHT RIGHT
  </div>
</div>

fiddle here too: https://jsfiddle.net/y0zatg8w/

erlloyd
  • 485
  • 6
  • 20
  • yes it is, if you use `JavaScript`, but in plain `css` you cant make it, that's the disadvantage of float, i think, display table and flex can do that. – mmativ Jun 22 '16 at 03:18

1 Answers1

1
<div class="container">
  <div class="left">
    LEFT
  </div>
  <div class="right">
    RIGHT RIGHT RIGHT RIGHT
  </div>
</div>

div {
  font-family: Tahoma, Verdana sans-serif;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
}

.container {
  width: 100%;
  background-color: rgba(255, 255, 0, 1);
  overflow: auto;
  display:flex;
}

.left {
 flex:10;
  width: calc(100% - 100px);
  background-color: rgba(0, 0, 255, 0.6);
  float: left;
  padding: 20px;
  border: dashed thick blue;
}

.right {
  flex:1;
  float: right;
  width: 100px;
  padding: 20px;
  border: dashed thick green;
}
Hiral Suvagya
  • 591
  • 3
  • 8
  • Ok, that is close, but it doesn't quite work. Now, the 'right' div will resize it's width when the page is resized, and I need it to be a fixed width while the left div changes size. You'll notice that's exactly what happens in my example. – erlloyd Jun 22 '16 at 04:31
  • If I don't float the left and right divs, and don't flex them, but put `display:flex` in the parent, then it works as I want. – erlloyd Jun 22 '16 at 04:34