簡體   English   中英

流體div寬度為100%

[英]Fluid div with 100% width

我有一個類似下面的帶有邊欄和主容器的html結構。 我想要的是具有一個固定寬度的側邊欄(稍后通過媒體查詢對其進行更改)和一個流暢的主容器。 這意味着如果我減小瀏覽器的寬度,則主容器的寬度應減小,而邊欄不會減小。

我已經嘗試過#container的100%寬度,邊欄的15%寬度和主容器的85%寬度,但這(當然)也減小了邊欄的寬度。 僅使用主容器的100%寬度和側邊欄容器的固定寬度似乎不起作用。

解決此問題的最佳方法是什么?

HTML:

<div id="container">
    <div id="sidebar">
        //content
    </div>
    <div id="main">
        //content
    </div>
</div>

 ________________________
|     |                  |
|     |                  |
|     |                  |
|     |                  |
|     |                  |
|     |                  |
|     |                  |
|     |                  |
--------------------------

使用以下CSS

.container{display:block; padding:0 0 0 200px;}
.sidebar{display:block; float:left; width:200px; margin:0 0 0 -200px;}
.main{display:block; width:100%}

小提琴http : //jsfiddle.net/3ApFZ/

CSS

#sidebar{
    width:150px;
    position: absolute;
    background:blue;
    height:100%;

}
#main{
    width:100%;
    padding-left: 150px;
    background:red;
    height:100%;
}

幾天前,我為某人提供了類似的幫助。 如果您使用以下演示怎么辦

基本上將左側設置為固定寬度,右側設置為可調整大小

.left {width:100%; height:20px; background-color:red; float:left; margin-left:-320px; display:inline}
.right {width:320px; height:20px; background-color:blue; float:right; display:inline}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM