亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

求助!左邊的DIV設定了固定的寬度,右邊的DIV如何自適應地填滿剩下的屏幕寬度?

求助!左邊的DIV設定了固定的寬度,右邊的DIV如何自適應地填滿剩下的屏幕寬度?

慕神8447489 2021-07-29 07:07:00
左邊的DIV設定了固定的寬度,右邊的DIV如何自適應地填滿剩下的屏幕寬度?自適應是為了滿足不同電腦的分辨率。我已經設定了DIV等高了。<style type="text/css">/*CSS部分*/*{margin:0;padding:0;font-family:"微軟雅黑";} /*去除默認間隔,設定全部字體為微軟雅黑*/body{background-image: url(images/wooden.jpg); background-repeat:no-repeat; background-size:cover; -moz-background-size: cover;} /*網頁背景*/#sidebar{width: 210px; height:auto; background-color: #ebb058;float:left; position: fixed; }#container{width: auto;height: auto;border: 2px solid #400080;margin-left: 210px; float: left; position: absolute;}</style><!--HTML部分--><body><!--div盒子模型 --><div id="sidebar"><!--左邊的DIV--></div><div id="container"><!--右邊的DIV--></div><!--javascript部分--><!--div等高-->document.getElementById("sidebar").style.height = document.getElementById("container").offsetHeight + "px";</script></body>
查看完整描述

2 回答

?
一只萌萌小番薯

TA貢獻1795條經驗 獲得超7個贊

無需js、無需浮動,直接用CSS即可搞定這樣的布局,主要代碼如下:


#sidebar, #container {min-height:400px/* 視具體情況 */}#sidebar {width:210pxbackground-color:#ebb058position:absolutetop:0left:0;}#container {margin-left:210pxborder:2px solid #400080;}


查看完整回答
反對 回復 2021-08-02
?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style type="text/css">

*{margin: 0;}

body{

width: 100%;

height: 100%;

}

.l{

float: left;

width: 131px;

height: 45px;

background-color: #aaa;

}

.r{

height: 45px;

background-color: #0f0;

}

</style>

</head>

<body>

<div>左</div>

<div>右</div>

</body>

</html>



查看完整回答
反對 回復 2021-08-02
  • 2 回答
  • 0 關注
  • 551 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號