HTML tag
CSS 의사 클래스를 사용하여 드롭다운 메뉴 만들기:focus
<style>
/* Dropdown styles */
.dropdown {
max-width: 13em;
margin: 80px auto 0;
position: relative;
width: 100%;
}
.dropdown-btn {
background: #1d1f24;
font-size: 18px;
width: 100%;
border: none;
color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.7em 0.5em;
border-radius: 0.5em;
cursor: pointer;
}
.arrow {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 6px solid #fff;
transition: transform ease-in-out 0.3s;
}
.dropdown-content {
list-style: none;
position: absolute;
top: 3.2em;
width: 100%;
visibility: hidden;
overflow: hidden;
}
.dropdown-content li {
background: #2f3238;
border-radius: 0.5em;
position: relative;
left: 100%;
transition: 0.5s;
transition-delay: calc(60ms * var(--delay));
}
.dropdown-btn:focus + .dropdown-content li {
left: 0;
}
.dropdown-btn:focus + .dropdown-content {
visibility: visible;
}
.dropdown-btn:focus > .arrow {
transform: rotate(180deg);
}
.dropdown-content li:hover {
background: #1d1f24;
}
.dropdown-content li a {
display: block;
padding: 0.7em 0.5em;
color: #fff;
margin: 0.1em 0;
text-decoration: none;
}
/* base styles */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Segoe UI", sans-serif;
color: #333;
/* background: #cecece; */
}
</style>
<div style="text-align: center; margin-top: 2rem;">
<h2>#1: Using CSS :focus</h2>
<p>Click on the button to display the dropdown menu</p>
</div>
<div class="dropdown">
<button class="dropdown-btn" aria-haspopup="menu">
<span>Framework</span>
<span class="arrow"></span>
</button>
<ul class="dropdown-content" role="menu">
<li style="--delay: 1;"><a href="#">React</a></li>
<li style="--delay: 2;"><a href="#">Angular</a></li>
<li style="--delay: 3;"><a href="#">Vue</a></li>
<li style="--delay: 4;"><a href="#">Svelte</a></li>
</ul>
</div>
HTMLtag
카페 게시글
검색이 허용된 게시물입니다.
다음검색