简体   繁体   中英

Problem with extending my div to the bottom of the page

I need help in extending my div to the bottom of the page when there is not enough content to do so, when I add a height of 100% to the content and container nothing changes and when I add it to the body everything messes up. I am trying to give as much information as possible and so have provided the CSS and HTML below.

CSS:

(all of it, a lot of it is probably unnecessary in regards to this problem sorry)

body {
background-color: #111014;
background-image: url("images/bg.png");
background-repeat: repeat-x;
color: #dad8df;
font-family: tahoma;
overflow-y: scroll;
}

#container {
height: 100%;
width: 1000px;
margin-left: auto;
margin-right: auto;
}

img{
border-style: none;
}

#banner {
margin-top: 45px;
margin-bottom: 38px;
height: 68px;
width: 1000px;
background-image: url("images/bannerbg.png");
}

#navigation {
height: 36px;
width: 1000px;
margin-left: 49px;
}

#content {
background-image: url("images/contentbg.png");
background-repeat: repeat-y;
height: 100%;
width: 850px;
padding-left:80px;
padding-bottom: 20px;
margin-bottom: -8px;
padding-right: 50px;
overflow: hidden;
}

#title {
height: 90px;
width: 542px;
padding-left: 60px;
padding-top: 36px;
background-image: url("images/titlebg.png");
background-repeat:no-repeat;
font-family: tahoma;
font-size: 2.5em;
color: #dad8df;
margin-left: -80px;
}

#slideshow {
height: 285px;
width: 840px;
margin-left: auto;
margin-right: auto;
background-color: #2e2c35;
float: left;
margin-bottom: 20px;
}

#slideleft {
height: 38px;
width: 23px;
background-image: url("images/slideleft.png");
float: left;
margin-left: -60px;
margin-top: 104px;
}

#slideright {
height: 38px;
width: 23px;
background-image: url("images/slideright.png");
float: right;
margin-right: -50px;
margin-top: 104px;
}

#emailform {
color: #dad8df;
font-family: tahoma;
overflow: hidden;
}

.inputs {
float: right;
width: 200px;
font: .9em tahoma;
}

#largemessage {
float: right;
clear: both;
width: 700px;
height: 150px;
resize: none;
font: .9em tahoma;
}

#submit {
margin-top: 20px;
clear: both;
float: right;
}

hr {
border-width: 3px 0 0 0;
border-style: dotted;
}

.contacterror {
margin-right: 180px;
height: 20px;
width: 300px;
color: red;
float: right;
padding-left: 20px;
}

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<title>About :: Lesley Robb Fine Art and Design</title>
<link rel="icon" type="image/png" href="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="design.css" type="text/css"/>
<script src="" type="text/javascript"></script>

</head>

<body>
<div id="container">

<div id="banner">
</div>
<div id="navigation">
<a href="index.php"><img src="images/nav_home.png" alt="Home" /></a><a href="portfolio.php"><img src="images/nav_portfolio.png" alt="Portfolio" /></a><a href="about.php"><img src="images/nav_about.png" alt="About" /></a><a href="contact.php"><img src="images/nav_contact.png" alt="Contact" /></a>
</div>
<div id="content">
<div id="title">
About
</div>
You can edit this section after you Log In to the Control Panel. :)</div>
</div>

</body>
</html>

The Page As it Currently Is

An image of it for future reference once I have fixed the problem

Thanks in advance for your time, Callum

Usually, if you add

body, html{
    height:100%;
}

the container div will inherit from it.

尝试使用一种称为Faux Columns的技术。

Try setting the height on your #container div to auto.

#container { 
     height:auto;

That should do it!

As the doc said:

The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (ie, it depends on content height), and this element is not absolutely positioned, the value computes to 'auto'

http://www.w3.org/TR/CSS2/visudet.html#the-height-property

If adding html,body { height:100%; } html,body { height:100%; } mess up, it's certainly because browsers set default margin/padding for these elements.

The simpler solution for your problem is to set for #container min-height the viewport height and set it a background which will fake #content reaches the bottom. Faux columns as Nathaniel said.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM