3

I'm trying to understand how to put two div's next to eachother inside a wrapper and have them both column div's to match heights at all times, even if one has more content than the other, all without applying a strict height to the column. I've tried using height:100% and doesn't seem to work, here is the code/fiddle to show what I mean. Does anyone know what I am talking about and how to get this working?

 <div class="wrapper">
 <div class="left"><img src="https://i.sstatic.net/Sv4BC.png"/></div>
 <div class="right">
 <div class="stretch">
 stretch to height: 100%
 </div>
 </div> 
 <div class="fix"></div>
 </div>

CSS:

.wrapper{background:#eee;padding:10px;}
.stretch{height:100%;}
.left,.right{float:left;padding:5px;background:#FFF;}
.fix{clear:both;}
.left img{width:200px;}

Fiddle: (The two columns should be identical) https://jsfiddle.net/19zsdswt/1/

asked Mar 7, 2015 at 5:12
1
  • I may be wrong, but with the scenario you've got I don't believe it's possible for the right column to know the height of the second column because of the floats. Hopefully someone corrects me (I haven't kept up on all the random CSS tricks), but otherwise you're going to have to find a different way to set it all up. Commented Mar 7, 2015 at 5:28

1 Answer 1

2

I think the problem is with trying to add a height: 100% to a div that is floated.

You could try using a table, table cell relationship, like this:

.wrapper{display: table; background:#eee;padding:10px;}
.stretch{height:100%;}
.left,.right{display: table-cell; padding:5px;background:#FFF;}
/* .fix{clear:both;} */
.left img{width:200px;}

I have updated your fiddle here - https://jsfiddle.net/sfyt9skx/

answered Mar 7, 2015 at 5:31
Sign up to request clarification or add additional context in comments.

1 Comment

Nice and simple. Good answer. (opposed to a mess like this: matthewjamestaylor.com/blog/… ... yuck.)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.