How do I remove the white bar on top of my parallax scrolling effect?

Viewed 200

If I want to change the background color of my text inside the parallax scrolling effect there's a white bar on top of it. I tried changing every color that I wrote down but it didn't disappeared. You can see the white bar here. Do I need to change a color in CSS or do I need to need to create a new div?

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {box-sizing: border-box;}

.parallax {

  background-image: url("pexels-philippe-donn-1169754.jpg");

  /* specific heigh */
  min-height: 500px; 

  /*parallax scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

.header {
  overflow: hidden;
  background-color: #f1f1f1;
  padding: 20px 10px;
}

.header a {
  float: left;
  color: black;
  text-align: center;
  padding: 12px;
  text-decoration: none;
  font-size: 18px;
  line-height: 25px;
  border-radius: 4px;
}

.header a.logo {
  font-size: 25px;
  font-weight: bold;
}

.header a:hover {
  background-color: #ddd;
  color: black;
}

.header a.active {
  background-color: dodgerblue;
  color: white;
}

.header-right {
  float: right;
}

@media screen and (max-width: 500px) {
  .header a {
    float: none;
    display: block;
    text-align: left;
  }

  .header-right {
    float: none;
  }
}
</style>
</head>
<body>

<div class="header">
  <a href="#default" class="logo">Space, Universe And Other Stuff</a>
  <div class="header-right">
    <a class="active" href="#home">Home</a>
    <a href="#chat">Chat</a>
    <a href="#personalprojects">Personal Projects</a>
    <a href="#contact">Contact</a>
    <a href="#about">About</a>
  </div>
</div>

<div class="parallax"></div>

<div style="height:700px;background-color:lightgrey;font-size:36px">

<div style="padding-left:20px">
  <h1>Text</h1>
  <p>Text....</p>
  <p>More text...</p>
</div>

<div class="parallax"></div>

</body>
</html>
3 Answers

Default margin to h1 is causing the issue.

....

<div style="padding-left:20px">
  <h1 style="margin-top:0px">Text</h1>
  <p>Text....</p>
  <p>More text...</p>
</div>

....

you should add a class instead of adding style attribute

It appears to be the <h1> tag's default margin sticking out the top. Try clearing the margin with

h1 {margin: 0;}

If you do need some gray space above the <h1> you could add padding instead.

Set margin: 0; on your h1 element.

* {
  box-sizing: border-box;
}

h1 {
  margin: 0;
}
.parallax {
  background-image: url("https://i0.wp.com/www.fmxexpress.com/wp-content/uploads/2020/09/pexels-philippe-donn-1169754.jpg");
  /* specific heigh */
  min-height: 500px;
  /*parallax scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

.header {
  overflow: hidden;
  background-color: #f1f1f1;
  padding: 20px 10px;
}

.header a {
  float: left;
  color: black;
  text-align: center;
  padding: 12px;
  text-decoration: none;
  font-size: 18px;
  line-height: 25px;
  border-radius: 4px;
}

.header a.logo {
  font-size: 25px;
  font-weight: bold;
}

.header a:hover {
  background-color: #ddd;
  color: black;
}

.header a.active {
  background-color: dodgerblue;
  color: white;
}

.header-right {
  float: right;
}

@media screen and (max-width: 500px) {
  .header a {
    float: none;
    display: block;
    text-align: left;
  }
  .header-right {
    float: none;
  }
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

  <div class="header">
    <a href="#default" class="logo">Space, Universe And Other Stuff</a>
    <div class="header-right">
      <a class="active" href="#home">Home</a>
      <a href="#chat">Chat</a>
      <a href="#personalprojects">Personal Projects</a>
      <a href="#contact">Contact</a>
      <a href="#about">About</a>
    </div>
  </div>

  <div class="parallax"></div>

  <div style="height:700px;background-color:lightgrey;font-size:36px">

    <div style="padding-left:20px">
      <h1>Text</h1>
      <p>Text....</p>
      <p>More text...</p>
    </div>

    <div class="parallax"></div>

</body>

</html>

Related