【问题标题】:How to remove unwanted space between these two DIVs?如何删除这两个 DIV 之间不需要的空间?
【发布时间】:2016-02-29 12:14:51
【问题描述】:

我有两个宽度为 100% 的 div 我有问题我在 div 之间获得空间我正在使用引导程序并尝试了不同的 CSS 属性但没有任何反应 我想要它们之间的 0 边距无法弄清楚它是如何完成的

我的代码:

          .sec-one {
            height: 200px;
            width: 100%;
            background-color: pink;
          }
          .sec-two {
            height: 200px;
            width: 100%;
            background-color: red;
            text-align: center;
          }
          #header h1 a {
            display: inline-block;
            text-decoration: none;
            font-size: 1.8em;
            color: white;
            margin-top: 90px;
          }
<html>

<head>
  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>

<body>

  <div class="sec-one">

  </div>

  <div class="sec-two">

    <div id="header">
      <h1><strong><a href="">A Heading</a></strong></h1>
    </div>

  </div>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>

</html>

【问题讨论】:

标签: html css twitter-bootstrap


【解决方案1】:
h1 {font-size:0px} //it will also work in case display:inline-block of div's

【讨论】:

  • 感谢您的回答先生
【解决方案2】:

试试这个

.sec-one {
    height: 200px;
    width: 100%;
    background-color:pink;
  }

  .sec-two{
    height: 200px;
    width: 100%;
    background-color:red;
    text-align: center;
  }

  #header h1 a {
    display: inline-block;
    text-decoration: none;
    font-size: 1.8em;
    color: white;
    margin-top: 90px;
  }
h1
{
    margin:0;
  }
 <div class="sec-one">

  </div>

  <div class="sec-two">

    <div id="header">
      <h1><strong><a href="">A Heading</a></strong></h1>
    </div>

  </div>

【讨论】:

    【解决方案3】:

    只需在样式表中插入h1 {margin:0px} 即可。

    在我的示例中,该属性位于顶部。

    Example

    【讨论】:

    • 非常感谢@Antonio Smoljan
    猜你喜欢
    • 2013-07-20
    • 2014-09-27
    • 1970-01-01
    • 2014-09-15
    • 2017-10-21
    • 2012-09-25
    • 2011-06-28
    • 2021-08-03
    • 2011-01-17
    相关资源
    最近更新 更多