CSS to center page with no top space
Question posted by: torweb
(Newbie)
on
January 28th, 2008 05:07 PM
I'm using CSS to center my pages...which works fine, however I would also like to eliminate the small space at the top so my page is flush with the top of the screen...both in IE and FireFox. The CSS code I'm using is:
- #container {
-
width: 980px;
-
margin-right: auto;
-
margin-left: auto;
-
margin-top: none;
-
-
}
Thanks in advance for any advice..
|
|
January 28th, 2008 06:03 PM
# 2
|
Re: CSS to center page with no top space
Hi torweb,
Browsers usually add default margins and paddings on the body and other elements. To eliminate this, write:
|
|
January 28th, 2008 08:08 PM
# 3
|
Re: CSS to center page with no top space
My #Container is a Div ID. If I change the code to:
- #container {
-
width: 980px;
-
margin-right: auto;
-
margin-left: auto;
-
margin-top: none;
-
padding: 0px;
-
margin: 0px;
-
}
It still doesn't remove that space. If I put the padding and margin within the body definition, my page no longer centers. Is this not working as my style section is referring to a div.
Thanks
Last edited by eWish : August 15th, 2008 at 01:13 PM.
Reason: Please use the [code][/code] tags
|
|
January 28th, 2008 08:11 PM
# 4
|
Re: CSS to center page with no top space
As just a feeling pointed out some browsers add padding and margins where there are none. This has nothing to do with your div because it's already there. Add the code that he provided and it should work.
Thanks, Death
|
|
January 28th, 2008 08:52 PM
# 5
|
Re: CSS to center page with no top space
Am I doing this wrong as I thought I did put the margin and padding amounts in my container definiton...
- #container {
-
width: 980px;
-
margin-right: auto;
-
margin-left: auto;
-
margin-top: none;
-
padding: 0px;
-
margin: 0px;
-
}
Last edited by eWish : August 15th, 2008 at 01:13 PM.
Reason: Please use the [code][/code] tags
|
|
January 28th, 2008 08:59 PM
# 6
|
Re: CSS to center page with no top space
Quote:
Am I doing this wrong as I thought I did put the margin and padding amounts in my container definiton...
- #container {
-
width: 980px;
-
margin-right: auto;
-
margin-left: auto;
-
margin-top: none;
-
padding: 0px;
-
margin: 0px;
-
}
|
lol yes try it like this.
- * {
-
margin:0;
-
padding:0;
-
}
-
-
#container {
-
width: 980px;
-
margin-right: auto;
-
margin-left: auto;
-
margin-top: none;
-
padding: 0px;
-
margin: 0px;
Thanks, Death
|
|
January 30th, 2008 07:05 PM
# 7
|
Re: CSS to center page with no top space
Well...it may be time to hit the bottle. Here is the whole page code (temp page) and still a space. If I can get this figured out I'll always be able to help others like myself.
Thanks
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-
"http://www.w3.org/TR/html4/loose.dtd">
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-
<title>Untitled Document</title>
-
-
<style type="text/css">
-
<!--
-
{
-
margin:0;
-
padding:0;
-
}
-
-
#container {
-
width: 980px;
-
margin-right: auto;
-
margin-left: auto;
-
margin-top: none;
-
padding: 0px;
-
margin: 0px
-
}
-
-->
-
</style>
-
</head>
-
-
<body>
-
<div id="container">
-
<table width="100%" border="0" cellspacing="0" cellpadding="0">
-
<tr>
-
<td bgcolor="#CCCCCC"> </td>
-
</tr>
-
</table>
-
</div>
-
</body>
-
</html>
Last edited by eWish : August 15th, 2008 at 01:13 PM.
Reason: Please use the [code][/code] tags
|
|
January 30th, 2008 07:36 PM
# 8
|
Re: CSS to center page with no top space
You didn't add the asterisk(sp?).This is what you added:
This is what you needed to add:
- * {
-
margin:0;
-
padding:0;
-
}
Thanks, Death
|
|
January 30th, 2008 11:50 PM
# 9
|
Re: CSS to center page with no top space
Quote:
You didn't add the asterisk(sp?).This is what you added:
This is what you needed to add:
- * {
-
margin:0;
-
padding:0;
-
}
Thanks, Death
|
Death - thanks to you. I have the same issue and your solution worked fine, well in IE, but in FF, it now aligns left when it is set to align center. (same issue that original poster had.)
Last edited by jcorp : January 30th, 2008 at 11:52 PM.
Reason: way bad english
|
|
January 31st, 2008 12:58 AM
# 10
|
Re: CSS to center page with no top space
Thanks for all the great help Death....this worked great in IE and Firefox:
-
<style type="text/css">
-
<!--
-
#container {
-
width: 980px;
-
margin-right: auto;
-
margin-left: auto;
-
}
-
* {
-
margin:0;
-
padding:0;
-
}
-
-
-->
-
</style>
Last edited by eWish : August 15th, 2008 at 01:14 PM.
Reason: Please use the [code][/code] tags
|
|
January 31st, 2008 07:34 PM
# 11
|
Re: CSS to center page with no top space
Quote:
Death - thanks to you. I have the same issue and your solution worked fine, well in IE, but in FF, it now aligns left when it is set to align center. (same issue that original poster had.)
|
Post your code or a link and I'll be glad to help you.
^_^ Thanks, Death
|
|
January 31st, 2008 07:35 PM
# 12
|
Re: CSS to center page with no top space
Quote:
Thanks for all the great help Death....this worked great in IE and Firefox:
- <style type="text/css">
-
<!--
-
#container {
-
width: 980px;
-
margin-right: auto;
-
margin-left: auto;
-
}
-
* {
-
margin:0;
-
padding:0;
-
}
-
-
-->
-
</style>
|
No problem it's what I'm here for.
^_^ Death
|
|
July 1st, 2008 11:01 PM
# 13
|
Re: CSS to center page with no top space
Death where do you live!!!!! I WANT TO HUG YOU AND NEVER LET GO this has saved me sooooooooooooooooooo much time and before it was SUPER annoying to fix and you have practically just stopped me from commiting suicide think of it as you have saved many peoples lives and work that was not need to be done THANK YOU!!!!!
|
|
July 2nd, 2008 06:41 PM
# 14
|
Re: CSS to center page with no top space
Quote:
Death where do you live!!!!! I WANT TO HUG YOU AND NEVER LET GO this has saved me sooooooooooooooooooo much time and before it was SUPER annoying to fix and you have practically just stopped me from commiting suicide think of it as you have saved many peoples lives and work that was not need to be done THANK YOU!!!!!
|
Your welcome...
Thanks,
{\_/}
(' . ')
(")[DEATH](")
(")(")
|
|
August 15th, 2008 10:27 AM
# 15
|
Re: CSS to center page with no top space
Hi, I was having the same problem as the original poster. The code provided fixed it, but only in FF. In IE the page is now left aligned. Please help.
The code:
-
* {
-
margin:0px;
-
padding:0px;
-
}
-
-
-
div.container {
-
width:950px;
-
height:700px;
-
background-position:center center;
-
margin-left:auto;
-
margin-right:auto;
-
font-family:calibri, arial, verdana, 'times roman';
-
font-size:1em;
-
color:white;
-
background-color:#181717;
-
}
Also I want to make a banner start furhter down the page, but when I put a top margin on it the container makes the space again. The code is the same as shown but with the addition of:
-
div.heading {
-
width:650px;
-
height:100px;
-
border-style:inset;
-
border-width:1px;
-
border-color:white;
-
background-color:black;
-
font-family:BankGothic Md BT;
-
font-size:3em;
-
color:white;
-
text-align:center;
-
background-position:center;
-
margin-left:auto;
-
margin-right:auto;
-
margin-top:10px;
-
}
Last edited by eWish : August 15th, 2008 at 01:14 PM.
Reason: Please use the [code][/code] tags
|
|
August 15th, 2008 01:17 PM
# 16
|
Re: CSS to center page with no top space
torweb and AJM Project,
When posting code samples you are expected to surround your code with the [code][/code] tags. I have edited your posts to include them. In the future please use the code tags.
Thank You,
Kevin
Not the answer you were looking for? Post your question . . .
189,087 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Latest Articles: Read & Comment
Top HTML / CSS Forum Contributors
|