吐槽职人
2016-07-20 22:28
老师,第二节课的后半部分应用的自适应矩形这里不太懂,能否放出相关代码让我们看看
老师不厚道,讲的一知半解的。下面是我理解的,可能跟老师的不一样,但是老师讲的是什么意思,我也实在是不了解。 <html> <head></head> <body> <div style="background: rgb(238, 238, 238); margin: 100px auto 0px; width: 600px; height: 400px; overflow: hidden; position: relative;"> <div style="width: 100%; height: 100%; position: absolute; z-index: 1; background-color: blue;"></div> <div style="background: white; width: 100%; height: 1000px; margin-top: 50%; position: absolute; z-index: 2;"></div> </div> </body> </html> 容器是相对定位的,里面有两个div。第一个是为了显示内容用的,第二个是为了遮住父元素的一部分的,也就是margin-top:50%,父元素宽度的一半。
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>自适应矩形</title>
<script type="text/javascript" src="../../js/jquery-3.0.0.min.js"></script>
<style type="text/css">
.box
{
background-color: olive;
overflow: hidden;
resize: both;
width: 400px;
height:250px;
display: block;
}
.box > div
{
margin-top:50%;
background-color: #eee;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div>
<div></div>
</div>
</body>
</html>我觉得应该是这样

还是没有明白它是怎么自适应的。。。这个自适应矩形难道不是指.box的这个矩形吗?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box{
width: 900px;
height: 200px;
background-color: olive;
overflow: hidden;
position: relative;
}
.tent{
margin: 20%;
background-color: red;
position: absolute;
}
</style>
</head>
<body>
<div>
<div>122333</div>
</div>
</body>
</html>是根据相对定位和绝对定位的 3:00那里重新看下
我的意思是,我自己没有实现例子中的效果

显示效果

你的问题估计老师也没看懂
CSS深入理解之margin
55936 学习 · 68 问题
相似问题