麻烦老师看下这个代码问题在哪

麻烦老师看下这个代码问题在哪

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{margin: 0;padding: 0;}
.container{width: 80%;height: 500px;margin: auto auto;background-color: #cccc99;position:relative;top: 50px;}
.up{width: 100%;height: 350px;background-color: #9999cc;position: absolute;}
.down{width: 100%;height: 150px;background-color: #ff9999;position: absolute;bottom: 0px;}
.upl{width: 50%;height: 350px;background-color: #9999cc;position: absolute;}
.upr{width: 50%;height: 350px;background-color: #9999cc;position: absolute;right: 0;}
img{display: block;position:absolute;top:0;bottom:0;left:0;right:0;margin: auto auto;}
.dol{width: 33%;height: 150px;background-color: #ff9999;float:left;}
.dom{width: 34%;height: 150px;background-color: #ff9999;float: left;}
.dor{width: 33%;height: 150px;background-color: #ff9999;float: left;}
</style>
</head>
<body>
<div class="container">
<div class="up">
<div class="upl"><img src="http://img1.sycdn.imooc.com/climg//58c0f808000129a303600215.jpg"></div>
<div class="upr"><img src="http://img1.sycdn.imooc.com/climg//58c0f819000198a703600214.jpg"></div>
</div>
<div class="down">
<div class="dol"><img src="http://img1.sycdn.imooc.com/climg//58c0f81d0001fe4402000060.jpg"></div>
<div class="dom"><img src="http://img1.sycdn.imooc.com/climg//58c0f8780001c74602000060.jpg"></div>
<div class="dor"><img src="http://img1.sycdn.imooc.com/climg//58c0f8220001dfce02000060.jpg"></div>
</div>
</div>
</body>
</html>

img用统一居中属性,为什么.up里面的图片能正常居中,.down里面的就不行呢?是因为我用了float的原因吗?

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
小丸子爱吃菜 2018-01-12 17:58:53

因为里面的图片你设置了相同的定位,所以它们重叠在一起了,不需要给图片设置定位,通过margin值去调整就可以了。


小丸子爱吃菜 2018-01-12 16:39:37

测试你的代码,down下面的图片是居中的呀?

你说的不行是怎么设置了不行?请详细说明一下。

祝学习愉快!

  • 提问者 秦鲸卿 #1
    我没说清楚哈,是.down下面有三个div:dol,dom,dor,在css里面写成三个并排float的,然后分别在三个div里面设置三张图片在各自的div中居中,但是我这边写完之后img三张重叠在一起在.down居中了。。。
    2018-01-12 17:03:49
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师