1)使用flex布局,父容器設定display:flex,左邊div設定flex:0 0 100px width:100px height:100px;右邊div設定:flex:1 height:100px
<
!doctype html>
"utf-8"
>
<
/title>
.container
.d1.d2
<
/style>
<
/head>
'container'
class
="container"
>
'd1'
class
="d1"
>
<
/div>
'd2'
class
="d2"
>
<
/div>
<
/div>
<
/body>
<
/html>
2)左側寬度固定,右側寬度自適應兩列布局:利用左側元素浮動,或者絕對定位的方式使其脫離常規文件流,讓兩個塊級元素能夠在同一行顯示,右側元素 margin-left 的值等於左側元素寬度,這時右側元素將緊挨著左側元素,由於塊元素的寬度會自動預設充滿剩下的螢幕,所以就實現了右側自適應的效果了
左側:position:absolute; width:100px; height:300px;
右側:margin-left:100px; height:200px;
<
!doctype
>
"en"
>
"utf-8"
>
document<
/title>
"stylesheet" href=
"test.css" type=
"text/css"
>
.one
.two
<
/style>
<
/head>
="one"
>
<
/div>
="two"
>第一種方法<
/div>
<
/body>
<
/html>
3)建立bfc—給左邊元素設定bfc,float:left,width:100px,右邊div設定overflow:auto/hidden(效果同2)
<
!doctype html>
"utf-8"
>
<
/title>
.one
.two
<
/style>
<
/head>
="one"
>
<
/div>
="two"
>第二種方法<
/div>
<
/body>
<
/html>
左右布局 左邊定寬 右邊自適應
要求 不少於三種方法 所有方案 父元素的寬度為單位為 absolute padding left right 小結 父元素設定padding left是給左邊元素預留空間,左邊元素絕對定位到該位置。flex,未來趨勢,推薦 left right 小結 flow屬性為flow grow,flow sh...
CSS布局樣式 左右布局,左邊定寬,右邊自適應
1.display table width 100 和 diplay table cell tabletitle head wrap sidebar content style id wrap class sidebar sidebardiv class content contentdiv div...
css布局之左邊定寬右邊寬度自適應的六種方法
1 方法一 採用浮動布局的方法,左邊浮動,右邊加上margin left的值,同時可以設定最小高度值,當內容超出該值時,會自動以等高的方式增高。如下 left right 效果如下所示 2 方法二 左邊設定左浮動,右邊設定寬度100 來實現。left right 3 方法三 採用左浮動和負邊距的方法...