开发者

Images aren't in correct places

I've so far made a html and css file which have three images; title, navigation and content, and a unordered list for the navigation.

I want the title and navigation images to be centered with a 150px top margin which I've done and it looks perfect. Then I add in the content image and write the css for that, but when I preview it, all the images go to the center of the page (vertically) and I can't see what is causing this.

Here's the HTML code:

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>The Internet</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">

  <div id="top">
    <div id="title">

    </div><!--Title End-->

    <div id="nav">
          <ul class="nav-links">
              <li><a href="#"> Home </a></li>
          </ul><!--Nav Links End-->

     </div><!--Navigation End-->

  </div><!--Top End-->

  <div id="content"> 

  </div><!--Content End-->

  <div id="footer">

  </div><!--Fotter End-->

</div><!--Container End-->
</body>

</html>

And here's the CSS code:

* {
  margin: 0px;
  padding: 0px;
  border: none;
}

body {
  background-image: url(images/background.png);
  font-family: Arial, sans-serif;
  font-size: 12px;
  color: #ffffff;
}

#container {
margin: auto;
width: 100%
}

#top {
float: left;
width: 100%;
height: 80px;
margin-top: 150px;
}

#title {
background-image: url(images/title.png);
float: center;
width: 311px;
height: 80px;
margin-top: auto;
margin-left: 20%;
margin-right: auto;
}

#nav {
background-image: url(im开发者_Python百科ages/navigation.png);
float: center;
width: 362px;
height: 50px;
margin-left: auto;
margin-right: 20%;
margin-top: -50px;
}

#content {
background-image: url(images/content.png);
float: center;
width: 724px;
height: 500px;
margin-top: 250px;
margin-left: auto;
margin-right: auto;
}

Thanks in advance!


Your float: center; is taking the divs out of the flow of the page. You might want to just use the background-position to place your images inside of the divs instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜