1. 程式人生 > >css顯示隱藏div

css顯示隱藏div

<!DOCTYPE html>  
<html lang="zh-cn">  
<head>  
    <meta charset="utf-8"/>  
    <title>hover顯示隱藏div</title>  
    <style type="text/css">  
        #div1{
            width: 300px;
            height: 300px;
            background: lime;
        }
        .div2{
            width: 300px;
            height: 300px;
            background: #ccc;
            position: relative;
            top: 350px;
            left: 350px;
            display: none; 
        }
         #div1:hover .div2{
            display: block;
         }
    </style>  
  
</head>  
<body>  
    <div id="div1">
        顯示的div1
        <p>當滑鼠移入div1的時候,顯示div2</p>
        <div class="div2">
            隱藏的div2
        </div>
    </div>
  
</body>  
</html>