无法摆脱div的白色边缘

时间:2016-12-25 22:47:11

标签: javascript html css margins removing-whitespace

所以,我已经尝试了所有我能想到的东西来摆脱页面上所有内容的白边。

我把margin: 0;放在我能想到的一切上,它仍然没有摆脱它。任何帮助都会很棒!

我为巨大的代码墙道歉。

function myFunction() {
  var x = document.getElementById("myTopnav");
  if (x.className === "topnav") {
    x.className += " responsive";
  } else {
    x.className = "topnav";
  }
}
/* global */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: sans-serif;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: "Tahoma", sans-serif;
  font-size: 16px;
  color: #454545;
  background-color: #fff;
}

div {
  margin: 0;
}


/* end global */


/* custom */

.container {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

.footer {
  padding: 5px 10px;
  background-color: #428cd9;
}


/* end custom */


/* custom responsive */

.row::after {
  content: "";
  clear: both;
  display: block;
}

[class*="col-"] {
  float: left;
  padding: 15px;
}

.col-1 {
  width: 8.33%;
}

.col-2 {
  width: 16.66%;
}

.col-3 {
  width: 25%;
}

.col-4 {
  width: 33.33%;
}

.col-5 {
  width: 41.66%;
}

.col-6 {
  width: 50%;
}

.col-7 {
  width: 58.33%;
}

.col-8 {
  width: 66.66%;
}

.col-9 {
  width: 75%;
}

.col-10 {
  width: 83.33%;
}

.col-11 {
  width: 91.66%;
}

.col-12 {
  width: 100%;
}


/*end custom responsive */


/* navbar */

ul.topnav {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #428cd9;
}

ul.topnav li {
  float: left;
}

ul.topnav li a {
  height: 55px;
  display: inline-block;
  color: #454545;
  padding: 0px 16px;
  line-height: 3.0;
  text-decoration: none;
  text-align: center;
  font-size: 17px;
  transition: 0.3s;
}

ul.topnav li a:hover {
  background-color: #2162a6;
  color: #757575;
}

ul.topnav li.icon {
  display: none;
}


/* end navbar */


/* responsive navbar */

@media screen and (max-width:680px) {
  ul.topnav li:not(: first-child) {
    display: none;
  }
  ul.topnav li.icon {
    float: right;
    display: inline-block;
  }
}

@media screen and (max-width:680px) {
  ul.topnav.responsive {
    position: relative;
  }
  ul.topnav.responsive li.icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  ul.topnav.responsive li {
    float: none;
    display: inline;
  }
  ul.topnav.responsive li a {
    display: block;
    text-align: left;
  }
}


/* end responsive navbar */

@media screen and (max-width:680px) {
  .nomobile {
    display: none;
  }
  .yesmobile {
    width: 100%;
  }
}

.header-img {
  min-height: 300px;
  background-image: url(http://thirdshiftdesigns.net/images/cabheader2.png);
  background-repeat: no-repeat;
  background-size: auto 100%;
  background-position: center top;
  /*padding: 40px; (If don't want to set min-height or some image content is there) */
}

.end-header {
  width: 100%;
  height: 15px;
  background-color: #428cd9;
}
<body>

  <div class="col-12">

    <ul class="topnav" id="myTopnav">
      <li><a href="#">Logo</a></li>
      <li><a href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">Contact</a></li>
      <li class="icon">
        <a href="javascript:void(0);" style="font-size:15px;" onclick="myFunction()">&#9776;</a></li>
    </ul>

    <div class="row">
      <div class="col-12">
        <div class="header-img">
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-12">
        <div class="end-header">
        </div>
      </div>
    </div>

  </div>
  <!-- end header -->
  <!-- footer -->
  <div class="col-12">
  </div>

</body>

3 个答案:

答案 0 :(得分:3)

如果您检查元素,则可以发现不需要的空格是由于以下样式将padding应用于class值包含col-的所有元素。

[class*="col-"] {
  float: left;
  padding: 15px;
}

覆盖样式,你可以摆脱不必要的空间。请注意,对于值为padding的所有类,这会将col-设置为0.

[class*="col-"] {
  padding: 0;
}

或者,您只能覆盖padding的{​​{1}},.col-12将填充0到.col-12,而其他包含col-的类仍会获得15px的填充。

.col-12 {
  padding: 0;
}

答案 1 :(得分:1)

您在.col-课程中包含了许多元素。所有15px元素都在CSS中设置,以便在边缘包含padding {{1}}个{{1}}。以下是检查Chrome开发者工具中页面的屏幕截图,您可以在其中看到突出显示的元素:

Oracle docs

答案 2 :(得分:0)

您需要在col-12元素上将填充设置为0.

更改CSS中的以下内容

.col-12 {
    width: 100%;
}

.col-12 {
    width: 100%;
    padding: 0px;
}

fiddle example here

相关问题