这里item没有设置float,为什么会发生高度塌陷?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | <!DOCTYPE html> < html > < head > < meta charset = "UTF-8" > < title >Document</ title > < style type = "text/css" > body{ margin:0; padding:0; } .box{ position: relative; width:100px; height: 100px; background-color: #ccc; margin:20px; } .item{ position:relative; width: 50px; height: 50px; background-color: red; margin:20px; } </ style > </ head > < body > < div class = "box" id = "demo" > < div class = "item" ></ div > </ div > < script src = "https://cdn.bootcss.com/jquery/3.2.1/jquery.js" ></ script > < script type = "text/javascript" > $(function(){ var demo = $('#demo'); var element = $('.item'); console.log(element.offset()); console.log(element.position()); }) </ script > </ body > </ html > |
62
收起
正在回答 回答被采纳积分+1
1回答
前端小白入门系列课程
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36712 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧