2015-04-13 173 views
0

我明顯使用overflow:hidden浮點數。我在標題部分使用了它,但由於某些原因,它尚未生效,導航列表下方的圖像與nav位於同一行。列表和標題,並由於某種原因減少了寬度。溢出隱藏不生效

我在哪裏出錯了?我檢查並交叉檢查,但我確保我沒有錯過任何html中的標籤,並在header中使用overflow: hidden

/* 
 
*************** 
 
=Header 
 
*************** 
 
*/ 
 
header { 
 
    overflow: hidden; 
 
} 
 
header h1 { 
 
    width: 200px; 
 
    height: 23px; 
 
    float: left; 
 
} 
 
/* 
 
*************** 
 
=Navigation 
 
*************** 
 
*/ 
 
nav { 
 
    float: right; 
 
} 
 
nav li { 
 
    display: inline; 
 
} 
 
/* 
 
*************** 
 
=Banner 
 
*************** 
 
*/ 
 
.banner { 
 
    background: url("../img/TitleImage.jpg") no-repeat; 
 
    /*width:1000px;*/ 
 
    height: 231px; 
 
} 
 
.callout { 
 
    background: black; 
 
    height: 231px; 
 
}
<div class="container_12"> 
 
    <header> 
 
    <h1> Black + White </h1> 
 
    <nav> 
 
     <ul> 
 
     <li><a href="#">Home</a> 
 
     </li> 
 
     <li><a href="#">Our Services</a> 
 
     </li> 
 
     <li><a href="#">How we work</a> 
 
     </li> 
 
     <li><a href="#">Testimonials</a> 
 
     </li> 
 
     <li><a href="#">Work Examples</a> 
 
     </li> 
 
     </ul> 
 
    </nav> 
 
    <div class="banner grid_10"> 
 
     <p>Some slick phrase would go in here to sum up .</p> 
 
    </div> 
 
    <div class="grid_2 callout"></div> 
 
    </header> 
 
    <div class="main"> 
 
    <div class="grid_10"> 
 
     <div class="grid_5"> 
 
     <h1>Services we offer </h1> 
 
     <p>This is sample text to check the formatting and practice html with css. It seems to come easy. I wonder why I never tried it before.</p> 
 
     <p>This is just another paragraph for testing purpose.</p> 
 
     <p> <a href="#" class="button"> Read more </a> 
 
     </p> 
 
     </div> 
 
     <div class="grid_5"> 
 
     <h1>How we work </h1> 
 
     <p>This is sample text to check the formatting and practice html with css. It seems to come easy. I wonder why I never tried it before.</p> 
 
     <p>This is just another paragraphn for testing purpose.</p> 
 
     <p> <a href="#" class="button"> Read more </a> 
 
     </p> 
 
     </div> 
 
    </div> 
 
    <div class="grid_2"> 
 
     <blockquote> 
 
     <p>sample block quote goes here in the website</p> 
 
     </blockquote> 
 
    </div> 
 
    <footer> 
 
     <p> <strong>black+white</strong> themes via <a href="#"> theme forest</a> 
 
     </p> 
 
    </footer> 
 
    </div> 
 
</div>

回答

0

overflow:hidden,在浮動信息交流方面,環繞它的所有元素的浮動兒童和隨後的兄弟姐妹會後元素出現在文檔流overflow:hidden

話雖這麼說,nav.banner出現在相同的元素(header),因此應用上headeroverflow:hidden這裏不會幫助你實現你想要的。

只需設置.banner清除所有花車:

.banner { clear: both; }

+0

謝謝你的明確解釋。這工作:)。 –

0

你有兩個浮動元素:H1和導航。 H1離開,導航是正確的。那麼當然,.callout出現在.banner之後,它不適合你的清算。你需要在包含.banner之前解決這兩個浮點數(h1和/或nav)。