I have a div called content
and within that div is a div called sidebar
. I want the sidebar to stretch to the bottom of the content
div, but it's not. Here's the relevant markup and CSS:
<div id="content">
<div id="sidebar">
<ul>
<li><a href="/register">Register</a></li>
<li><a href="/login">Login</a></li>
<li><a href="/forgotpass">Forgotten password</a></li>
</ul>
</div>
<form action="login" method="post" id="main-form">
<p class="p-username">
<label for="username">Username</label>
<?php echo form_error('username'); ?>
<input original-title="Alphanumeric characters, underscores and dashes" type="text" name="username" value="<?php echo set_value('username') ?>">
</p>
<p class="p-password">
<label for="password">Password</label>
<?php if(isset($error)): ?>
<span class="error"><?php echo $error ?></span>
<?php else: ?>
<?php echo form_error('password'); ?>
<?php endif; ?>
<input original-title="Please choose a strong password" type="password" name="password">
</p>
<p>
<input type="submit" class="primary-button" value="Log in">
</p>
</form>
<div class="clear"></div>
</div>
CSS:
#content {
width: 960px;
border: 1px solid #e7e7e7;
margin-top: 10px;
border-radius: 5px;
}
#sidebar {
width: 250px;
background: #f5f8fa;
float: left;
height: 100%;
border-right: 1px solid #e0eefb;
box-shadow: inset -5px 0px 4px -2px #e8f1f9;
margin-right: 10px;
}
#sidebar ul {
margin:; 0;
padding: 0;
list-style-type: none;
}
#sidebar ul li {
line-height: 40px;
}
#sidebar ul li a {
display: block;
width: inherit;
padding-left: 20px;
text-decoration: none;
font-size: 16px;
}
And a jsFiddle link: http://jsfiddle.net/QXfH3/
as you can see, the sidebar stops after the last list item. I want it to stretch to the bottom of the content
div. I thought adding height: 100%
would do it but apparently not. height: inherit
does nothing aswell.
Thanks.
A way to achieve this, is to set a background image for #content
which is for #sidebar
:
#content {
background: url(data:image/png;base64,[BASE64-DATA]) repeat-y; /* background-image for #sidebar */
}
remove background
, border-right
and box-shadow
from #sidebar
:
#sidebar {
width: 250px;
/* background: #f5f8fa; */
float: left;
height: 100%;
/* border-right: 1px solid #e0eefb;
box-shadow: inset -5px 0px 4px -2px #e8f1f9; */
margin-right: 10px;
}
and wrap the whole content for the right column into a div
(in this example #right
) and apply this style:
#right { display: inline-block }
This way, you don't have to care about how much content you're putting in there ;)
Live demo: http://jsfiddle.net/QXfH3/5/
If you don't want to use images, to get this illusion, the answer from Alvaro seems to be the best way