943,660 Members | Top Members by Rank

Ad:
Mar 14th, 2007
0

Why is this page center aligned?

Expand Post »
Hi,

I have this page designed in html and css. but what I can't understand is without mentioning any thing about the alignment of this page as center aligned, this page is center aligned for some reason. Generally as far as I understand this tag "text-align:center" if put in the main body of the page makes the page look center-aligned. But I have not done so. I am learning css on my own and am not an expert so please bear with me. Can any one please let me know as why this page is center aligned? Thanks,

This is the html code:

HTML and CSS Syntax (Toggle Plain Text)
  1.  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<a rel="nofollow" href="http://www.w3.org/TR/html4/loose.dtd" target="_blank">http://www.w3.org/TR/html4/loose.dtd</a>">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <title>Web site design </title>
  7. <link href="good.css" rel="stylesheet" type="text/css">
  8. <meta name="keywords" content="content management, online booking, database, solutions, databases, software, development,">
  9. <meta name="description" content="Web site design, graphic design, website software systems development and web promotion
  10. projects services. Specialists in e-commerce, hotel and tourism websites.">
  11. </head>
  12. <body>
  13. <div id="maincontainer">
  14. <div id="footercontainer">
  15. <div id="top">
  16. <img src="top.gif" alt="Website Design" width="699" height="80">
  17. </div>
  18. <div id="google"><!-- Google CSE Search Box Begins -->
  19. <form id="searchbox_009844139294785558261:viu5inxbnja" action="<a rel="nofollow" href="http://www.google.com/cse" target="_blank"> http://www.google.com/cse</a> ">
  20. <input type="hidden" name="cx" value="009844139294785558261:viu5inxbnja" />
  21. <input name="q" type="text" size="20" />
  22. <input type="submit" name="sa" value="Search" />
  23. <input type="hidden" name="cof" value="FORID:1" />
  24. </form>
  25. </div>
  26. <div id="nav">
  27. <ul>
  28. <li> <a href="index.asp"> home </a> </li>
  29. <li> | <a href="contact/callback.asp"> call back </a> </li>
  30. <li> | <a href="clients/casestudies.asp"> our clients </a> </li>
  31. <li> | <a href="website-design-services/services.asp"> services </a> </li>
  32. <li> | <a href="website-design-company/company.asp"> company </a> </li>
  33. <li> | <a href="news/news.asp"> news </a> </li>
  34. <li> | <a href="website-design-services/supportform.asp"> support </a> </li>
  35.  
  36. </ul>
  37. </div>
  38. <div id="mainimage">
  39. <img src="stones1.jpg" alt="Website design, James Bond">
  40. </div>
  41. <div id="title">
  42. <h1> < LEADING WEB SITE DESIGN AGENCY> </h1>
  43. </div>
  44. <div id="testimonials"> <h1> CLIENT TESTIMONIALS</h1>
  45. <p> Cheers</p>
  46. <p> Good Work<br>
  47.  
  48. </p>
  49. </div>
  50. <div id="testimonialcontent">
  51. <p> "We have provided a friendly, efficient and quality service of design and development solutions, helping us
  52. communicate more effectively with our stakeholders." <a href="<a rel="nofollow" href="http://www.goodjob.org.uk/" target="_blank">http://www.goodjob.org.uk</a>" target="_blank">www.good.org.uk</a>
  53. </p>
  54. <p>&quot;You promised you could deliver on time and you did. You promised to listen to our needs and you did. You all
  55. managed to do it all with a smile.....my expectations were high and I am suitably impressed&quot;<br>
  56. <a href="<a rel="nofollow" href="http://www.good.org.uk/" target="_blank"> http://www.good.org.uk</a> " target="_blank">www.goodwork.org.uk</a> </p>
  57. </div>
  58. <div id="launch"> <a href="clients/clients.asp"> launch</a> </div>
  59. <div id="download"> <a href="PDF/Commendations.pdf" target="_blank"> download</a> </div>
  60. <div id="about">
  61. <h1> WHAT WE DO</h1>
  62. <ul>
  63. <li> High quality, long established website design agency</li>
  64. <li> Content Managed web site packages to suit all budgets</li>
  65. <li> Expandable website solutions that grow with your business</li>
  66. <li> Dynamic website modules to deliver real business benefits</li>
  67. <li> E-commerce development, integration and customisation</li>
  68. <li> Search Engine Optimisation and PPC campaign management</li>
  69. <li> Customer support and maintenance packages </li>
  70. </ul>
  71. </div>
  72.  
  73. <div id="footer">
  74. <p> Web site design © <a href="<a rel="nofollow" href="http://www.good.net/" target="_blank">http://www.good.net</a>" target="_blank">Good Job</a></p>
  75. <p>0111 7900 924 |
  76. </p>
  77. </div>
  78. <div id="footerlinks">
  79. <p><a href="contact/contact.asp">Contact Us </a> |<a href="wgood/terms.asp"> Terms</a> | <a
  80. href="good.asp">Privacy</a> | <a href="good.asp">Sitemap</a></p>
  81. <p>Photography courtesy of <a href="<a rel="nofollow" href="http://www.good.co.uk/" target="_blank"> http://www.good.co.uk/</a> " target="_blank">James Bond</a> </p>
  82. </div>
  83. </div>
  84. </div>
  85. </body>
  86. </html>

Here is the separate css sheet.


[php]body {
margin: 0px;
padding: 0px;
background-image: url('background.jpg');
}

#maincontainer {
width: 700px;
margin: 0px auto;
position: relative;border: red 4px dashed;
background-image:url('backgroundnew.jpg');padding-left:25px; padding-right:25px; padding-top:0px; padding-bottom:0px
}
#top {
top: 0px;
margin: 0px;
padding: 0px;
position: absolute;
}
#nav {
top: 59px;
margin: 0;
padding: 0;
position: absolute;
height: 20px;
width: 700px;
font: 9px Verdana, Arial, Helvetica, sans-serif;
}
#nav ul {
margin: 0;
padding: 0px 0px 0px 265px;
}
#nav li {
display:inline;
margin: 0;
padding: 0;
}
#nav li a {
font: bold 11px Verdana, Arial, Sans-Serif;
color: #666;
text-decoration: none;
}
#nav li a:hover {
color: #FF8000;
}
#mainimage {
top: 85px;
position: absolute;
}
#title {
top: 243px;
height: 35px;
width: 700px;
position: absolute;
background-image:url('title.gif');
padding: 0;
margin: 0
}
#title h1 {
font: bold 10px Verdana, Arial, Helvetica, Sans-Serif;
color: #fff;
margin: 5px 10px 4px 65px;
}
#testimonials {
top: 278px;
width: 350px;
height: 120px;
background-image: url('testimonialsback.gif');
position:absolute;
background-repeat: no-repeat
}
#testimonials h1 {
font: 12px Arial, Helvetica, sans-serif;
color: #666;
margin: 20px 0px 0px 0px;
}
#testimonials p {
font: 11px Arial, Helvetica, sans-serif;
color:#FF6600;
margin: 14px 0px 55px 5px;
}
#about {
top: 278px;
left: 365px;
width: 330px;
height: 150px;
position:absolute;
background-image:url('newback.gif');
}
#about h1 {
font: 12px Arial, Helvetica, sans-serif;
color: #666;
margin: 20px 0px 0px 6px;
}
#about p {
font: 11px/16px Arial, Helvetica, sans-serif;
color: #666666;
margin: 14px 15px 0px 5px;
}
#about a {
font: bold 11px Arial, Helvetica, sans-serif;
text-decoration:none;
color: #999;
margin: 0px 0px 0px 0px;
padding: 0;
}
#about a:hover {
color: #FF8000;
}
#about ul {
padding: 0;
list-style-image:url('arrow.gif');
color: #999; margin-left:25px; margin-right:0px; margin-top:10px; margin-bottom:0px

}
#about li {
font: 11px Arial, Helvetica, sans-serif;
color: #666;
margin: 0px 0px 15px 0px;
padding: 0;
margin: 2px;

}
#about li a {
color: #FF6600;
text-decoration:none;
}
#about li a:hover {
color: #333;
}
#downloadabout {
top: 299px;
left: 492px;
position: absolute;
width: 150px;
}
#downloadabout a {
font: bold 11px Arial, Helvetica, sans-serif;
text-decoration:none;
color: #999;
margin: 0px 0px 0px 0px;
padding: 0;
}
#downloadabout a:hover {
color: #FF8000;
}
#launch {
top: 299px;
left: 170px;
position:absolute;
}
#launch a {
font: bold 11px Arial, Helvetica, sans-serif;
text-decoration:none;
color: #999;
margin: 0px 0px 0px 0px;
padding: 0;
}
#launch a:hover {
color: #FF8000;
}
#download {
top: 299px;
left: 250px;
position:absolute;
}
#download a {
font: bold 11px Arial, Helvetica, sans-serif;
text-decoration:none;
color: #999;
margin: 0px 0px 0px 0px;
padding: 0;
}
#download a:hover {
color: #FF8000;
}
#testimonialcontent {
left: 80px;
top: 327px;
width: 255px;
position: absolute;
}
#testimonialcontent p {
font: 11px Arial, Helvetica, sans-serif;
color: #666666;
margin: 0px 0px 14px 0px;
}
#testimonialcontent a {
color: #FF6600;
text-decoration:none;
}
#testimonialcontent a:hover {
color: #333;
}
#footer {
position: absolute;
width: 690px;
bottom: 0;
background-image:url('bottom.gif');
margin: 0; padding-left:10px; padding-right:0px; padding-top:15px; padding-bottom:0px
}
#footer p {
font: 11px Arial, Helvetica, sans-serif;
color: #666;
margin: 0px 0px 7px 0px;
}
#footer a {
color:#FF9900;
text-decoration:none;
}
#footer a:hover {
color: #666666;
}
#footercontainer {
position: relative;
height: 780px;
width: 700px;
}
#footerlinks {
position: absolute;
width: 220px;
bottom: -3px;
left: 482px;
font: 11px Arial, Sans-serif;
color: #666666;
margin: 0;
padding: 2px 0px 0px 0px;
}
#footerlinks p {
margin: 0;
padding: 0px 0px 8px 0px;
text-align: right;
}
#footerlinks a {
font: 11px Arial, Helvetica, sans-serif;
color: #FF9900;
text-decoration: none;
}
#footerlinks a:hover {
color: #666666;
}
#google {
position: absolute;
top: 20px;
left: 485px;
height: 50px;
width: 220px;
} [/php]
Last edited by tech291083; Mar 14th, 2007 at 12:15 pm.
Similar Threads
Reputation Points: 15
Solved Threads: 0
Junior Poster
tech291083 is offline Offline
181 posts
since Oct 2006
Mar 14th, 2007
0

Re: Why is this page center aligned?

this line:
HTML and CSS Syntax (Toggle Plain Text)
  1. margin: 0px auto;

is setting some of the margins on your '#maincontainer' div to be auto. auto means; take a proportion of the available space. Generally, if you set the left and right margins of something to be "auto" it has the effect of aligning it in the middle of the page. This only happens if you give something a specific size (or if it has a specific size). in this case, you are giving the main container a width of 700px; so left and right auto margins will each take ( 50% of ( the width of the page minus 700 px ) ); and that will center the maincontainer div.

Note, that this isn't the same as using text-align: center. text-align: center aligns 'text' (and certain objects) in a container around the container's horizontal center. But, margin-left:auto;margin-right:auto; aligns an object to the center of its container regardless of text alignment rules in that container.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Mar 15th, 2007
0

Re: Why is this page center aligned?

Click to Expand / Collapse  Quote originally posted by MattEvans ...
this line:
HTML and CSS Syntax (Toggle Plain Text)
  1. margin: 0px auto;
Excellent reply my friend. I was trying very hard to get to grips with the whole idea of margin since being a newbie in the field of web design. Your explanation makes good sense. Here is something very similar to your reply that I just came across.

http://www.w3.org/TR/CSS21/visudet.html#blockwidth

Thanks a lot. Appreciated.
Last edited by tech291083; Mar 15th, 2007 at 7:43 am.
Reputation Points: 15
Solved Threads: 0
Junior Poster
tech291083 is offline Offline
181 posts
since Oct 2006
Mar 25th, 2007
0

Re: Why is this page center aligned?

Click to Expand / Collapse  Quote originally posted by MattEvans ...
this line:
HTML and CSS Syntax (Toggle Plain Text)
  1. margin: 0px auto;

is setting some of the margins on your '#maincontainer' div to be auto. auto means; take a proportion of the available space. Generally, if you set the left and right margins of something to be "auto" it has the effect of aligning it in the middle of the page. This only happens if you give something a specific size (or if it has a specific size). in this case, you are giving the main container a width of 700px; so left and right auto margins will each take ( 50% of ( the width of the page minus 700 px ) ); and that will center the maincontainer div.

Note, that this isn't the same as using text-align: center. text-align: center aligns 'text' (and certain objects) in a container around the container's horizontal center. But, margin-left:auto;margin-right:auto; aligns an object to the center of its container regardless of text alignment rules in that container.
well defined.. easy to understand.. thanks!
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Gmarvz is offline Offline
13 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: does <img tag has disable property
Next Thread in HTML and CSS Forum Timeline: java





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC