为什么垂直居中后我的div顶部会有额外的间距?

时间:2015-09-23 07:01:01

标签: html css

我一直在使用垂直间距技巧来处理所有div中的文本,当它使垂直间距从0%到90%完美居中时,它会在顶端留下更多空间然后底部。它是在我使用它的每个div上进行的。我已经尝试将填充/边距设置为0但没有任何反应。不确定具体是由什么造成的。这很刺激。有人有想法吗?

实例 -

https://jay-portfolio.herokuapp.com/

问题图片 -

http://i988.photobucket.com/albums/af6/jtbitt/spacing-incorrect_zps0hjolnyv.png

HTML -

<section id="about" ng-controller="aboutController">    
  <div class="container-fluid">

    <div class="row about-row">

      <div class="about-left col-xs-12 col-md-6">
      </div>

      <div class="about-right col-xs-12 col-md-6">
        <div class="about-content">
          <div class="about-content-title">
            <h1><strong>I'M JAY.</strong></h1>
          </div>

          <div class="about-content-info">
            <p ng-if="about.firstParagraph">{{ about.paragraphOne }}</p>
            <p ng-if="!about.firstParagraph">{{ about.paragraphTwo }}</p>
          </div>

          <div class="about-button">
            <button ng-if="about.firstParagraph" class="label label-success" ng-click="about.switchParagraph()">MORE =></button>
            <button ng-if="!about.firstParagraph" class="label label-success"><a href="##skills">VIEW SKILLS</a></button>
          </div>

          <div class="about-personal-info">
            <h4>Email: jaybittner@gmail.com</h4>
          </div>

          <div class="about-icon">
            <a href="{{ profile.url }}" ng-repeat="profile in about.profiles"><img ng-src="{{ profile.icon }}" /></a>
          </div>
        </div>

      </div>

    </div>

  </div>
</section>

CSS -

#about {
  height: 100%; 
  width: 100%;
  background: rgba(0,97,65,1);
  background: -moz-linear-gradient(left, rgba(0,97,65,1) 0%, rgba(54,135,95,1) 7%, rgba(36,123,85,1) 22%, rgba(0,97,65,1) 53%, rgba(34,121,84,1) 76%, rgba(54,135,95,1) 90%, rgba(54,135,95,1) 100%);
  background: -webkit-gradient(left top, right top, color-stop(0%, rgba(0,97,65,1)), color-stop(7%, rgba(54,135,95,1)), color-stop(22%, rgba(36,123,85,1)), color-stop(53%, rgba(0,97,65,1)), color-stop(76%, rgba(34,121,84,1)), color-stop(90%, rgba(54,135,95,1)), color-stop(100%, rgba(54,135,95,1)));
  background: -webkit-linear-gradient(left, rgba(0,97,65,1) 0%, rgba(54,135,95,1) 7%, rgba(36,123,85,1) 22%, rgba(0,97,65,1) 53%, rgba(34,121,84,1) 76%, rgba(54,135,95,1) 90%, rgba(54,135,95,1) 100%);
  background: -o-linear-gradient(left, rgba(0,97,65,1) 0%, rgba(54,135,95,1) 7%, rgba(36,123,85,1) 22%, rgba(0,97,65,1) 53%, rgba(34,121,84,1) 76%, rgba(54,135,95,1) 90%, rgba(54,135,95,1) 100%);
  background: -ms-linear-gradient(left, rgba(0,97,65,1) 0%, rgba(54,135,95,1) 7%, rgba(36,123,85,1) 22%, rgba(0,97,65,1) 53%, rgba(34,121,84,1) 76%, rgba(54,135,95,1) 90%, rgba(54,135,95,1) 100%);
  background: linear-gradient(to right, rgba(0,97,65,1) 0%, rgba(54,135,95,1) 7%, rgba(36,123,85,1) 22%, rgba(0,97,65,1) 53%, rgba(34,121,84,1) 76%, rgba(54,135,95,1) 90%, rgba(54,135,95,1) 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#006141', endColorstr='#36875f', GradientType=1 );
  background-repeat: no-repeat;
  color: #101010;
  border-bottom: 3px solid black;
}

#about .container-fluid, #about .row {
  height: 100%;
}

.about-left {
  height: 100%;
  background-image: url('../../images/jay-ocean.jpg'); 
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  border-right: 3px solid #101010;
}

.about-right {
  height: 100%;
  width: 50%;
  text-align: center;
  position: relative;
}

.about-content {
  width: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin-left: auto;
  margin-right: auto;
}

.about-content-title h1{
  font-size: 3.1vw;
  margin-bottom: 0.6vh;
}

.about-content-info p {
  font-size: 1vw;
  word-spacing: 0.3vw;
  margin-bottom: 0.7vh;
}

.about-button button {
  margin-bottom: -0.1vh;
}

.about-personal-info h4 {
  margin-bottom: 0.7vh;
}

.about-button button {
  color: gray;
  border: 1px solid #101010;
  background-color: #101010;
  font-size: 0.7vw;
}

.about-button a {
  color: gray;
}

.about-personal-info h4 {
  font-size: 1vw;
  word-spacing: 0.3vw;
}

.about-icon img {
  height: 3.5vh;
  width: 1.75vw;
  border-radius: 10px;
  border: 1px solid #101010;
  margin: 3px;
}

@media only screen and (max-width: 992px) {
  .about-left {
    height: 50%;
    border-bottom: 3px solid black;
  }

  .about-right {
    height: 50%;
    width: 100%;
  }

  .about-content {
    width: 70%;
  }

  .about-content-title h1 {
    font-size: 5vw;
  }

  .about-content-info p {
    font-size: 2.5vw;
  }

  .about-button button {
    font-size: 2.5vw;
  }

  .about-personal-info h4 {
    font-size: 2.5vw;
  }

  .about-icon img {
    height: 20px;
    width: 20px;
  }
}

3 个答案:

答案 0 :(得分:0)

尝试将*{margin:0px; padding:0px;}添加到样式表中,然后从那里编辑div标签。祝你好运。

答案 1 :(得分:0)

你可以在另一个div中使用css技巧作为垂直中心div:

&#13;
&#13;
#outerdiv {
   width: 700px;
   margin-left: auto;
   margin-right: auto;
   height: 400px;
   position: relative;
   background: #eee;
   text-align: center;
}
#innerdiv{
   width: 240px;
   height:100px;
   position: absolute;
   top: 50%;
   left: 50%;
   margin-left: -120px;/* half of #innerdiv width*/
   margin-top: -50px;/* half of #innerdiv height*/
  background: #ccc;
}
&#13;
<div id="outerdiv">
  <div id="innerdiv">Centered div</div>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

答案结果是我需要添加&#39; margin-top:0&#39;到.about-content-title h1。在h1上方有一个额外的空间,导致内容div在其顶部有额外的空白区域。 div居中但内部空白。这解决了它。

.about-content-title h1 {
  font-size: 3.1vw;
  margin-bottom: 0.6vh;
  margin-top: 0;
}