λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
🌌 | WEB DEV/HTML CSS

CSS κ°€μƒν΄λž˜μŠ€ (3)_μˆœμ„œ κ°€μƒν΄λž˜μŠ€[2] (first-child, last-child)

by KASSID 2022. 1. 7.

λͺ©μ°¨

    728x90

    μ €λ²ˆμ‹œκ°„μ— μ΄μ–΄μ„œ μˆœμ„œλΆ€μ—¬ κ°€μƒν΄λž˜μŠ€!

    μˆœμ„œλΆ€μ—¬ κ°€μƒν΄λž˜μŠ€λŠ”html에 λ”°λ‘œ 클래슀λ₯Ό λΆ€μ—¬ν•˜μ§€ μ•Šμ•„λ„

    μ›ν•˜λŠ” μš”μ†Œ μ ‘κ·Όν•  수 μžˆλ„λ‘ ν•˜κΈ° μœ„ν•΄μ„œ μ‚¬μš©ν•œλ‹€.

     

    first-child

    ν•΄λ‹Ή μ„ νƒμžμ˜ κ°€μž₯ 첫 번째 μš”μ†Œ

     

    last-child

    ν•΄λ‹Ή μ„ νƒμžμ˜ κ°€μž₯ λ§ˆμ§€λ§‰ μš”μ†Œ

     

    λ‹Ήμ—°ν•˜μ§€λ§Œ nth-child와 달리 μˆœμ„œλ₯Ό λœ»ν•˜λŠ” μˆ«μžλŠ” ν•„μš”ν•˜μ§€ μ•Šλ‹€.

     

     

    μ˜ˆμ‹œ

    <div class="tab-inner">
        <div class="btn">
            <span>곡지사항</span>
            <span>가러리</span>
        </div>
        <div class="tab">
            <a href="#none">2022 신년인사</a>
            <a href="#none">μˆ˜κ°•μ‹ μ²­ 방법 μ•ˆλ‚΄</a>
            <a href="#none">μž₯ν•™κΈˆ μ‹ μ²­κΈ°κ°„ μ•ˆλ‚΄</a>
            <a href="#none">볡학 μ‹ μ²­ μ•ˆλ‚΄</a>
            <a href="#none">동계 λ°©ν•™ 기간쀑 λ„μ„œκ΄€ 운영 μ•ˆλ‚΄</a>
        </div>
    </div>

     

    전체 CSSμ½”λ“œ

    .tab-inner {
        width: 400px;
    }
    .btn span {
        background-color: #ccc;
        display: inline-block;
        width: 120px;
        padding: 5px;
        font-weight: bold;
        text-align: center;
        border-radius: 5px 5px 0 0;
        cursor: pointer;
        border: 2px solid #000;
        margin-right: -7px;
    }
    .btn span:first-child {
        background-color: #fff;
        border-bottom: 2px solid #fff;
        margin-left: 10px;
        margin-bottom: -4px;
    }
    .btn span:last-child {
        border-bottom: 0px solid #fff;
    }
    .tab {
        border: 2px solid #000;
    }
    .tab a{
        display: block;
        text-decoration: none;
        color: #000;
        border-bottom: 2px solid #000;
        padding: 2px;
        margin: 3px 10px 3px 10px;
        transition: 0.4s;
    }
    .tab a:last-child{
        border-bottom: 0;
    }
    .tab a:hover {
        transition: 0s;
        background-color: rgba(136, 153, 247, 0.3);
    }

     

    first-child와 last-childλ₯Ό μ΄μš©ν•˜μ—¬ κ°„λ‹¨ν•œ κ²Œμ‹œνŒ ν˜•νƒœλ₯Ό λ§Œλ“€μ–΄λ³΄μ•˜λ‹€.

     

    λŒ“κΈ€