margin-top有效和margin-bottom无效
来源:4-3 编程练习
慕盖茨6251851
2019-07-04 21:47:32
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> <style> *{margin:0;padding:0} body,html{width:100%;} .box01{ position:relative; width:80%; margin: 0 auto; } .img-01{ display:block; width:80%; height:3000px; margin:0 auto; } .left,.right{position:fixed;} .left img{ width:100px;height:200px; } .left{top:50%;left:3%;margin-top:-100px; }/* 为什么设置margin-bottom:100px无效 */ .right img{ width:100px;height:200px; } .right{top:50%;right:3%;margin-top:-100px; }/* 为什么设置margin-bottom:100px无效 */ </style> </head> <body> <div class="box01"><img src="http://climg.mukewang.com/59c9f7ce0001839219034033.png" class="img-01"/> <div class="right"><img src="http://climg.mukewang.com/5a3383c70001f1b702240364.png"/></div> <div class="left"><img src="http://climg.mukewang.com/5a3383d00001a3dd02240364.png"/></div> </div> </body> </html>
2回答
慕盖茨6251851
提问者
2019-07-05
非常感谢!
好帮手慕星星
2019-07-05
你好,
1、左右两侧的图片没有垂直居中显示,代码中图片设置的高度是200px,但是外层的盒子不是200px哦:
图片是内联元素,有文字特性,默认存在间隙,所以父盒子高度会大一些。可以设置父盒子和图片一样的高度,或者图片设置成block元素。例如:
2、同学说的margin-bottom属性不生效是浏览器的问题,但是这个样式是设置上的:
只不过不进行移动而已,记住用margin-top值实现即可。
3、代码中图片都是缩放之后的,建议按照图片正常大小显示即可。
祝学习愉快!
相似问题