๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
HTML&CSS

CSS 9์ฐจ์‹œ

by Zใ…ฃ์กด์ˆ˜๋นˆzz 2022. 11. 14.

# Avatar

<h1>Avatar</h1>

    <style>
        .container {
            display: inline-flex;     // flex๋Š” container๋ผ๋ฆฌ ์œ„์•„๋ž˜๋กœ(์ƒํ•˜)๋กœ ์Œ“์ด์ง€๋งŒ inline-flex๋Š” ์ขŒ์šฐ๋กœ ์Œ“์ธ๋‹ค.
            align-items: center;
        }
        img {
            width: 3rem;
            height: 3rem;
            object-fit: cover;     // ์‚ฌ์ง„์˜ ๋น„์œจ์„ ์œ ์ง€ํ•˜๋ฉด์„œ ์ฝ˜ํ…์ธ  ๋ฐ•์Šค๋ฅผ ๊ฐ€๋“ ์ฑ„์šด๋‹ค. ๋น„์œจ์ด ๋งž์ง€ ์•Š์œผ๋ฉด ์ผ๋ถ€๋Š” ์ž˜๋ ค๋‚˜๊ฐ
            border-radius: 50%;     // ๋ชจ์„œ๋ฆฌ ๋‘ฅ๊ธ€๊ฒŒ
        }
        h3 {margin-left: 0.5rem;}
    </style>

    <div class="container">
        <img src="์ด๋ฏธ์ง€ ์ฃผ์†Œ" alt="">
        <h3>bunny</h3>
    </div>


# Thumbnails (opacity)

<style>
        img {
            width: 100px;
            height: 100px;
            object-fit: cover;
            opacity: 0.8;     // ํˆฌ๋ช…๋„ : 0์€ ์™„์ „ํˆฌ๋ช…, 1์€ ์™„์ „ ๋ถˆํˆฌ๋ช…
            cursor: pointer;
            transition: 0.2s;     // ์†์„ฑ๊ฐ’์ด ๋ณ€ํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„
        }
        img:hover {
            opacity: 1;
        }
    </style>

 

<div class="container">
        <img src="์ด๋ฏธ์ง€ ์ฃผ์†Œ" alt="">
        <img src="#" alt="">
        <img src="#" alt="">
    </div>


# Thumbnail (Scalable)

๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ ธ์„ ๋•Œ ํ™•๋Œ€๋˜์–ด ๋‚˜ํƒ€๋‚จ

<h1>Scalcble thumbnails</h1>

    <style>
        .container {
            width: 200px;
            height: 200px;
            overflow: hidden;     // ํ™•๋Œ€๋œ ์ด๋ฏธ์ง€๊ฐ€ ์›๋ž˜์˜ ํฌ๊ธฐ๋ฅผ ๋„˜์œผ๋ฉด ์ž˜๋ผ๋ƒ„
        }
        img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: 0.2s;     // ์†์„ฑ์ด ๋ณ€ํ•˜๋Š” element์— transition์„ ์ ์šฉํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
        }
        .container:hover img{
            transform: scale(1.1, 1.1);     // ํฌ๊ธฐ๊ฐ€ ๊ฐ€๋กœ์ถ•, ์„ธ๋กœ์ถ• 10%์ฆ๊ฐ€
        }
    </style>

    <div class="container">
        <img src="#" alt="">
    </div>


# hoverable Overlay Thumbnails

    <style>
        .container {
            width: 200px;
            height: 200px;
            cursor: pointer;
            position: relative;
        }
        img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .item {
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            background-color: rgba(0 0 0 / 0.5);
            display: flex;
            justify-content: center;
            align-items: center;
            color: #fff;
            opacity: 0;
            transition: 0.2s;     // display: none์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ถ€๋“œ๋Ÿฌ์šด ํšจ๊ณผ๋ฅผ ๋‚ผ ์ˆ˜ ์—†๋‹ค.(์ค‘๊ฐ„๊ฐ’์ด ์žˆ์–ด์•ผ ํ•จ)
        }
        .container:hover .item {
            opacity: 1;
        }
    </style>

    <div class="container">
        <div class="item">&#129414;&#129414;&#129414;</div>
        <img src="#" alt="">
    </div> -->


# Main image

<style>
        .container {
            height: 20rem;
            background-color: #ddd;
            background-image: linear-gradient(to right, #f60, #f00);
            position: relative;
        }
        .item {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;     // item์˜ ํฌ๊ธฐ๋ฅผ width๋‚˜ height์˜ ์ •์˜ ์—†์ด container์— ๋งž์ถค
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>

 

    <div class="container">
        <div class="item">
            <h1>Heading</h1>
        </div>
    </div>


# reponsive image

- ์ด๋ฏธ์ง€๋Š” ๊ฐ€๋กœ, ์„ธ๋กœ ๋‘˜ ์ค‘ ํ•˜๋‚˜๋งŒ ์„ค์ •ํ•ด๋„ ์‚ฌ์ง„ ๋น„์œจ์— ๋งž์ถ”์–ด ์ž๋™์œผ๋กœ ์ถœ๋ ฅ๋œ๋‹ค.

+ ๋น„์œจ์ด ๋‹ค๋ฅธ ์‚ฌ์ง„์„ ๋™์‹œ์— ์ถœ๋ ฅํ•  ๋•Œ

<h1>Q. Responsive</h1>

    <style>
        .container {
            display: flex;
            align-items: flex-start;     // stretch๊ฐ€ ๊ธฐ๋ณธํ˜•์ด๋ฏ€๋กœ
        }
        img {
            width: 50%;
            height: auto;
        }
    </style>

    <div class="container">
        <img src="#" alt="">
        <img src="#" alt="">
    </div>


# ํ”Œ๋ž™์Šค๋ฅผ ํ™œ์šฉํ•œ ๊ทธ๋ฆฌ๋“œ

    <style>
        .container {
            display: flex;      // item 3๊ฐœ๋ฅผ ์ค„๋ฐ”๊ฟˆ์—†์ด ์ผ๋ ฌ๋กœ ๋ฐฐ์—ด
            /* gap: 1rem; */
        }
        .item {
            width: 33.33333%;
        }
        img {
            width: 100%;
            padding: 0.5rem;
            box-sizing: border-box;
        }
    </style>

    <div class="container">
        <div class="item">
            <img src="์ด๋ฏธ์ง€ ์ฃผ์†Œ" alt="">
            <img src="#" alt="">
            <img src="#" alt="">
        </div>
        <div class="item">
            <img src="#" alt="">
            <img src="#" alt="">
            <img src="#" alt="">
        </div>
        <div class="item">
            <img src="#" alt="">
            <img src="#" alt="">
            <img src="#" alt="">
        </div>
    </div>

'HTML&CSS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

CSS 11์ฐจ์‹œ  (0) 2022.11.20
CSS 10์ฐจ์‹œ  (0) 2022.11.16
CSS 8์ฐจ์‹œ  (0) 2022.11.11
CSS 7์ฐจ์‹œ  (0) 2022.11.07
CSS 6์ฐจ์‹œ  (0) 2022.11.06

๋Œ“๊ธ€