whatisthis?
practice - css ) μ¬λΌμ΄λ νμ΄μ§ - CSS only (JSβ) λ³Έλ¬Έ
PRACTICE/SELF
practice - css ) μ¬λΌμ΄λ νμ΄μ§ - CSS only (JSβ)
thisisyjin 2022. 3. 11. 16:48Slide Page
- only CSS
- without JS
- π μ€μ΅νλ©΄μ μκ²λ μ κΈ°λ‘
μ¬μ§κ» jsλ‘ λ³΅μ‘νκ² νλ λ°©μ λμ , jsλ₯Ό νλλ μμ°κ³
μ€λ‘μ§ cssμ :checked μ νμ λ§μΌλ‘ μ¬λΌμ΄λλ₯Ό ꡬνν μ μλ€κ³ νλ€.
π :checked
- CSS κ°μν΄λμ€
- μ ννκ±°λ on μνμΈ radio, checkbox, optionμμλ₯Ό λνλ
__
π CSS sibling element κ΄λ ¨ κ²°ν©μ
~ : μ΄ν νμ μμ λ€κ°μ΄~ μ ννλ λλ.
+ : λ°λ‘ λ€μμ μμΉνλ νμ μμλ§ μ ν.
>> λ°λ‘ λ€μ νμ λ§ νμνλ©΄ + / κ·Έ μΈκ° νμνλ©΄ ~ μ°κΈ°.
p ~ span { color: red; }β
π https://developer.mozilla.org/ko/docs/Web/CSS/General_sibling_combinator<span>μ΄κ±΄ λΉ¨κ°μ΄ μλλλ€.</span> <p>μ¬κΈ° λ¬Έλ¨μ΄ μμ΅λλ€.</p> <code>κ·Έλ¦¬κ³ μ½λλ μμ΅λλ€.</code> <span>μ΄μ λΉ¨κ°μ λλ€!</span> <code>λ λ§μ μ½λκ° μμ΅λλ€.</code> <span>μ΄κ²λ λΉ¨κ°μ λλ€!</span>
ver 1 - κ°λ‘ μ¬λΌμ΄λ (κΈ°λ³Έ)
app.html
<!DOCTYPE html>
<html lang="en">
<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>Slide Banner</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="slide">
<input type="radio" name="pos" id="pos1" checked />
<input type="radio" name="pos" id="pos2" />
<input type="radio" name="pos" id="pos3" />
<input type="radio" name="pos" id="pos4" />
<ul class="outer">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<p class="bullet">
<label for="pos1">1</label>
<label for="pos2">2</label>
<label for="pos3">3</label>
<label for="pos4">4</label>
</p>
</div>
</body>
</html>
style.css
/* colors
#fbf8cc
#f1c0e8
#cfbaf0
#a3c4f3
*/
* {
margin: 0;
padding: 0;
}
ul,
li {
list-style: none;
}
.slide {
height: 300px;
overflow: hidden;
position: relative;
}
.slide .outer {
width: calc(100% * 4);
display: flex;
transition: all 1s ease-out;
}
.slide li {
width: calc(100% / 4);
height: 300px;
}
.slide li:nth-child(1) {
background-color: #fbf8cc;
}
.slide li:nth-child(2) {
background-color: #f1c0e8;
}
.slide li:nth-child(3) {
background-color: #cfbaf0;
}
.slide li:nth-child(4) {
background-color: #a3c4f3;
}
.slide input {
display: none;
}
.slide .bullet {
position: absolute;
bottom: 20px;
left: 0;
right: 0;
text-align: center;
z-index: 10;
}
.slide .bullet label {
cursor: pointer;
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
border: 2px solid #666;
font-size: 0;
background-color: #fff;
transition: all 0.5s ease-in-out;
}
/* radio 체ν¬μ - λ§μ§ μ μ© */
#pos1:checked ~ .outer {
margin-left: 0;
}
#pos2:checked ~ .outer {
margin-left: -100%;
}
#pos3:checked ~ .outer {
margin-left: -200%;
}
#pos4:checked ~ .outer {
margin-left: -300%;
}
/* bullet μ‘ν°λΈ νμ */
#pos1:checked ~ .bullet label:nth-child(1),
#pos2:checked ~ .bullet label:nth-child(2),
#pos3:checked ~ .bullet label:nth-child(3),
#pos4:checked ~ .bullet label:nth-child(4) {
background-color: #666;
}
ver 2 - κ°λ‘ νμ΄λ (opacity μ΄μ©)
style.css
/* colors
#fbf8cc
#f1c0e8
#cfbaf0
#a3c4f3
*/
* {
margin: 0;
padding: 0;
}
ul,
li {
list-style: none;
}
.slide {
height: 300px;
overflow: hidden;
position: relative;
}
.slide li {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
opacity: 0;
transition: all 1s ease-out;
}
.slide li:nth-child(1) {
background-color: #fbf8cc;
}
.slide li:nth-child(2) {
background-color: #f1c0e8;
}
.slide li:nth-child(3) {
background-color: #cfbaf0;
}
.slide li:nth-child(4) {
background-color: #a3c4f3;
}
.slide input {
display: none;
}
.slide .bullet {
position: absolute;
bottom: 20px;
left: 0;
right: 0;
text-align: center;
z-index: 10;
}
.slide .bullet label {
cursor: pointer;
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
border: 2px solid #666;
font-size: 0;
background-color: #fff;
transition: all 0.5s ease-in-out;
}
/* radio 체ν¬μ - opacity 1λ‘ */
#pos1:checked ~ ul li:nth-child(1),
#pos2:checked ~ ul li:nth-child(2),
#pos3:checked ~ ul li:nth-child(3),
#pos4:checked ~ ul li:nth-child(4) {
opacity: 1;
}
/* bullet μ‘ν°λΈ νμ */
#pos1:checked ~ .bullet label:nth-child(1),
#pos2:checked ~ .bullet label:nth-child(2),
#pos3:checked ~ .bullet label:nth-child(3),
#pos4:checked ~ .bullet label:nth-child(4) {
background-color: #666;
}
result
ref >
'PRACTICE > SELF' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
practice) React.js - ν±νν (Tic Tac Toe) κ²μ (0) | 2022.03.15 |
---|---|
practice - css ) BookStore UI (0) | 2022.03.12 |
practice - js ) μ¬λΌμ΄λ νμ΄μ§ (2) ν°μΉν(λλκ·Έ) (0) | 2022.03.11 |
practice - js ) μ¬λΌμ΄λ νμ΄μ§ (1) λ²νΌν (0) | 2022.03.11 |
practice - css / js ) Tab Menu (0) | 2022.03.11 |