Reputation: 55
There seems to be an unknown margin or padding that comes in between my header navi ID tags.
Here are the div tags:
<div id="container">
<div id="header">
<p align="center">HEADER</p>
</div>
<div id="navi">
<p align="center">NAVIGATION</p>
</div>
</div>
The stylesheet that goes with it:
#container
{
width: 800px;
background-color: #AFAF97;
margin: 0px auto;
}
#header
{
height: 75px;
width: 100%;
background-color: #888888;
}
#navi
{
height: 50px;
width: 100%;
background-color: #aaaaaa;
/*margin-top: -16px;*/
}
Here's the screenshot of the unknown margin/padding. https://i.sstatic.net/v7FMg.jpg
The alternative fix is to put a negative margin-top value. But why and how is it there?
Upvotes: 3
Views: 7357
Reputation: 3775
Always use reset styles
* {
margin: 0;
padding: 0;
}
Using a CSS Reset, CSS authors can force every browser to have all its styles reset to null, thus avoiding cross-browser differences as much as possible.
a little more advanced css reset.
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fixed:demo
Upvotes: 4
Reputation: 8981
Like this
css
*{
margin:0;
padding:0;
}
body{
margin:0;
padding:0;
}
Upvotes: 0