Jump to content

not able to align div properly


Alicia

Recommended Posts

Hi,

 

Can some guru help me to check what have I done incorrectly in this simple css layout? After I adjusted the div on top before the content div, the content and footer div is all aligned to far right which I never adjusted. I tried to move it back inside the container and align the content to left but failed. I am wondering how come the div from content to footer will move to such position.

 

Besides, can you give me an idea what I have done on the top positioning is correct or not. I can get the positioning of the div i want on top before the content but i am wondering why negative value is required to make it fit into the container.

 

Please advise and thanks.

 

<!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>Untitled Document</title>
<style type="text/css">
#page-container {
    width: 960px;
    margin: 0 auto;
}

#main-nav {
    height: 30px;
    position: relative;
    background-color: #CFF;
    width: 300px;
    top: -95px;
    left: -145px;
    float: left;
}

#sidebar-a {
    background: darkgreen;
    float: left;
    position:relative;
}

#content {
    background: green;
    width: 960px;
    position: relative;
}

#footer {
    background: orange;
    height: 66px;
}

#logo {
    width : 200px;
    height: 100px;
    margin-top:52px;
    padding-left:10px;
    position: relative;
}

#mailinglistbox {
    width : 450px;
    height: 50px;
    background-color:#09F;
    margin-right:220px;
    float:left;
    position: relative;
    left: 225px;
    top: -115px;
}

#topcontactbox {
    width : 250px;
    height: 30px;
    background-color:#FF6;
    margin-right:120px;
    float:left;
    position: relative;
    left: 695px;
    top: -155px;
}

body {
    margin-top: 0px;
    background-image: url(images/mainbg.jpg);
    background-repeat: repeat-x;
    background-color: #F0F4F5;
}

</style>
</head>
<body>
<div id="page-container">
  <div id="logo"><img src="images/logo.gif" width="179" height="82" /></div>
  <div id="mailinglistbox">mailing list box</div>
    <div id="topcontactbox">contact</div>
    <div id="main-nav">Main Nav</div>
    <div id="content">Content</div>
    
    <div id="footer">Footer</div>

</div>
</body>
</html>



Link to comment
Share on other sites

  • 1 month later...

Hi I copied your code to notepad++ and played around with it, i have found the solution!

 

 

i have to admit i also tried "text-align:left" to no success.

i then tried "clear:both"

 

 

in the html this is a class

<div class="clear"><>

 

 

Below is your fixed 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>Untitled Document</title>
<style type="text/css">
#page-container {
    width: 960px;
    margin: 0 auto;
}


#main-nav {
    height: 30px;
    position: relative;
    background-color: #CFF;
    width: 300px;
    top: -95px;
    left: -145px;
    float: left;
}


#sidebar-a {
    background: darkgreen;
    float: left;
    position:relative;
}


#content {
    background: green;
    width: 960px;
    position: relative;
}


#footer {
    background: orange;
    height: 66px;
}


#logo {
    width : 200px;
    height: 100px;
    margin-top:52px;
    padding-left:10px;
    position: relative;
}


#mailinglistbox {
    width : 450px;
    height: 50px;
    background-color:#09F;
    margin-right:220px;
    float:left;
    position: relative;
    left: 225px;
    top: -115px;
}


#topcontactbox {
    width : 250px;
    height: 30px;
    background-color:#FF6;
    margin-right:120px;
    float:left;
    position: relative;
    left: 695px;
    top: -155px;
}


body {
    margin-top: 0px;
    background-image: url(images/mainbg.jpg);
    background-repeat: repeat-x;
    background-color: #F0F4F5;
}


.clear
{
   clear:both;
}


</style>
</head>
<body>
<div id="page-container">
  <div id="logo"><img src="images/logo.gif" width="179" height="82" /><>
  <div id="mailinglistbox">mailing list box<>
    <div id="topcontactbox">contact<>
    <div id="main-nav">Main Nav<>
   <div class="clear"><>
    <div id="content">Content<>
    <div class="clear"><>
    <div id="footer">Footer<>


<>
</body>
</html>

 

 

PS: add the closing div tags after each opening div!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.