2016-12-25 74 views
1

因此,我嘗試了所有我能想到的方法來擺脫頁面上所有內容的白邊。無法擺脫div上的白色邊緣

我已經把: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>

+1

你能更具體? 「圍繞一切」的含義非常模糊。你確定你正在考慮利潤率,而不是你在其他元素上應用的填充項嗎?具體DIV – toniedzwiedz

+1

復位填充你想 'div.col-12 { 填充:0 }'https://jsfiddle.net/kfexozkh/3/ –

回答

3

如果檢查的元素,你可以發現有多餘的空格是因爲以下的風格,適用padding包含col-的值爲class的所有元素。

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

覆蓋風格,你可以擺脫不必要的空間。請注意,這將爲其值爲col-的所有類別的padding設置爲0。

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

或者你只能覆蓋.col-12padding將適用0填充到.col-12而含col-其他類仍然會得到15像素的填充。

.col-12 { 
    padding: 0; 
} 
+0

就是這樣!小「col-」位 – Daniel

1

你包裹在一個.col-12類的許多元素。所有.col-元素都設置在您的CSS中,以包含邊緣周圍的padding15px。下面是來自於Chrome開發者工具檢查網頁的截圖,你可以看到的元素被突出顯示:

enter image description here

+0

謝謝!這正是錯誤的地方。 – Daniel

0

您需要在col-12元素上設置填充爲0。

更改以下在你的CSS

.col-12 { 
    width: 100%; 
} 

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

fiddle example here

+0

這確實是它!不能相信我錯過了那個。 -_- – Daniel

+0

我一直在使用這類東西的一個技巧是在問題區域/空白處單擊右鍵(使用Chrome瀏覽器)並選擇INSPECT ...它將顯示顯示元素屬性的Chrome開發工具並且您可以解決特定問題。 – tamak

相關問題