๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸŒŒ | WEB DEV/HTML CSS

CSS ๊ฐ€์ƒํด๋ž˜์Šค (1)-2_๋งˆ์šฐ์Šค ์˜ค๋ฒ„ ํšจ๊ณผ(hover, transition) ์ถ”๊ฐ€!

by KASSID 2022. 1. 7.

๋ชฉ์ฐจ

    728x90

    hover์™€ transition์„ ๊ฐ€์ง€๊ณ  ๋†€๋‹ค๊ฐ€

     

    transition์— width์™€ height์˜ ์†๋„๋ฅผ ๋‹ค๋ฅด๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์„ ๋ฐœ๊ฒฌํ–ˆ๋‹ค.

     

    <div class="parent">
        <div class="child"></div>
    </div>

     

    .parent {
        width: 400px;
        height: 200px;
        position: relative;
    }
    .child {
        position: absolute;
        width: 25px;
        height: 25px;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        background-color: blueviolet;
        transition: width 0.95s, height 1s;
    }
    .child:hover {
        width: 100%;
        height: 100%;
        background-color: rgb(216, 179, 250);
        transition: width 1s, height 0.25s;
    }

     

     

    ์œ„์˜ ๊ฒฐ๊ณผ์ฒ˜๋Ÿผ transition์„ ์ ์šฉํ•  ๋•Œ

    width์™€ height๋ฅผ ๋”ฐ๋กœ ์ ์šฉ์‹œ์ผœ์ค„ ์ˆ˜ ์žˆ๋‹ค.

     

    ๋˜ํ•œ hover์ผ ๋•Œ์™€ ์•„๋‹ ๋•Œ๋„ ๋”ฐ๋กœ ์ ์šฉ์„ ํ•ด์ค„ ์ˆ˜ ์žˆ์–ด์„œ

    ์—ญ์‹œ ์›ํ•˜๋Š”๋Œ€๋กœ ์กฐ์ ˆ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

     

     

    transition ์‹œ๊ฐ„์„ ๋ฐ˜๋Œ€๋กœ ์กฐ์ ˆํ–ˆ์„ ๋•Œ๋Š”

    .parent {
        width: 400px;
        height: 200px;
        position: relative;
    }
    .child {
        position: absolute;
        width: 25px;
        height: 25px;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        background-color: blueviolet;
        transition: width 0.95s, height 1s;
    }
    .child:hover {
        width: 100%;
        height: 100%;
        background-color: rgb(216, 179, 250);
        transition: width 0.2s, height 1.2s;
    }

     

    ๋Œ“๊ธ€