0

I have a "navigation" div which is a list of links floated to the left of the page. Beside it on the right is a "content" div of text also floated left. Naturally, their height is dependent on the content within.

Therefore the "navigation" div of only 5 links is much shorter than the multiple paragraph "content" div. (these are coloured boxes on a background of white, this is why i'm trying to line them up)

What I would like is to make these the same height so that they are lined up. Of course I could manually specify a pixel height for both of them, however I would like this CSS file to be used across multiple HTML pages, where the text content varies from 2-5 paragraphs, and manually specifying wouldn't work.

  • possible duplicate of [How might I force a floating DIV to match the height of another floating DIV?](http://stackoverflow.com/questions/526294/how-might-i-force-a-floating-div-to-match-the-height-of-another-floating-div) – Aaron Digulla May 06 '14 at 09:38
  • See my answer at http://stackoverflow.com/a/23491034/34088 – Aaron Digulla May 06 '14 at 09:40
  • @AaronDigulla this doesn't work when `float: left` is used: [Updated Fiddle](http://jsfiddle.net/6j58h/2/) – Re Captcha May 06 '14 at 09:43
  • 1
    @ReCaptcha: `float` is an ugly hack which you don't need if you use `display: table-cell`. – Aaron Digulla May 06 '14 at 10:00

1 Answers1

3

Please check below answer.

HTML

<div class="container clearfix">
<div class="sidebar">
    <ul>
        <li>link1</li>
        <li>link1</li>
        <li>link1</li>
        <li>link1</li>
    </ul>
</div>
<div class="content">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
</div>

CSS

.container{border:1px red solid; position:relative;}
.sidebar {float:left;width:150px;border:1px green solid;position:absolute;top:0;bottom:0;left:0;}
.sidebar ul{list-style:none;padding:0;margin:0;}
.content{float:left;width:300px;border:1px orange solid;margin-left:160px;}
.clearfix:before, .clearfix:after { content: " "; display: table; }
.clearfix:after { clear: both; }
.clearfix { *zoom: 1;}

Below is the fiddle of my code. You can solve this by many way I just mentioned one.

http://jsfiddle.net/murli2308/htZhG/

murli2308
  • 2,976
  • 4
  • 26
  • 47