๐ŸŒˆCSS:Selector

hojuneยท2023๋…„ 8์›” 13์ผ
0

Web Development

๋ชฉ๋ก ๋ณด๊ธฐ
6/33

Universal Selector

* =  ์ „์ฒด ์„ ํƒ์ž

Element Selector


img, button, etc.



Selector List

,(์‰ผํ‘œ๋กœ) ์—ฌ๋Ÿฌ๊ฐœ ๊ฐ€๋Šฅ

h1,h2 { color : blue;}

ID Selector - '#'

<button id="signup">Sign Up</button> -html
#signup {background-color: black;} - css

id - ๋„์–ด์“ฐ๊ธฐ x

     ์งง์€ ๊ธธ์ด

     ์˜๋ฏธ ํฌํ•จ

     ์ค‘๋ณต ์‚ฌ์šฉ x (ํŒŒ์ผ์•ˆ์—์„œ ํ•˜๋‚˜๋งŒ ์‚ฌ์šฉ ํ•  ๊ฒƒ)

Class Selector - .

<span class="tag">funny</span>
.tag { background-color: #e63946;

       color: #f1faee;

       font-size: 16px;}
       

์œ ํ˜•์ด ๊ฐ™์ง€ ์•Š์•„๋„ ๋จ class๋ฅผ ์ด์šฉํ•˜๋ฉด ๊ณตํ†ต์ ์œผ๋กœ ์š”์†Œ ์ ์šฉ ๊ฐ€๋Šฅ

์šฐ์„ ์ˆœ์œ„๋กœ class selector ์ ์šฉ

<li class="done">Walk Chickens</li>

<li>Clean Out Coop</li>

<li class="done">Collect Chicken Eggs</li>
 
<li>Incubate Chicken Eggs</li>

<li>Hatch New Chickens!</li>
.done{color:grey;}

li{color:blue;}

Descendant Selector- (๊ณต๋ฐฑ)

header a {font-size:30px; color:teal;}



#dislikes a {color:red; font-weight:bold;}



๊ณต๋ฐฑ(๋„์–ด์“ฐ๊ธฐ)๊ฐ€ ์ค‘์š”ํ•จ

Adjacent Selector - +

 <nav>

      <label for="search">Search</label>

      <input type="text" placeholder="search" id="search">

      <input type="password" placeholder="password">

      <button>Log In</button>

      <button id="signup">Sign Up</button>

</nav>
input + button { background-color: pink;}

์„ค๋ช… : input ๋‹ค์Œ์—์˜ค๋Š” button์„ ์„ ํƒํ•จ

Direct Child - >

 <footer>
        <nav>
            <ul>
                <li>
                    <a href="#home">Home</a>
                </li>
                <li>
                    <a href="#about">About</a>
                </li>
                <li>
                    <a href="#contact">Contact</a>
                </li>
                <li>
                    <a href="www.google.com">Google</a>
                </li>
            </ul>
        </nav>
      <a href="#license">Content is available under these licenses.</a>
 </footer>
footer>a {color: red;}

footer ํ•œ๋‹จ๊ณ„ ์•„๋ž˜์ธ <a> tag์—๋งŒ ์ ์šฉ

footer >ul >li >a ์—๋Š” ์ ์šฉ์ด ์•ˆ๋จ

+)adjicent selector์™€ direct child ๋Š” ๋งŽ์ด ์“ฐ์ด์ง€๋Š” ์•Š์Œ


Attribute Selector

<input type="password" placeholder="password">
input [type="password"] { color: greenyellow;}

<a href="www.google.com">Google</a>
a[href *="google"] { color: magenta;}

" *= " 

Pseudo Classes

:hover = ์ปค์„œ๋ฅผ ์˜ฌ๋ ค๋‘๋ฉด ํŠน์ • ํšจ๊ณผ ๋ฐœ์ƒ

button:hover { color: aqua;}



:active = ํ™œ์„ฑํ™”๋˜์—ˆ์„ ๋•Œ ๋‹ค๋ฅธ ์ƒ‰์ด๋‚˜ ์ƒํƒœ๋ฅผ ๋ถ€์—ฌ (ex)๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๊ณ  ์žˆ์œผ๋ฉด)

button:active {color: yellowgreen;}



:checkd = radio type or checkbox type ์—์„œ ์ฒดํฌ๊ฐ€ ๋˜์–ด์žˆ์„ ๋‚˜ํƒ€๋‚˜๋Š” ๋‹ค๋ฅธ ์ƒ‰์ด๋‚˜ ์ƒํƒœ๋ฅผ ๋ถ€์—ฌ



:nth-of-type = ๋™์ผํ•œ ์œ ํ˜•์—์„œ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ ์šฉ์‹œํ‚ด



.post:nth-of-type(3n) { background-color: wheat;}

Pseudo Elements

๋ณดํ†ต :: ๋กœ ์ž‘๋™

h2::first-letter { font-size: 50px;}

first-line ๋“ฑ๋“ฑ ์—ฌ๋Ÿฌ ์˜ต์…˜์ด ์žˆ์Œ

- The Cascade 

 code์ˆœ์„œ์— ๋”ฐ๋ผ ์œ„์—์„œ๋ถ€ํ„ฐ ์•„๋ž˜๋กœ ์ ์šฉ๋จ


- Specificity

 Inline Styles > ID > CLASS > ELEMENT

 ์ถฉ๋Œ์ด ์žˆ์„ ๋•Œ๋Š” ์ ์ˆ˜ ํ•ฉ์‚ฐ์œผ๋กœ ๊ฒฐ์ •๋จ

 specificity calculator ์‚ฌ์šฉ ๊ฐ€๋Šฅ



- chrome ๊ฐœ๋ฐœ์ž ๋„๊ตฌ๋Š” ์œ ์šฉํ•˜๋‹ค


- Inline Styles

 ์‚ฌ์šฉ๋„๊ฐ€ ๋–จ์–ด์ง html ์ฝ”๋“œ์†์— ์ ๋‹ค ๋ณด๋‹ˆ ์ฝ”๋“œ ๊ฐ€๋…์„ฑ๊ณผ ์‹ค์šฉ์„ฑ์ด ๋–จ์–ด์ง


- !important

 specificity๋ฅผ ๋„˜์–ด์„œ๋Š” ๋ช…์‹œ์  ์ง€์‹œ 


- Inheritance

color : inherite

์ด๋Ÿฐ์‹์œผ๋กœ ์ด์šฉ ๊ฐ€๋Šฅ



- ๊ฐœ๋ฐœ์ž๋„๊ตฌ - elments๋ฅผ ๋“ค์–ด๊ฐ€๋ฉด ๋ฌด์—‡์œผ๋กœ๋ถ€ํ„ฐ ์ƒ์†๋ฐ›์•˜๋Š”์ง€ ๋“ฑ์„ ์•Œ ์ˆ˜ ์žˆ์Œ

0๊ฐœ์˜ ๋Œ“๊ธ€