[英]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.