如何删除div元素下面的空格

时间:2016-12-01 17:54:35

标签: javascript html css

我有一些div,其中有一个小差距或空白。 我尝试过更改上下边距,但是没有用。我认为它与图像有关,但我还没有找到解决方案。

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;

}

4 个答案:

答案 0 :(得分:3)

html中有一个`字符,这会产生额外的空间。

enter image description here

答案 1 :(得分:2)

你有一个`在这些div之间

用这个替换这些div

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

        </div>
    </div>

   <div class = "details-wrapper">

    </div>

答案 2 :(得分:1)

height删除#header-bg。您为高度设置了590px

https://jsfiddle.net/owmbw4x6/

答案 3 :(得分:0)

Poistioning和display:flex不能很好地结合在一起。

如果你想在flexed容器上使用position:absolute,在#header-bg上应用position:absolute,那是因为你有空白

检查此代码段

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>

希望有所帮助

相关问题