Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whitespace on top of website [duplicate]

I have a whitespace on top of my website that i want to remove and dont know how:

body {
  border: 0;
  padding: 0;
  margin: 0;
}

.header {
  width: 900px;
  height: 100px;
  background-color: #5132FF;
  text-align: center;
  margin-left: auto;
  margin-right: auto;
  margin-top: 0;
  border: 0;
  top: 0;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>DevDoWeb.com</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="=width=1920, initial-scale=1.0, user-scalable=yes">
    <link rel="stylesheet" type="text/css" href="styleSheet.css">
    <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
  </head>
  <body>
    <div class="header">
      <h3 class="headerText">Test</h3>
    </div>
  </body>
</html>

The dev tools tell me that it cant be maring, padding, or border.... i am really clueless on what to do here, any help is appreciated.

like image 851
griesgram Avatar asked May 30 '18 07:05

griesgram


2 Answers

In this case the white space is caused by the margin added from the browser stylesheet to h3. If you remove that by giving h3 a margin of 0, you get rid of the white space.

body {
  border: 0;
  padding: 0;
  margin: 0;
}

.header {
  width: 900px;
  height: 100px;
  background-color: #5132FF;
  text-align: center;
  margin-left: auto;
  margin-right: auto;
  margin-top: 0;
  border: 0;
  top: 0;
}

h3 {
  margin-top: 0;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <title>DevDoWeb.com</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="=width=1920, initial-scale=1.0, user-scalable=yes">
  <link rel="stylesheet" type="text/css" href="styleSheet.css">
  <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
</head>

<body>
  <div class="header">
    <h3 class="headerText">Test</h3>
  </div>
</body>

</html>
like image 122
Maharkus Avatar answered Oct 16 '22 19:10

Maharkus


Try This:

h3 {
  margin: 0;
}

body {
  border: 0;
  padding: 0;
  margin: 0;
}

.header {
  width: 900px;
  height: 100px;
  background-color: #5132FF;
  text-align: center;
  margin-left: auto;
  margin-right: auto;
  margin-top: 0;
  border: 0;
  top: 0;
}

h3 {
  margin: 0;
}
<div class="header">
  <h3 class="headerText">Test</h3>
</div>
like image 36
Ehsan Avatar answered Oct 16 '22 20:10

Ehsan