How can i start at the exact top of the website in css
i tried to display a bar at the top of the web page but the bar appears about 5 px empty place at the top, right and left sides of the page. The image was 1 black line and i wanted to repeat it from left to right. How can i fix it?
ul.postinge
{
width:auto;
position:relative;
margin:0cm 0cm 0cm 0 cm;
display:block;
height:105px;
b开发者_运维知识库ackground:url(images/bar.jpg) repeat-x top left;
}
Thanks
in some browsers the body
and or html
elements have margins or padding. Many experienced CSS developers use CSS resets, but all you should need is:
html, body
{
margin: 0;
padding: 0;
}
I typically discourage people from using pre-built CSS resets, as I believe it's more important to have a good understanding of what styles are being set and why. That being said, re-using a core stylesheet that resets styles to the site-specific format is a good idea.
That being said, you're liable to come across:
*
{
margin: 0;
padding: 0;
}
Which may help in this particular case, however you're likely going to come across unexpected issues involving forms and tables by using this "simple" style.
Use a CSS reset like: http://developer.yahoo.com/yui/reset/
You need to reset the body tag:
body {margin:0;padding:0}
Using a reset will allow you to "normalize" the margins and padding for your lists as well, among other things
Same as others are saying, only thing I'd add is list-style
and border
are other good things to reset too. Generally you never want things unless you specifically specify them.
* { margin: 0; padding: 0; list-style: none; border: none; }
What *
does, is it's a wildcard that effects all elements on the page. It can be used in more specific cases as well, for example: if you have container with an id of container
you could make all elements within it have a red border with the following code:
#container * {
border: 1px solid #F00;
}
body { margin: 0; padding: 0; }
Also:
margin:0cm 0cm 0cm 0 cm;
- are we really measuring in centimeters?
- also note the extra space after the last 0
ul.postinge { width: auto; position: relative; margin: 0; padding: 0; display: block; height: 105px; background: url('images/bar.jpg') repeat-x top left; }
add this style in ur css
*{margin:0; padding:0;}
you have to do this because every element has its default margin and padding. By doing this u r setting all elements default padding and margin to zero.
精彩评论