Tôi có hai div: s trong một vùng chứa.
Div đầu tiên phải có chiều cao tự động, lấy bất kỳ khoảng trống nào là bắt buộc.
Div thứ hai phải có chiều cao còn lại của vùng chứa.Điền vào div-height còn lại chỉ sử dụng CSS
Tôi muốn làm điều này mà không cần sử dụng Javascript.
Không có giải pháp chỉ CSS nào? Có thể bằng cách sử dụng display:table
/display:table-cell
hoặc display:flex
? Ví dụ
không làm việc
<!DOCTYPE html>
<html>
<head>
<title>Stretch</title>
<style type="text/css">
html { height: 100%; }
body {
padding: 0 0;
margin: 0 0;
height: 100%;
background: grey;
}
#container { background: pink; }
#autoHeight { background: blue; }
#remainingHeight { background: green; }
</style>
</head>
<body>
<div id="container">
<div id="autoHeight">Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat.</div>
<div id="remainingHeight">This div should fill out the rest, making the display
mainly green. And no, I don't mean to just have green background. It will
contain other things.</div>
</div>
</body>
</html>
thể trùng lặp của [Thực hiện một div lấp đầy không gian màn hình còn lại] (http://stackoverflow.com/questions/90178/make-a-div-fill-the-remaining-screen -không gian) –