[jQuery] 멀티탭 구현
07 Oct 2021 -
Less than 1 minute read
제이쿼리를 이용해 멀티탭 구현하기
See the Pen 멀티탭 구현 by Jinsol (@losuif) on CodePen.
HTML
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>멀티탭</title>
<link rel="stylesheet" href="style/style.css">
</head>
<body>
<h1>멀티탭구현</h1>
<div id="wrap">
<div id="btns">
<button type="button" class="selected">
공지사항
</button>
<button type="button" class="">
갤러리
</button>
</div>
</div>
<!-- div#wrap -->
<script src="script/jquery-3.6.0.min.js"></script>
<script src="script/script.js"></script>
</body>
</html>
CSS
@charset "UTF-8";
* {
box-sizing: border-box;
}
h1 {
width: 500px;
text-align: center;
border: 2px solid #aaa;
margin: 20px auto;
}
div#wrap {
width: 500px;
margin: 20px auto;
}
div#btns {
border: 3px solid #000;
padding: 34px;
display: flex;
}
button {
border: 1px solid #666;
font-size: 22px;
font-weight: bold;
padding: 6px 10px;
border-right: none;
border-left: none;
cursor: pointer;
}
button.selected {
border-right: 1px solid #666;
border-left: 1px solid #666;
background-color: #fff;
}
button:not(.selected) {
border-right: 1px solid #666;
}
JavaScript
$(function(){
$("button").click(function(){
$("button").css({"background-color":"#fff"});
$(this).css({"background-color":"#efefef"});
});
});