您需要使用绝对定位来实现这一点。每个内部 div 的绝对位置将有两个top
, left
, right
, 或bottom
设置为 0。
这是一个例子:
<html>
<head>
<title>CSS Based layouts</title>
<style type="text/css">
#rect {
width: 300px;
height: 300px;
position: relative;
border: 1px solid black;
}
#topleft {
position: absolute;
top: 0;
left: 0;
border: 1px solid black;
}
#bottomleft {
position: absolute;
bottom: 0;
left: 0;
border: 1px solid black;
}
#topright {
position: absolute;
top: 0;
right: 0;
border: 1px solid black;
}
#bottomright {
position: absolute;
bottom: 0;
right: 0;
border: 1px solid black;
}
</style>
</head>
<body>
<h1>CSS Based layouts</h1>
<p></p>
<div id="rect">
<div id="topleft">
Top and Left
</div>
<div id="bottomleft">
Bottom and Left
</div>
<div id="topright">
Top and Right
</div>
<div id="bottomright">
Bottom and Right
</div>
</div>
</body>
</html>