๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ณต๋ถ€/HTML&CSS

[ex34~37] CSS(selector-nth:child,์ ‘์€๊ธ€,::before)

ex34

 

๊ฐ€์ƒ ํด๋ž˜์Šค
1. :first-child > ์ž์‹ ์ด ์ž์‹ ์˜ ๊ทธ๋ฃน์—์„œ ์ฒซ๋ฒˆ์งธ ์ž์‹์ธ์ง€?
2. :last-child > ์ž์‹ ์ด ์ž์‹ ์˜ ๊ทธ๋ฃน์—์„œ ๋งˆ์ง€๋ง‰ ์ž์‹์ธ์ง€?
3. :nth-child() > 1๋ถ€ํ„ฐ ์‹œ์ž‘
4. :nth-last-child() > ๋’ค์—์„œ๋ถ€ํ„ฐ

n
1. ์ˆซ์ž: index(์œ„์น˜) > 1๋ถ€ํ„ฐ ์‹œ์ž‘
2. ์ˆ˜์—ด: 2n, 2n+1 (0๋ถ€ํ„ฐ ์‹œ์ž‘)
3. ์ˆ˜์—ด: even, odd

 

์ฝ”๋“œ

๋”๋ณด๊ธฐ
    <style>

        li:nth-child(odd) {
            color: orange;
        }




        /* 
        li:first-child {
            color: orange;
        }

        li:last-child {
            color: coral;
        }

        li:nth-child(3) {
            color: blue;
        }

        li:nth-last-child(3) {
            color: gold;
        } 
        */

        .tbl {
            border: 1px solid black;
            border-collapse: collapse;
        }

        .tbl td {
            border: 1px solid black;
            padding: 5px;
        }

        /* .tbl tr:first-child {
            background-color: gold;
        } */

        /* ๋ชจ๋“  td๋“ค์˜ ์ฒซ์งธ๋“ค > ์ฒซ๋ฒˆ์งธ์—ด */
        /* .tbl td:first-child {
            background-color: tomato;
        } */
        
        /* ๋‹ค์„ฏ๋ฒˆ์งธ์—ด */
        /* .tbl td:nth-child(5) {
            background-color: tomato;
        } */

        /* ์ง์ˆ˜ํ–‰ */
        /* .tbl tr:nth-child(even) {
            background-color: #DDD;
        } */

        /* ์ง์ˆ˜ํ–‰์ด๋ฉด์„œ ํ™€์ˆ˜์—ด */
        .tbl tr:nth-child(even) td:nth-child(odd) {
            background-color: gold;
        }
        
        /* ํ™€์ˆ˜ํ–‰์ด๋ฉด์„œ ์ง์ˆ˜์—ด */
        .tbl tr:nth-child(odd) td:nth-child(even) {
            background-color: gold;
        }

        
    </style>
</head>
<body>
    <!-- ex34_selector.html -->

    <h1>๋ชฉ๋ก</h1>

    <ul class="list1">
        <li>๊ฐ•์•„์ง€</li>
        <li>๊ณ ์–‘์ด</li>
        <li>๋‹ค๋žŒ์ฅ</li>
        <li>์†Œ</li>
        <li>๋ผ์ง€</li>
        <li>๋ง</li>
        <li>์ฝ”๋ผ๋ฆฌ</li>
        <li>์‚ฌ์ž</li>
        <li>ํ˜ธ๋ž‘์ด</li>
        <li>๋Š‘๋Œ€</li>
    </ul>

    <h1>ํ…Œ์ด๋ธ”</h1>

    <!-- table.tbl>tr*20>td{item}*10 -->
    <table class="tbl">
        <tr>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
        </tr>
        <tr>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
        </tr>
        <tr>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
        </tr>
        <tr>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
            <td>item</td>
        </tr>
    </table>

</body>
</html>

 

ํ™”๋ฉด

๋”๋ณด๊ธฐ

๋ชฉ๋ก

  • ๊ฐ•์•„์ง€
  • ๊ณ ์–‘์ด
  • ๋‹ค๋žŒ์ฅ
  • ์†Œ
  • ๋ผ์ง€
  • ๋ง
  • ์ฝ”๋ผ๋ฆฌ
  • ์‚ฌ์ž
  • ํ˜ธ๋ž‘์ด
  • ๋Š‘๋Œ€

ํ…Œ์ด๋ธ”

item item item item item item item item item item
item item item item item item item item item item
item item item item item item item item item item
item item item item item item item item item item

ex35

 

์†์„ฑ ์„ ํƒ์ž
1. ์„ ํƒ์ž[์†์„ฑ๋ช…]     : ํ•ด๋‹น ์†์„ฑ์„ ๋ช…์‹œํ–ˆ๋Š”์ง€?
2. ์„ ํƒ์ž[์†์„ฑ๋ช…=๊ฐ’]  : ํ•ด๋‹น ์†์„ฑ๊ณผ ๊ฐ’์„ ๋ช…์‹œํ–ˆ๋Š”์ง€?
3. ์„ ํƒ์ž[์†์„ฑ๋ช…^=๊ฐ’] : ์†์„ฑ๊ฐ’์ด ๊ฐ’์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š”์ง€?
4. ์„ ํƒ์ž[์†์„ฑ๋ช…$=๊ฐ’] : ์†์„ฑ๊ฐ’์ด ๊ฐ’์œผ๋กœ ๋๋‚˜๋Š”์ง€?
5. ์„ ํƒ์ž[์†์„ฑ๋ช…*=๊ฐ’] : ์†์„ฑ๊ฐ’์ด ํฌํ•จ๋˜๋Š”์ง€?

 

/* target ์†์„ฑ์„ ๊ฐ€์ง€๊ณ ์žˆ๋Š” a ํƒœ๊ทธ */
.list a[target] { background-color: gold;}
/* ์†์„ฑ๊ฐ’ ์กฐ๊ฑด  */
.list a[target=_blank] { background-color: gold;}
/* ์†์„ฑ๊ฐ’์ด ~๋กœ ์‹œ์ž‘ํ•˜๋Š”์ง€ */
.list a[href^=https] { background-color: gold;}
/* ์†์„ฑ๊ฐ’์ด ~๋กœ ๋๋‚˜๋Š”์ง€ */
.list a[href$='.com'] { background-color: gold;}
/* ์†์„ฑ๊ฐ’์— ~๊ฐ’์ด ํฌํ•จ๋˜๋Š”์ง€ */
.list a[href*=m] { background-color: gold;}

ex36

 

์ ‘๊ธฐ

 

์ฝ”๋“œ

๋”๋ณด๊ธฐ

 

<!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>Document</title>
    <style>
        .list input[type=text] {
            display: block;
            border: 1px solid #555;
            padding: 3px;
            margin-bottom: 3px;
            background-color: white;
            color: #444;
            outline: none;
        }

        /* optional : required๊ฐ€ ์•„๋‹Œ๊ฒƒ */
        /* .list input[type=text]:required { background-color: gold; } */
        /* .list input[type=text]:optional { background-color: #CCC; } */

        /* .list input[type=text]:disabled { background-color: #999; }
        .list input[type=text]:enabled { background-color: gold; } */

        /* .list input[type=text]:read-only { cursor: not-allowed; }
        .list input[type=text]:read-write { background-color: gold; } */
        

        input[type=checkbox] {
            /* ๊ฑฐ์˜ ์•ˆ๋จ */
            /* border: 1px solid black; */
            /* background-color: blue; */

            /* width: 200px; */

            /* ๋ถˆํˆฌ๋ช…๋„(0~1) */
            /* opacity: 0.2; */
        }

        input[type=checkbox]:checked {
            opacity: 1;
        }

        .cb-cat + .cat {
            visibility: hidden;
        }
        
        .cb-cat:checked + .cat {
            visibility: visible;
        }

        .cb1 + div {
            /* visibility: hidden; */

            /* ์•ˆ๋ณด์ผ๋•Œ ๊ณต๊ฐ„ ์ฐจ์ง€x */
            display: none;
        }
        
        .cb1:checked + div {
            /* visibility: visible; */
            display: block;
        }


        .item {
            border: 1px solid #555;
            width: 200px;
        }

        .item #cb2 {
            display: none;
        }

        .item label {
            font-size: 1.5rem;
            font-family: Arial;
            font-variant: small-caps;
            display: block;
            padding: 10px;
            background-color: greenyellow;
            cursor: pointer;
        }

        .item div {
            padding: 12px;
            border-top: 1px solid #555;
            display: none;
        }

        .item #cb2:checked + label {
            background-color: gold;
        }

        /* cb2๊ฐ€ ์ฒดํฌ๋˜๋ฉด ํ˜•์ œ์ธ label์˜ ํ˜•์ œ์ธ div๊ฐ€ ๋ณด์ธ๊ฒŒ */
        .item #cb2:checked + label + div {
            display: block;
        }


        
    </style>
</head>
<body>
    <!-- ex36_selector.html -->

    <div class="item">
        <input type="checkbox" class="cb2" id="cb2">
        <label for="cb2">Html</label>
        <div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Aspernatur architecto et magni dolores eligendi harum ducimus odio quos sed quod dolorum error consectetur rem, libero cupiditate repellendus rerum voluptatem vero!</div>
    </div>



    <hr>

    ์ œ๋ชฉ <input type="checkbox" class="cb1">
    <div>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Optio, commodi ab! Molestias tempora tenetur nesciunt quod numquam recusandae quibusdam, dolore perferendis maxime esse quisquam dignissimos quos ipsa odit optio delectus.</div>

    <details>
        <summary>์ œ๋ชฉ</summary>
        <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Expedita neque deleniti impedit! Vel voluptatibus quo magnam in, nobis, quod ex culpa, error asperiores odio ut voluptatum exercitationem nesciunt. Delectus, ad.</p>
    </details>

    <div>
        <input type="checkbox" class="cb-cat">
        <img src="images/catty01.png" class="cat">
    </div>

    <div>
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
    </div>

    <div class="list">
            <input type="text" value="1" required>
            <input type="text" value="2" readonly>
            <input type="text" value="3" readonly>
            <input type="text" value="4">
            <input type="text" value="5" required>
            <input type="text" value="6" disabled>
            <input type="text" value="7" disabled>
            <input type="text" value="8">
            <input type="text" value="9">
            <input type="text" value="10" required>
    </div>
</body>
</html>

 

ํ™”๋ฉด

๋”๋ณด๊ธฐ
Document
Lorem ipsum dolor sit amet consectetur adipisicing elit. Aspernatur architecto et magni dolores eligendi harum ducimus odio quos sed quod dolorum error consectetur rem, libero cupiditate repellendus rerum voluptatem vero!

์ œ๋ชฉ
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Optio, commodi ab! Molestias tempora tenetur nesciunt quod numquam recusandae quibusdam, dolore perferendis maxime esse quisquam dignissimos quos ipsa odit optio delectus.
์ œ๋ชฉ

Lorem ipsum dolor sit amet consectetur adipisicing elit. Expedita neque deleniti impedit! Vel voluptatibus quo magnam in, nobis, quod ex culpa, error asperiores odio ut voluptatum exercitationem nesciunt. Delectus, ad.


ex37

 

CSS ์„ ํƒ์ž(๊ฐ€์ƒ ํด๋ž˜์Šค)
1. :first-child
    - ๊ฐ€์ƒ ํด๋ž˜์Šค
    - ๊ฒ€์ƒ‰๋œ ํƒœ๊ทธ ์ž์ฒด๋ฅผ ์กฐ์ž‘
2. ::before
    - ๊ฐ€์ƒ ์š”์†Œ(Element)
    - ๊ฒ€์ƒ‰๋œ ํƒœ๊ทธ ์ฃผ๋ณ€์„ ์กฐ์ž‘

์ „ํ›„ ์„ ํƒ์ž
1. ::before(:before)
2. ::after(:after)

 

์ „์ฒด์ฝ”๋“œ 

๋”๋ณด๊ธฐ
<!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>Document</title>
    <style>

        span {
            color: blue;
        }

        span::before {
            content: '[';
        }
        span::after {
            content: ']';
        }

        /* ์•ž์— ์‚ฝ์ž… */
        /* span::before {
            content: 'ํ™๊ธธ๋™';
            color: orange;
            font-weight: bold;
            font-size: 1.5rem;
        }
        /* ๋’ค์— ์‚ฝ์ž… */
        /* span::after {
            content: '์•„๋ฌด๊ฐœ';
            color: pink;
        } */ 

        /* ๊ณต๋ฐฑ์ œ๊ฑฐ ๋ฐฉ๋ฒ•1 > font-size: 0; */
        /* #list {
            font-size: 0;
        }
        
        #list div {
            width: 100px;
            height: 100px;
            display: inline-block;
            font-size: 1rem;
        } */
        
        
        /* ๊ณต๋ฐฑ์ œ๊ฑฐ ๋ฐฉ๋ฒ•2 > float */
        #list .item {
            width: 100px;
            height: 100px;
            float: left;
        }

        /* float ๋’ท์ฒ˜๋ฆฌ ์šฉ๋„ */
        #list::after {
            content: '';
            display: block; /* clear๋Š” ๋ธ”๋Ÿญํƒœ๊ทธ์—๋งŒ ๋ถ™์ผ ์ˆ˜ ์žˆ์Œ*/
            clear: left;
        }


        #list div:nth-child(1) { background-color: tomato;}
        #list div:nth-child(2) { background-color: gold;}
        #list div:nth-child(3) { background-color: cornflowerblue;}
        #list div:nth-child(4) { background-color: greenyellow;}
        #list div:nth-child(5) { background-color: plum;}



    </style>
</head>
<body>
    <!-- ex37_selector.html -->
    <p>Lorem <span>ipsum</span> dolor sit amet consectetur, adipisicing elit. Eaque assumenda eligendi <span>porro</span> rerum consequuntur? Dolor, nihil <span>doloribus</span>. Dolore culpa error cum unde amet voluptas atque libero, eius qui in eveniet!</p>

    <hr>

    <div id="list">
        <div class="item">๋นจ๊ฐ•</div>
        <div class="item">๋…ธ๋ž‘</div>
        <div class="item">ํŒŒ๋ž‘</div>
        <div class="item">์ดˆ๋ก</div>
        <div class="item">๋ณด๋ผ</div>
        <!-- <div style="clear:left;"></div> -->
    </div>

    <div>๋‹ค๋ฅธ ๋‚ด์šฉ๋“ค..</div>

</body>
</html>

'ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ณต๋ถ€ > HTML&CSS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[ex38~] CSS(shadow)  (0) 2023.04.19
[ex33] CSS(box-sizing)  (0) 2023.04.18
[ex25~28] CSS(position, align)  (0) 2023.04.17
[ex24] CSS(์ดˆ๊ธฐ๊ฐ’ ์ดˆ๊ธฐํ™”)  (0) 2023.04.17
[ex21~23] CSS(display, float)  (0) 2023.04.17