html– 给子div一个相对于父div的边距[复制]

html– 给子div一个相对于父div的边距[复制],第1张

概述参见英文答案 > Why does this CSS margin-top style not work?                                    11个这是我的HTML:<div class='parentDiv'> <div class='childDiv'></div> &

参见英文答案 > Why does this CSS margin-top style not work?                                    11个
这是我的HTML:

这是我的CSS:

.parentdiv {    margin-top: 200px;    wIDth: 700px;    height: 800px;    background-color: red;}.childdiv {    background-color: green;    wIDth: 50px;    height: 50px;    margin-top: 22px;}

小提琴:http://jsfiddle.net/1whywvpa/

为什么childdiv没有获得22px的保证金?如果像素大于已经给予parentdiv的200px,则它仅获得上边距.有什么方法可以让childdiv获得相对于parentdiv的父div为22px而不做某种类型的’给父div一个1px填充’Hack?

最佳答案也许这可以帮助:CSS Margins Overlap Problem

向两个元素添加position属性.父母是亲戚,孩子是绝对的……

.parentdiv {    position: relative;    margin-top: 200px;    wIDth: 700px;    height: 800px;    background-color: red;}.childdiv {    position: absolute;    background-color: green;    wIDth: 50px;    height: 50px;    margin-top: 22px;}

这是你的小提琴:http://jsfiddle.net/algorhythm/1whywvpa/5/ 总结

以上是内存溢出为你收集整理的html – 给子div一个相对于父div的边距[复制]全部内容,希望文章能够帮你解决html – 给子div一个相对于父div的边距[复制]所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1121998.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)