我在.header里设置完固定定位后,.nav发生了异位是为什么?
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> * { margin: 0; padding: 0; } ul { list-style: none; } .container { color: #ccc; text-align: center; font-size: 30px; width: 80%; margin: 0 auto; position: relative; } .header { background: black; /* overflow: hidden; */ width: 100%; /* max-width: 1100px; */ height: 100px; position: fixed; /* top: 0; left: 0; */ } .logo img { float: left; } .nav { overflow: hidden; } .nav ul { float: right; } .nav li { float: left; height: 100px; line-height: 100px; margin-right: 30px; } .booder img { width: 100%; display: block; } .footer { background: black; overflow: hidden; /*text-align: center;*/ } .footer li{ float: left; /*width: 100%;*/ height: 100px; line-height: 100px; margin: 0 auto; } </style> </head> <body> <div class="container"> <div class="header"> <div class="logo"> <img src="http://img1.sycdn.imooc.com/climg//58c0d2d900016ce303000100.png" alt=""> </div> <div class="nav"> <ul> <li>课程</li> <li>职业路径</li> <li>实战</li> <li>猿问</li> <li>手记</li> </ul> </div> </div> <div class="booder"> <img src="http://img1.sycdn.imooc.com/climg//58c0eda50001e12416000480.jpg" alt=""> <img src="http://img1.sycdn.imooc.com/climg//58c0edb80001c9f216000480.jpg" alt=""> <img src="http://img1.sycdn.imooc.com/climg//58c0edc9000100d516000480.jpg" alt=""> </div> <div class="footer"> <ul> <li>网站首页</li> <li>企业合作</li> <li>人才招聘</li> <li>联系我们</li> <li>常见问题</li> <li>友情链接</li> </ul> </div> </div> </body> </html>
0
收起
正在回答 回答被采纳积分+1
3回答
Jack崔
2019-09-08 21:34:43
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> * { margin: 0; padding: 0; } ul { list-style: none; } .container { color: #ccc; text-align: center; font-size: 30px; width: 80%; margin: 0 auto; position: relative; } .header { background: black; /* width: 80%; */ /* 这个部分100%异位,而80%后就能恢复 */ width: 100%; height: 100px; position: fixed; } .logo img { float: left; } .nav { overflow: hidden; } .nav ul { float: right; } .nav li { float: left; height: 100px; line-height: 100px; margin: 0 15px; } .booder img { width: 100%; display: block; } </style> </head> <body> <div class="container"> <div class="header"> <div class="logo"> <img src="http://img1.sycdn.imooc.com/climg//58c0d2d900016ce303000100.png" alt=""> </div> <div class="nav"> <ul> <li>课程</li> <li>职业路径</li> <li>实战</li> <li>猿问</li> <li>手记</li> </ul> </div> </div> <div class="booder"> <img src="http://img1.sycdn.imooc.com/climg//58c0eda50001e12416000480.jpg" alt=""> <img src="http://img1.sycdn.imooc.com/climg//58c0edb80001c9f216000480.jpg" alt=""> <img src="http://img1.sycdn.imooc.com/climg//58c0edc9000100d516000480.jpg" alt=""> </div> </div> </body> </html>
前端小白入门系列课程
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36713 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星