Notice
Recent Posts
Recent Comments
Link
ยซ   2025/07   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

POTATO THAT WANT TO BE HUMAN

[CSS] background-clip๊ณผ background-origin ๋ณธ๋ฌธ

์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

[CSS] background-clip๊ณผ background-origin

๋…œํž 2022. 5. 5. 22:32
๋ฐ˜์‘ํ˜•

๐Ÿค” background-clip

background-clip ์€ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋‚˜ ๋ฐฐ๊ฒฝ์ƒ‰์„ ๊ทธ ๋ฐ•์Šค ์ค‘ ์–ด๋””์— ๋„ฃ์„์ง€ ์ •ํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค. 

๊ธฐ๋ณธ๊ฐ’์€ border-box ์ด๋ฉฐ ํ…Œ๋‘๋ฆฌ ์˜์—ญ๊ณผ ๊ทธ ์•ˆ์ชฝ ์˜์—ญ์„ ์ฑ„์›๋‹ˆ๋‹ค.

 

  • border-box : ํ…Œ๋‘๋ฆฌ ์˜์—ญ๊ณผ ๊ทธ ์•ˆ์ชฝ ์˜์—ญ์„ ์ฑ„์›๋‹ˆ๋‹ค.
  • padding-box : ์•ˆ์ชฝ ์—ฌ๋ฐฑ ์˜์—ญ๊ณผ ๊ทธ ์•ˆ์ชฝ ์˜์—ญ์„ ์ฑ„์›๋‹ˆ๋‹ค.
  • content-box : ๋‚ด์šฉ ์˜์—ญ๊ณผ ๊ทธ ์•ˆ์ชฝ ์˜์—ญ์„ ์ฑ„์›๋‹ˆ๋‹ค.
  • initial : ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
  • inherit : ๋ถ€๋ชจ ์š”์†Œ์˜ ์†์„ฑ๊ฐ’์„ ์ƒ์†๋ฐ›์Šต๋‹ˆ๋‹ค.

 

์˜ˆ์ œ๋ฅผ ํ†ตํ•ด ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 

<head>
    <meta charset="UTF-8">
    <title>background-clip</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            margin: 20px 0;
            border: 5px dotted rgb(255, 101, 127);
            background-color: #eee;
            line-height: 200px;
            text-align: center;
            font-weight: 700;
        }
        .a {
            background-clip: border-box;
        }
        .b {
            background-clip: padding-box;
        }
        .c {
            background-clip: content-box;
        }
    </style>
</head>
<body>
    <div class="a">border-box</div>
    <div class="b">padding-box</div>
    <div class="c">content-box</div>
</body>

 

 

๐Ÿค” background-origin

background-origin ์€ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ์–ด๋А ์˜์—ญ๋ถ€ํ„ฐ ์ฑ„์›Œ๋‚˜๊ฐˆ์ง€๋ฅผ ์ •ํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค.

๊ธฐ๋ณธ๊ฐ’์€ padding-box ๋กœ ์•ˆ์ชฝ ์—ฌ๋ฐฑ ์˜์—ญ ์™ผ์ชฝ ์œ„๋ถ€ํ„ฐ ์ฑ„์›๋‹ˆ๋‹ค.

 

  • border-box : ํ…Œ๋‘๋ฆฌ ์˜์—ญ ์™ผ์ชฝ ์œ„๋ถ€ํ„ฐ ์ฑ„์›๋‹ˆ๋‹ค.
  • padding-box : ์•ˆ์ชฝ ์—ฌ๋ฐฑ ์˜์—ญ ์™ผ์ชฝ ์œ„๋ถ€ํ„ฐ ์ฑ„์›๋‹ˆ๋‹ค.
  • content-box : ๋‚ด์šฉ ์˜์—ญ ์™ผ์ชฝ ์œ„๋ถ€ํ„ฐ ์ฑ„์›๋‹ˆ๋‹ค.
  • initial : ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
  • inherit : ๋ถ€๋ชจ ์š”์†Œ์˜ ์†์„ฑ๊ฐ’์„ ์ƒ์†๋ฐ›์Šต๋‹ˆ๋‹ค.

 

์˜ˆ์ œ๋ฅผ ํ†ตํ•ด ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

<head>
    <meta charset="UTF-8">
    <title>background-origin</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            margin: 20px 0;
            padding: 30px;
            border: 5px dotted rgb(223, 38, 69);
            background-image: url('img/sky.jpg');
            background-repeat: no-repeat;
            line-height: 200px;
            text-align: center;
            font-weight: 700;
            color: #fff;
        }
        .a {
            background-origin: border-box;
        }
        .b {
            background-origin: padding-box;
        }
        .c {
            background-origin: content-box;
        }
    </style>
</head>
<body>
    <div class="a">border-box</div>
    <div class="b">padding-box</div>
    <div class="c">content-box</div>
</body>

 

๋‘๋ฒˆ์งธ ์˜ˆ์ œ๋ฅผ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

background-origin ์†์„ฑ๊ฐ’์— ๊ด€๊ณ„์—†์ด ๋ฐฐ๊ฒฝ์ด๋ฏธ์ง€๋ฅผ ๋ฐ˜๋ณต์‹œํ‚ค๋ฉด ํ…Œ๋‘๋ฆฌ ์˜์—ญ๊ณผ ๊ทธ ์•ˆ์ชฝ ์˜์—ญ์„ ๋‹ค ์ฑ„์šฐ๊ณ , ์ฑ„์šฐ๊ธฐ ์‹œ์ž‘ํ•˜๋Š” ์œ„์น˜๋งŒ ๋‹ฌ๋ผ์ง‘๋‹ˆ๋‹ค.

์œ„ ์˜ˆ์ œ์—์„œ background-repeat: no-repeat; ์„ ์‚ญ์ œํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

<head>
    <meta charset="UTF-8">
    <title>background-origin</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            margin: 20px 0;
            padding: 30px;
            border: 5px dotted rgb(223, 38, 69);
            background-image: url('img/sky.jpg');
            background-size: 90px;
            /* background-repeat: no-repeat; */
            line-height: 200px;
            text-align: center;
            font-weight: 700;
            color: #fff;
        }
        .a {
            background-origin: border-box;
        }
        .b {
            background-origin: padding-box;
        }
        .c {
            background-origin: content-box;
        }
    </style>
</head>
<body>
    <div class="a">border-box</div>
    <div class="b">padding-box</div>
    <div class="c">content-box</div>
</body>

๋ฐ˜์‘ํ˜•
Comments