[英]2-column CSS one responsive another fixed
我需要兩列,一列響應式,另一列固定為100px width
例如,左列的100px width
為100px width
,右列的寬度為剩余
在這個簡單的代碼中要放多少寬度?
<!DOCTYPE html>
<html>
<head>
<style>
.main{
display: table;
clear: both;
width: 100%;
}
#left{
float: left;
width: 100px;
}
#right{
float: right;
/*width: ;*/
background-color: red;
}
</style>
</head>
<body>
<div class="main">
<div id="left">
left
</div>
<div id="right">
right
</div>
</div>
</body>
</html>
由於您已經在父級上使用display: table
,因此將子級的顯示設置為table-cell
然后像您一樣為第一個table-cell
一個寬度。 第二列將自動采用剩余寬度。
#left{
display: table-cell;
width: 100px;
}
#right{
display: table-cell;
}
您可以使用calc()
計算剩余寬度。 檢查瀏覽器兼容性表: 我可以使用calc() 。
html, body { margin: 0; padding: 0; } .main { width: 100%; } #left { float: left; width: 100px; background: lightblue; } #right { float: left; background-color: tomato; width: calc(100% - 100px); }
<!DOCTYPE html> <html> <head> <style> </style> </head> <body> <div class="main"> <div id="left"> left </div> <div id="right"> right </div> </div> </body> </html>
嘗試這個:
#left {
position: absolute;
left: 0;
width: 100px;
}
#right {
position: absolute;
left: 100px;
width: 100%;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.