我这样写可以吗?

来源:5-2 编程练习

慕先生3246696

2019-07-26 12:04:56

<html>
<head>
    <style type="text/css"></style>
       </head>
       <style type="text/css">
            div{
                width:300px;

            height:300px;

            position:absolute;
            }
            .div1{
                top:20px;
                left:40px;
                z-index:1;
            }
            .div2{
                top:30px;
                left:60px;
                z-index:2;
                
            }
            
        </style>
<body>
<div id=div1>
    <img src="img/2.jpg" />
</div>
<div id=div2>
<img src="img/1.jpg" />
</div>
</body>
</html>

写回答

1回答

好帮手慕小尤

2019-07-26

同学你好,因在div上使用的是id所以需要使用id选择器的(#),修改代码:

div{
    width:300px;
    height:300px;
    position:absolute;
}
#div1{
      top:20px;
      left:40px;
      z-index:1;
}
#div2{
      top:30px;
      left:60px;
      z-index:5;    
}

祝学习愉快!

0

0 学习 · 4928 问题

查看课程