[英]How to shift div over div?
我正在嘗試做這個例子(看圖片),當我需要將綠色 div 向左移動 10px,向左移動 10px,藍色 div,向左移動 20px,向低移動 20px。 但是當我試圖將它添加到 CSS 時(例如左 10px),這不起作用,因為其他“左”屬性被覆蓋了。 我怎樣才能解決這個問題?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#container {
height: 400px;
position: relative;
}
#leftdiv {
background-color: red;
border: 1px solid black;
position: absolute;
margin-right: 0px;
left: 0px;
top: 0px;
bottom: 0px;
right: 80%;
}
#middiv {
background-color: green;
position: absolute;
border: 1px solid black;
left: 20%;
top: 10px;
bottom: 0px;
right: 30%;
}
#rightdiv {
background-color: blue;
position: absolute;
border: 1px solid black;
left: 70%;
top: 20px;
bottom: 0px;
right: 0px;
}
table,
th,
td {
border: 1px solid white;
text-align: center;
}
table.center {
left:10%;
right:10%;
top:10%;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div id="container">
<div id="leftdiv">
</div>
<div id="middiv">
<table class="center">
<tr>
<td><img src="images/dog.jpg" alt="Italian Trulli">
</td>
<td><img src="images/cat.jpg" alt="Italian Trulli">
</td>
</tr>
<tr>
<td><p>call *066</p></td>
<td><p>call *077</p></td>
</tr>
</table>
</div>
<div id="rightdiv">
</div>
</div>
</body>
</html>
您可以使用z-index
和overflow
,尤其是對於綠色和紅色,而您對紅色 div 什么都不做,看看這個:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#container {
height: 400px;
position: relative;
}
#leftdiv {
background-color: red;
border: 1px solid black;
position: absolute;
margin-right: 0px;
left: 0px;
top: 0px;
bottom: 0px;
right: 80%;
z-index: 0;
}
#middiv {
background-color: green;
position: absolute;
border: 1px solid black;
left: 18%;
top: 10%;
bottom: -10%;
right: 30%;
z-index: 1;
overflow: clip;
}
#rightdiv {
background-color: blue;
position: absolute;
border: 1px solid black;
left: 67%;
top: 20%;
bottom: -20%;
right: 0px;
z-index: 2;
}
table,
th,
td {
border: 1px solid white;
text-align: center;
}
table.center {
left:10%;
right:10%;
top:10%;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div id="container">
<div id="leftdiv">
</div>
<div id="middiv">
<table class="center">
<tr>
<td><img src="img/img1.PNG" alt="Italian Trulli">
</td>
<td><img src="img/img1.PNG" alt="Italian Trulli">
</td>
</tr>
<tr>
<td><p>call *066</p></td>
<td><p>call *077</p></td>
</tr>
</table>
</div>
<div id="rightdiv">
</div>
</div>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.