-3

i want to get rid of the white margin around my website . I have set on #body #header and #html margin:0; and padding:0; Can someone please help

Here is the HTML code:

<DOCTYPE html>
<html>
<header> 
<link href="CSS/stylesheet.css" rel=stylesheet>
</header>   
<body>
<div id="bannertop"></div>

</body>
</html>

And the CSS:

#html{
    margin: 0 !important;
    padding: 0 !important;
}
#header{
    margin: 0 !important;
    padding: 0 !important;
}
#body{
    margin: 0 !important;
    padding: 0 !important;
}
#bannertop{
   height: 200px;
   width: 100%;
   background-color: cadetblue;
   margin-top:0px;

} 

Here is a picure of the website Website

4 Answers4

1

You need to remove the # from html,body and header because # use for ID and . for class difference between ID & Class

html,body{
    margin: 0 !important;
    padding: 0 !important;
}
header{
    margin: 0 !important;
    padding: 0 !important;
}

#bannertop{
   height: 200px;
   width: 100%;
   background-color: cadetblue;
   margin-top:0px;

}
Baezid Mostafa
  • 2,680
  • 2
  • 14
  • 26
0

Welcome to StackOverflow!

You are not referencing some of your elements correctly. The # selector (in front of html, body and header in your CSS) target elements with id attributes set the the value after the #.

Due to your HTML elements you are attempting to reference not having IDs your CSS has not targeted the elements correctly.

To fix it you must remove the # in front of html and body. You can also write this more concisely by using multiple selectors:

html, body {
  margin: 0 !important;
  padding: 0 !important;
}

FYI you have a minor mistake using header instead of head.


If you're currently learning HTML and CSS I recommend the following resources:

Wing
  • 8,438
  • 4
  • 37
  • 46
0

remove # before the body and html

html{
    margin: 0 !important;
    padding: 0 !important;
}
#header{
    margin: 0 !important;
    padding: 0 !important;
}
body{
    margin: 0 !important;
    padding: 0 !important;
}
#bannertop{
   height: 200px;
   width: 100%;
   background-color: cadetblue;
   margin-top:0px;

} 
<DOCTYPE html>
<html>
<header> 
<link href="CSS/stylesheet.css" rel=stylesheet>
</header>   
<body>
<div id="bannertop"></div>

</body>
</html>
jafarbtech
  • 6,842
  • 1
  • 36
  • 55
-2

try this:

* {
    margin: 0;
}

it should set all the margin to 0 on every element. you can just overide it by keeping it at the start of your css and adding diferent margins to other elements

Grey
  • 877
  • 9
  • 29