Web

DIV 팝업창 띄우기

Zyss 2024. 2. 27. 18:16
반응형

DIV 팝업창 띄우기

 

 

  <style>
    #popup {
      position: fixed;
      top: 28%;
      left: 30%;
      transform: translate(-50%, -50%);
      width: 500px;
      height: 400px;
      background-color: #fff;
      border: 1px solid #ccc;
      padding: 20px;
      z-index: 100;
      display: none;
    }
    
    #popup h2 {
      margin-top: 0;
    }
    
    #popup button {
      margin-top: 10px;
    }
  </style>


<body onload="openPopup()">
  <div id="popup">
      <h2>팝업창 제목</h2>
      <P> 내용 </P>
  
    <button onclick="closePopup()">닫기</button>
  </div>    
  
    <script>
    function openPopup() {
      document.getElementById("popup").style.display = "block";
    }
    
    function closePopup() {
      document.getElementById("popup").style.display = "none";
    }
  </script>

 

 

 

반응형