fixed问题

fixed问题

<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <title></title>
   <style type="text/css">
       /*此处写代码*/
       *{padding: 0;margin: 0;}
       .div{width:1100px; margin: 0 auto}
       .header{height: 100px;width:1100px;background-color: #14191e;position:fixed; z-index: 999;}
       .header_img{position: relative;}
       img{display: block;}
       .header_content a{
           text-decoration: none;
           font-size: 20px;
           color: orange;
           position: relative;
           left: 450px;
           padding: 0 20px;
           top:-60px;
       }
       .footer{
           background-color: #14191e;
           width: 1100px;
           height: 100px;
           text-align: center;
           line-height: 100px;
           /*position: fixed;*/

       }
       .footer a{
           text-decoration: none;
           font-size: 20px;
           color: orange;
           padding: 0 50px;

       }
   </style>
</head>
<body>
<!-- 此处写代码 -->
<div class="div">
   <div class="header">
       <div class="header_img"><img src="http://img1.sycdn.imooc.com/climg//58c0d2d900016ce303000100.png"/></div>
       <div class="header_content">
           <a href="#">课程</a>
           <a href="#">职业路径</a>
           <a href="#">实践</a>
           <a href="#">猿问</a>
           <a href="#">手记</a>
       </div>
   </div>
   <div class="container">
       <div class="pic1">
           <img src="http://img1.sycdn.imooc.com/climg//58c0eda50001e12416000480.jpg" width="100%"/>
       </div>
       <div class="pic1">
           <img src="http://img1.sycdn.imooc.com/climg//58c0edb80001c9f216000480.jpg" width="100%"/>
       </div>
       <div class="pic1">
           <img src="http://img1.sycdn.imooc.com/climg//58c0edc9000100d516000480.jpg" width="100%"/>
       </div>
   </div>
   <div class="footer">
           <a href="#">联系我们</a>
           <a href="#">联系我们</a>
           <a href="#">联系我们</a>
           <a href="#">联系我们</a>
           <a href="#">联系我们</a>
   </div>
</div>
</body>
</html>


按照2-4的基础来写width应为1100px,不是100%。我的问题是为啥给foot添加position:fixed,该层就不显示出来了,还是我没搞懂定位的原理


正在回答

登陆购买课程后可参与讨论,去登陆

2回答

同学你好,

1、顶部导航项没有实现垂直居中显示,代码中定位复杂了,左右两侧浮动就可以,行高实现垂直居中,如下:

http://img1.sycdn.imooc.com//climg/5dc24029096bbe1e00000000.jpg

2、不能只给元素添加固定定位哦,还需要设置方位属性 ,将元素固定在哪个位置,如下:

http://img1.sycdn.imooc.com//climg/5dc23f3309bfd6e704280231.jpg

http://img1.sycdn.imooc.com//climg/5dc23e9409eb8bc904080269.jpg

3、container中需要设置上下间距,可以不用相对定位,用margin上下间距就可以,如下:

http://img1.sycdn.imooc.com//climg/5dc23f1e09dc218e03140154.jpg

4、需要将1100px修改成宽度为100%哦。

自己再测试下,祝学习愉快!

欢迎采纳~

  • qq_慕九州2374973 提问者 #1
    中间复杂定位值为设置a标签的位置,因为我按照width:1100px来设置整体效果。fixed的定位搞懂了,是没有仔细看听课的原因。
    2019-11-06 12:41:55
提问者 qq_慕九州2374973 2019-11-06 11:07:37

css样式里面还应加个

.container{position: relative;top:100px;}


footer的fixed问题还是没弄明白

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师