Web-Student214
Web-Student214

Reputation: 127

how to remove whitespace below div element

I have some divs and among them there's a small gap or whitespace. I have tried changing margin top and bottom but it is not working. I think it's something to do with the image but I have not found a solution yet.

HTML

<!DOCTYPE html>
<html lang = "en-us">
    <head>
        <title>Vizion Fitness</title>
        <link href="https://fonts.googleapis.com/css?family=Roboto:400,500" rel="stylesheet">
        <link rel = "stylesheet" type = "text/css" href = "vizion.css">
    </head>
<body>

            <div class = "clearfix menu">
                <a href = "#" class = "logo">Vizion Fitness</a>

                <a href = "#contact-title" class = "nav-links last">Contact</a>

                <a href = "#portfolio" class = "nav-links">Pricing</a>

                <a href = "#skills" class = "nav-links">Trainers</a>

                <a href = "#about-me" class = "nav-links ">Home</a>
            </div>

    <div id = "header-bg">
        <div id = "header-wrapper">

        </div>
    </div>

`   <div class = "details-wrapper">

    </div>
</body>
</html>

CSS

body{
    margin: 0;
    padding: 0;
    font-family: 'Roboto', sans-serif;
    font-weight: 400;
    line-height: 1.43;
    color: red;
}

p{
    font-size: 16px;
}

a:link{
    font-size: 16px;
    text-decoration: none;
    margin: 0;
    padding: 0;
}

a:visited{
    text-decoration: none;
    margin: 0;
    padding: 0;
}

h1,h2,h3,h4,h5,h6,ul,ol,li{
    margin: 0;
    padding: 0;

}

ul, ol{
    list-style-type: none;
}

::selection{
    color: #fff;
    background-color: #333;
}

::-moz-selection{
    color: #fff;
    background-color: #333;
}

.clearfix::after{
    content: "";
    display: table;
    clear: both;
}




.menu{
    position:relative;
    background-color: #666666;
    width: 100%;
    height: auto;
    top: 0;
    left: 0;
    z-index: 150;
    margin-bottom: 0;
}

.logo:link{
    float: left;
    font-size: 28px;
    color: white;
    margin-left: 30px;
    margin-top: 20px;
    margin-bottom: 20px;


}

.nav-links:link{
    float: right;
    font-size: 18px;
    color: white;
    margin-right: 20px;
    margin-top: 30px;
    transition: all 0.2s ease;
    -webkit-transition: all 0.2s ease-in-out;
    -moz-transition: all 0.2s ease-in-out;
    -o-transition: all 0.2s ease-in-out;

}

.nav-links:hover{
    color: #ff5b5b;
}

#header-bg{
    position: relative;
    width: 100%;
    height: 590px;
    margin-top: 0;
    background-image: url(bg.jpg);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    line-height: 0px;


}

#header-wrapper{
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-flow: row wrap;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    line-height: 0px;

}

/*-----------------------------------------------------DETAILS----------------------------*/

.details-wrapper{
    position: relative;
    width: 100%;
    height: 400px;
    background-color: red;

}

Upvotes: 2

Views: 100

Answers (4)

Simo Mafuxwana
Simo Mafuxwana

Reputation: 3762

You have a ` between those divs

Replace those divs with this

    <div id = "header-bg">
        <div id = "header-wrapper">

        </div>
    </div>

   <div class = "details-wrapper">

    </div>

Upvotes: 2

Geeky
Geeky

Reputation: 7498

Poistioning and display:flex does not well together.

If you want to use position:absolute on the flexed container apply position:absolute on #header-bg,it is because of that you have the white space

check this snippet

body {
  margin: 0;
  padding: 0;
  font-family: 'Roboto', sans-serif;
  font-weight: 400;
  line-height: 1.43;
  color: red;
}
p {
  font-size: 16px;
}
a:link {
  font-size: 16px;
  text-decoration: none;
  margin: 0;
  padding: 0;
}
a:visited {
  text-decoration: none;
  margin: 0;
  padding: 0;
}
h1,
h2,
h3,
h4,
h5,
h6,
ul,
ol,
li {
  margin: 0;
  padding: 0;
}
ul,
ol {
  list-style-type: none;
}
::selection {
  color: #fff;
  background-color: #333;
}
::-moz-selection {
  color: #fff;
  background-color: #333;
}
.clearfix::after {
  content: "";
  display: table;
  clear: both;
}
.menu {
  position: relative;
  background-color: #666666;
  width: 100%;
  height: auto;
  top: 0;
  left: 0;
  z-index: 150;
  margin-bottom: 0;
}
.logo:link {
  float: left;
  font-size: 28px;
  color: white;
  margin-left: 30px;
  margin-top: 20px;
  margin-bottom: 20px;
}
.nav-links:link {
  float: right;
  font-size: 18px;
  color: white;
  margin-right: 20px;
  margin-top: 30px;
  transition: all 0.2s ease;
  -webkit-transition: all 0.2s ease-in-out;
  -moz-transition: all 0.2s ease-in-out;
  -o-transition: all 0.2s ease-in-out;
}
.nav-links:hover {
  color: #ff5b5b;
}
#header-bg {
  position: relative;
  width: 100%;
  height: 590px;
  margin-top: 0;
  background-image: url(https://storage.googleapis.com/gweb-uniblog-publish-prod/static/blog/images/google-200x200.7714256da16f.png);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
  line-height: 0px;
}
#header-bg {
  position: absolute;
}
#header-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  line-height: 0px;
}
/*-----------------------------------------------------DETAILS----------------------------*/

.details-wrapper {
  position: relative;
  width: 100%;
  height: 400px;
}
<html lang="en-us">

<head>
  <title>Vizion Fitness</title>
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,500" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="vizion.css">
</head>

<body>

  <div class="clearfix menu">
    <a href="#" class="logo">Vizion Fitness</a>

    <a href="#contact-title" class="nav-links last">Contact</a>

    <a href="#portfolio" class="nav-links">Pricing</a>

    <a href="#skills" class="nav-links">Trainers</a>

    <a href="#about-me" class="nav-links ">Home</a>
  </div>

  <div id="header-bg">
    <div id="header-wrapper">

    </div>
  </div>

  <div class="details-wrapper">
    heyllo--details wrapper
  </div>
</body>

</html>

Hope it helps

Upvotes: 0

Felix A J
Felix A J

Reputation: 6470

There is a ` character in html, which makes extra space.

enter image description here

Upvotes: 3

Grasper
Grasper

Reputation: 1313

remove height from #header-bg. You set 590px for the height.

https://jsfiddle.net/owmbw4x6/

Upvotes: 1

Related Questions