html - 将 margin-top 设置为 h1 后,如何删除 div 上方的空白区域?

标签 html css

嘿,我正在为类制作我的作品集,我试图删除 div 上方的空白,我有我的 h1。我添加了一个 h1,但我不希望它一直在 div 之上,所以当我在其上添加一个 margin-top 在 div 上方创建空白。我该如何删除它?

<!DOCTYPE html>
<html lang = "en-us">

    <head>

      <title>Carlos Elizondo</title>    
      <link rel = "stylesheet" type = "text/css" href = "main.css">

      <link rel = "stylesheet" type = "text/css" href = "http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">

      <link href="https://fonts.googleapis.com/css?family=Raleway:300,400,500" rel="stylesheet">

    </head>

    <body>

      <header>
          <div class="header-bg"></div>

          <div class="header-dark">

            <div class="wrapper">

              <div class = "heading">Hi. My Name is</div>

              <div class = "box-name">Carlos Elizondo</div>

              <div class = "heading">I'm a future web developer and current student </div>

              <ul>

                <li>
                    <a href="#" class="ion-social-facebook"></a>
                </li>

                <li>
                  <a href="#" class="ion-social-twitter"></a>
                </li>

                <li>
                  <a href="#" class="ion-social-linkedin"></a>
                </li>

              </ul>

            </div>

          </div>

          <nav class = "clearfix">

              <a href = "index.html" class = "logo" CE>CE</a>

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

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

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

              <a href = "#" class = "nav-links ">About Me</a>

          </nav>

        </header>

        <div class = "about-container">

            <h1 class = "title">About Me</h1>  //this is the h1 i am trying to edit 




        </div>





    </body>

</html>


----------------------------------------CSS-------------------------------------

*{
    margin: 0;
    padding: 0;
}


body{
    margin: 0;
    font-family: sans-serif;
    padding: 0;
}


header{
    position: relative;
    display: block;
    width: 100%;
    height: 100vh;
    bottom: 0;
    margin: 0;


}

.header-bg{

    position: absolute;
    width: 100%;
    height: 100%;
    background-image: url(macbook2.jpg);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;

}

.header-dark{

    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    display: flex;
    flex-flow: row wrap;
    justify-content: center;
    align-items: center;

}

.wrapper{

    width: 850px;
    height: auto;
    margin-top: -50px;
}


h2{
    color: white;
    text-align: center;
    letter-spacing: 0.1em;

}

h4{
    color: white;
    text-align: center;
    letter-spacing: 0.1em;
}

ul{   

    list-style-type: none;
    text-align: center;
    padding: 0;

}

ul li{

    display: inline-block;
    padding: 0 13px;


}


.ion-social-facebook{
   color: white;
   font-size: 28px;

}

.ion-social-facebook:visited{
    color: white;
}

.ion-social-facebook:visited{
    color: white;
}

.ion-social-twitter{

    color: white;
    font-size: 28px;
}

.ion-social-linkedin{
    color: white;
    font-size: 28px;
}


nav{
    position: fixed;
    width: 100%;
    height: auto;

}

.nav-links{
    float: right;
    color: white;
    margin: 20px 10px;
    text-decoration: none;
}

.nav-links.last{
    margin-right: 30px;
}

.logo:link{

    margin-left: 30px;
    margin-top: 20px;
    margin-bottom: 20px;
    float: left;

}

.heading{
    color: white;
    text-align: center;
    font-size: 30px;

}

.box-name{
    color: white;
    text-align: center;
    border: 4px solid white;
    padding: 9px;
    font-size: 75px;
    margin-bottom: 10px;
    letter-spacing: 2px;
    margin-top: 10px;
    text-transform: uppercase;
    font-family: 'Raleway', sans-serif;
    font-weight: 500;
}

.about-container{
    position: relative;
    width: 100%;
    height: 600px;
    margin-bottom: 40px;
    background-color: #d8d8d8;
    margin-top: 0;


}

.title{


   color: #777777;
   text-align: center;
   margin: 0px;
   margin-top: 20px;



}

最佳答案

您可以简单地从 margin-top: 20px; 切换到 padding-top: 20px;

编辑

margin 和 padding 是不同的,因为 margin 将元素与另一个元素分开,而 padding 只是添加一些“透明”空间来增加元素的大小,但它使它与其他元素保持接近,如果您想了解更多信息,请阅读:

https://css-tricks.com/almanac/properties/p/padding/

https://css-tricks.com/almanac/properties/m/margin/

关于html - 将 margin-top 设置为 h1 后,如何删除 div 上方的空白区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40324623/

相关文章:

javascript - 简单的if else onclick then呢?

javascript - Chrome 似乎不允许 window.print()

javascript - 使用Jquery在右键单击时停止垂直滚动

jquery - 无法解释的内联 CSS 添加到 div

javascript - 转到页面顶部,当我们单击标签链接时

javascript - 网页重置并停止应用 CSS

html - 我怎样才能得到这两个表单字段来填充它们之间的空间

javascript - 如何计算一个月的工作时间?

javascript - CSS动画帮助。仅以一种方式播放

css - 多行文本元素上的左边框倾斜