星空网 > 软件开发 > 网页设计

为什么margin的auto属性值失效了

为什么margin的auto属性失效了:
建议:尽可能的手写代码,可以有效的提高学习效率和深度。
通常情况下,可以使用margin:0px auto将对象设置为水平居中对齐。这是因为auto属性值能够使浏览器自动为对象判断外边距大小,但是在下面的情况下却失效了。代码如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">.parent{ width:300px; height:200px; border:1px solid red;}.children{ width:200px; height:100px; background-color:green; position:absolute; margin:0px auto;}</style></head><body><div class="parent"> <div class="children"></div></div></body></html>

因为子对象是绝对定位,所以margin:0px auto无法将它居中对齐。解决方法可以参阅如何实现div水平垂直和居中效果。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4707

更多内容可以参阅:http://www.softwhy.com/divcss/




原标题:为什么margin的auto属性值失效了

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

独立站老司机:https://www.goluckyvip.com/tag/10246.html
电商国际小包:https://www.goluckyvip.com/tag/102460.html
便宜的国际小包:https://www.goluckyvip.com/tag/102461.html
澳大利亚国际小包:https://www.goluckyvip.com/tag/102462.html
国际邮政小包:https://www.goluckyvip.com/tag/102463.html
邮政小包国际:https://www.goluckyvip.com/tag/102465.html
活动回顾 | 千亚麦佳携手MoonSees呈现精彩亚马逊运营管理课程:https://www.kjdsnews.com/a/1836386.html
生日景点免费 上海景点生日免费景点:https://www.vstour.cn/a/363173.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流