右边的广告用了fixed定位还是没有起到效果,为什么?

来源:4-3 编程练习

weibo_淡写丶甜甜的回溢_0

2018-01-06 19:34:30

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
  <title></title>
  <style type="text/css">
      *{padding:0;margin:0;}
      .div{
            width:100%;
            height:4100px;
            background:url(http://climg.mukewang.com/59c9f7ce0001839219034033.png) center top no-repeat;}
      /*左侧广告*/
      .div1{
            width:500px;
            height:250px;
            top:0;
            left:0;
            bottom:0;
            margin:auto 0;
            position:fixed;}
      /*右侧广告*/
      .div2{
            width:500px;
            height:250px;
            top:0;
            right:0;
            bottom:0;
            margin:auto 0;
            position:fixed;}
  </style>
</head>
<body>
  <div class="div">
    <div class="div1">
      <img src="http://climg.mukewang.com/5a3383d00001a3dd02240364.png"/>
    </div>
    <div class="div2">
      <img src="http://climg.mukewang.com/5a3383c70001f1b702240364.png"/>
    </div>
  </div>
</body>
</html>

写回答

2回答

樱桃小胖子

2018-01-07

默认的img不会继承父元素的宽度和高度,因此,需要对img单独设置宽度和高度

0

weibo_淡写丶甜甜的回溢_0

提问者

2018-01-06

div1和div2里面的宽和高不是应该是来设置图片的大小的吗,为什么对图片起不了作用,却能对图片的上下位置起作用?

0

0 学习 · 36712 问题

查看课程