CSS :nth-child() Selector (w3schools.com)
CSS :nth-child() Selector
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
Example
How to use the :nth-child() selector:
div:nth-child(2) {
background: red;
}
/* Selects the second li element in a list */
li:nth-child(2) {
background: lightgreen;
}
/* Selects every third element among any group of siblings */
:nth-child(3) {
background: yellow;
}
์ ์ฉํ ์๋ ํ๊ทธ ์ต์คํ ์ htmltagwrap
์ฌ์ฉ๋ฒ alt+w
๋ถํธ์คํธ๋ฉ์ ์ต์ข css๋ณด๋ค ์์ ๋ถ์ฌ์ฃผ๋๋ก ํ์. ๊ฐ๋ฐ์๊ฐ ์์ฑํ css๊ฐ ์ต์ฐ์ ์์๊ฐ ๋ ์ ์๊ฒ๋.
<form action="https://www.google.com/search" method="GET">
<div
class="mx-auto mt-5 position-absolute top-90 start-50 translate-middle search-bar input-group mb-3"
>
<input
name="q"
type="text"
class="form-control rounded-pill"
placeholder="Google ๊ฒ์ ๋๋ URL ์
๋ ฅ"
aria-label="Recipient's username"
aria-describedby="button-addon2"
/>
</div>
</form>
<form>ํ๊ทธ์ action์ ์ด๋๋ก ํฅํ ๊ฑด์ง๋ผ๋ ์ฃผ์์ด๊ณ
method๋ ๋ฐ์ดํฐ์ ์ ์ก ๋ฐฉ์์ด๋ค.
Get ๋ฐฉ์์ ์ฃผ์์ฐฝ์ ๋ญ๊ฐ๋ฅผ ?๋ฌผ์ํ ๋ค์ name์ ํด๋นํ๋๊ฑธ ๊ฐ์ ธ์์ ์ฌ์ฉ์๊ฐ ์์ฑํ๊ฑธ ๋ณด๋ด์ฃผ๋ ๋ฐฉ์
https://www.google.com/search?q="์ฌ์ฉ์์
๋ ฅ๊ฐ"
<form action="https://www.google.com/search" method="GET">
<div
class="mx-auto mt-5 position-absolute top-90 start-50 translate-middle search-bar input-group mb-3"
>
<input
name="q"
type="text"
class="form-control rounded-pill"
placeholder="Google ๊ฒ์ ๋๋ URL ์
๋ ฅ"
aria-label="Recipient's username"
aria-describedby="button-addon2"
/>
</div>
</form>
๋ฐ๋๋ก post ๋ฐฉ์์ ์ฌ์ฉํ๊ฒ ๋๋ฉด
์ฃผ์์ฐฝ์ ์ ๋ฌํ ๋๊ฐ ์๋๋ผ ๋ด๋ถ์ ์ผ๋ก ๋ญ๊ฐ๋ฅผ ์ ๋ฌํ ๋ ์ฌ์ฉํ๋ค.
๊ตฌ๊ธ ๊ฒ์์ฐฝ ๊ฐ์ ๊ฒฝ์ฐ๋ ์ฃผ์์ฐฝ์ ์ ๋ณด๋ฅผ ๋ณด๋ด๊ธฐ ๋๋ฌธ์
Get ๋ฐฉ์์ผ๋ก ์ฌ์ฉ์์ ์ ๋ ฅ ๋ด์ฉ์ q๋ผ๋ ์ด๋ฆ์ ๋ด์์ ๋ณด๋ผ ๊ฒ์ด๋ค.
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" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="style.css" />
<title>Document</title>
</head>
<body>
<h1>
<span>G</span><span>o</span><span>o</span><span>g</span><span>l</span
><span>e</span>
</h1>
<form action="https://www.google.com/search" method="GET">
<div
class="mx-auto mt-5 position-absolute top-90 start-50 translate-middle search-bar input-group mb-3"
>
<input
name="q"
type="text"
class="form-control rounded-pill"
placeholder="Google ๊ฒ์ ๋๋ URL ์
๋ ฅ"
aria-label="Recipient's username"
aria-describedby="button-addon2"
/>
</div>
</form>
</body>
</html>
css
h1 {
margin-top: 257px;
text-align: center;
font-size: 90px;
font-weight: 550;
}
form {
text-align: center;
}
h1 span:nth-child(1) {
color: #4582f4;
}
h1 span:nth-child(2) {
color: #ea4335;
}
h1 span:nth-child(3) {
color: #fbbc05;
}
h1 span:nth-child(4) {
color: #4285f4;
}
h1 span:nth-child(5) {
color: #34a853;
}
h1 span:nth-child(6) {
color: #ea4335;
}
.search-bar {
width: 500px;
}
'๋งํฌ์ > Html & Css' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Html/css ๊ตฌ์ฑํ๋๋ฐ ์ ์ฉํ ์ฌ์ดํธ (0) | 2022.04.23 |
---|---|
[1๋ถ ์ฝ๋ฉ] CSS ๋ ์ด์์ ํต์ฌ (0) | 2022.03.26 |
CSS์ ๋ ์ด์์ display (0) | 2022.03.21 |
CSS ๊ธฐ์ด ๊ธฐ๋ณธ (0) | 2022.03.20 |
๋ฐ์ํ ์น ํ์ํ ๋ถํธ์คํธ๋ฉ (0) | 2022.03.18 |