为什么我的左侧栏出来了后,底部会不见了?
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | <!DOCTYPE html> < html > < head > < meta charset = "UTF-8" > < title >slidebar</ title > < meta name = 'viewport' content = 'width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no' > < style > *{ margin:0; padding:0; } body{ transition: all 200ms ease-in-out; } body.active{ transform: translate(150px,0); transition: all 200ms ease-in-out; } .header{ width: 100%; height: 45px; position: fixed; top: 0; left: 0; border-bottom: 1px solid red; line-height: 45px; } header div{ width: 50px; text-align: center; line-height: 45px; /*background: red;*/ cursor: pointer; margin-left: 30px; } .header div span{ width: 25px; height: 2px; background:#999; display: inline-block; box-shadow: 0 7px 0 #999 ,0 -7px 0 #999; cursor: pointer; } .slidebar{ width: 150px; height: 100vh; position: absolute; background: #999; top: 0; left: 0; transition: all 200ms ease-in-out; transform: translate(-150px,0); z-index: 100; } .footer{ width: 100%; height: 45px; position: fixed; left: 0; bottom: 0; border-top: 1px solid red; } </ style > < script src = "http://libs.baidu.com/jquery/1.9.0/jquery.js" ></ script > </ head > < body > < header class = "header" > < div id = 'slide-btn' >< span ></ span ></ div > </ header > < section class = "slidebar" ></ section > < footer class = "footer" ></ footer > < script > document.addEventListener('DOMContentLoaded',function(){ (function(){ var slideBtn = document.querySelector('#slide-btn'); var body_ = document.querySelector('body'); slideBtn.onclick = function(){ console.log(1); body_.classList.toggle("active"); } })(); }) </ script > </ body > </ html > |
1
收起
正在回答
2回答
是因为body中的内容都是定位的元素,没有内容撑起来,但是给body添加了transform之后,里面设置定位的元素都会相对于body来定位,相当于是position:relative;,但是没有relative的本质。body没有高度,而footer设置了bottom为0,那么底部就会在顶部显示,如下:
所以需要给html,body设置高度为100%。自己可以举个例子测试一下。
组件化思想开发电商网页 18版
- 参与学习 人
- 提交作业 467 份
- 解答问题 4826 个
本路径带你通过系统学习HTML5、JavaScript、jQuery的进阶知识,不仅如此,还会学习如何利用组件化的思想来开发网页,知识点+案例,使得所学可以更好的得到实践。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧