작성
·
419
답변 2
1
내용을 나타나게 한다는건 동작을 말씀하시는거죠?
그런 동작들은 CSS 그리드와는 관계가 없고, 자바스크립트로 하셔야 합니다.
아래 간단하게 코드를 작성해 보았으니 한번 테스트 해보세요~
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
}
.container {
display: grid;
grid-template-columns: 150px 1fr;
min-height: 100%;
}
.menu-area {
background: #fff000;
}
.content-area {
background: lightgray;
}
.menu a {
display: block;
}
.content {
display: none;
}
.content.show {
display: block;
}
</style>
</head>
<body>
<div class="container">
<div class="menu-area">
<nav class="menu">
<a href="#" data-index="0">menu 0</a>
<a href="#" data-index="1">menu 1</a>
<a href="#" data-index="2">menu 2</a>
</nav>
</div>
<div class="content-area">
<div class="content" data-index="0">
content-0
</div>
<div class="content" data-index="1">
content-1
</div>
<div class="content" data-index="2">
content-2
</div>
</div>
</div>
<script>
(function () {
const menu = document.querySelector('.menu');
const contents = document.querySelectorAll('.content');
let currentContent = contents[0];
function activate() {
currentContent.classList.add('show');
}
function inactivate() {
currentContent.classList.remove('show');
}
menu.addEventListener('click', function (e) {
e.preventDefault();
if (e.target.dataset.index) {
if (currentContent) {
inactivate();
}
currentContent = contents[e.target.dataset.index];
activate();
}
});
activate();
})();
</script>
</body>
</html>
0