▶ 버튼 클릭 시 alert박스가 뜨고 닫기 버튼 클릭시 다시 alert박스가 사라진다.
[핵심 코드]
<div id="box" class="alert-box">Alert!
<button onclick="document.getElementById('box').style.display = 'none';">닫기</button>
</div>
<button onclick="document.getElementById('box').style.display = 'block';">버튼</button>
[HTML]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div id="box" class="alert-box">Alert!
<button onclick="document.getElementById('box').style.display = 'none';">닫기</button>
</div>
<button onclick="document.getElementById('box').style.display = 'block';">버튼</button>
</body>
</html>
[CSS]
.alert-box {
background-color: skyblue;
padding: 20px;
color: white;
border-radius: 5px;
display: none;
}
': ) Web > 웹 스터디' 카테고리의 다른 글
[JS] [실습] function 문법 | alert 박스 만들기 (0) | 2024.01.05 |
---|---|
[JS] [이론] function 문법 (1) | 2024.01.05 |
[HTML, CSS] [실습] CSS Grid로 레이아웃 만들기 (grid-column, grid-row이용) (0) | 2023.12.15 |
[HTML, CSS] CSS Grid 레이아웃 만들기 (0) | 2023.12.15 |
[HTML, CSS] [실습] transition & animation으로 navbar만들기 (0) | 2023.12.15 |