2017-10-05 73 views
1

我有一個ul div(left-nav-bar)。我試圖讓ul跨越整個div,當用戶懸停在它上面,但每個li之前生成空白,我不知道爲什麼。無序列表不包含整個div

enter image description here

我已經試過:

.nav-container ul{ 
    width: 100%; 
} 

允許UL到超出文本,但並沒有解決的空白。

這裏是一個小提琴:https://jsfiddle.net/ytynqhmj/

回答

1

默認情況下ul元素採取padding-left: 60px;只是0像素更新,以解決此問題。檢查下面更新片斷..

html, 
 
body { 
 
    height: 100%; 
 
    background-color: #333; 
 
} 
 

 
body { 
 
    background-color: #333; 
 
    text-align: center; 
 
    text-shadow: 0 .05rem .1rem rgba(0, 0, 0, .5); 
 
    margin: 0; 
 
    font-family: "Helvetica Neue", Arial, sans-serif; 
 
    font-size: 1rem; 
 
    font-weight: 400; 
 
    line-height: 1.5; 
 
    display: block; 
 
} 
 

 

 
/** CONTAINER DIVS **/ 
 

 
.site-wrapper { 
 
    display: table; 
 
    width: 100%; 
 
    height: 100%; 
 
    min-height: 100%; 
 
} 
 

 
.site-wrapper-inner { 
 
    display: table-cell; 
 
    vertical-align: top; 
 
    overflow: auto; 
 
} 
 

 
.logo-holder { 
 
    height: 150px; 
 
    text-align: center; 
 
    border: 1px solid black; 
 
} 
 

 
.logo-holder h3 { 
 
    line-height: 150px; 
 
} 
 

 
.nav-container { 
 
    width: 300px; 
 
    float: left; 
 
    background-color: #fff; 
 
    height: 100%; 
 
} 
 

 
.nav-container a { 
 
    text-align: left; 
 
    padding: 5px; 
 
    color: #333; 
 
} 
 

 
.nav-container ul { 
 
    width: 100%; 
 
    padding: 0px; 
 
} 
 

 
.nav-container ul li { 
 
    list-style-type: none; 
 
    width: 100%; 
 
} 
 

 
.nav-container li:hover { 
 
    background-color: #333; 
 
}
<div class="site-wrapper"> 
 
    <div class="site-wrapper-inner"> 
 
     <div class="nav-container"> 
 
      <div class="logo-holder"> 
 
       <h3>Logo</h3></div> 
 
      <nav class="nav left-nav-bar"> 
 
       <ul> 
 
        <li><a class="nav-link active" href="">Home</a></li> 
 
        <li><a class="nav-link" href="">Blog</a></li> 
 
        <li><a class="nav-link" href="">Store</a></li> 
 
        <li><a class="nav-link" href="">Contact</a></li> 
 
       </ul> 
 
      </nav> 
 
     </div> 
 
    </div> 
 
</div>

1

只是刪除默認的左填充爲ul像這樣:

.nav-container ul{ 
    padding-left:0;<----Added 
    //more code.... 
} 

Demo