yhsdygdyusgdysgdsudsd
yhsdygdyusgdysgdsudsd

Reputation: 103

Making the height of a div depend on the height of another div?

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.

Upvotes: 0

Views: 199

Answers (1)

murli2308
murli2308

Reputation: 3002

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/

Upvotes: 3

Related Questions