![](/img/trans.png)
[英]Why is a scrollbar added to the browser window when body's width is 100%?
[英]Why body width don't set to 100% on browser window resize?
例如,讓我們看一下Twitter引導程序的主頁http://twitter.github.com/bootstrap/index.html
如果我將瀏覽器窗口的大小調整為400px,我會在右邊看到奇怪的空間(看圖片)。
另一個示例是StackOverflow。 在瀏覽器中,調整灰色背景標題行的大小不要調整到所有屏幕的大小(請參見下文)。
為什么正文不調整為瀏覽器窗口的100%? 我的網站上有類似的問題
當您使瀏覽器窗口小於內容的最小寬度並水平滾動時,就會發生此問題。 設置為100%寬度的元素為寬度的100%,直到您水平滾動直到看起來被切除為止。
解決方案是在這些元素上設置min-width
,以使它們至少與內容一樣寬。
這是一個例子:
的HTML
<div id="header1">Broken header</div>
<div id="header2">Fixed header</div>
<div id="content">
content goes here.
</div>
的CSS
#header1 {
background-color:#ccc;
border: 2px solid #00F;
}
#header2 {
background-color:#ddd;
min-width: 600px;
border: 2px solid #0F0;
}
#content {
width: 600px;
border: 2px solid #F00;
}
類似問題:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.