CSS - margin,padding / box-sizing / border / background-image

SeomIIIยท2021๋…„ 8์›” 18์ผ
0

FRONTEND

๋ชฉ๋ก ๋ณด๊ธฐ
8/11

๐Ÿ“Œ margin / padding

โœ… margin : ๋ฐ”๊นฅ์ชฝ / padding : ์•ˆ์ชฝ

๐Ÿ”ป float: left; / overflow: hidden;

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            body{
                background-color: #3e3e3e;
            }


            #content{
                width:810px;
                margin:0 auto;
                background-color: #cccccc;
                overflow:hidden;
            }

            #content div{
                width:250px;
                float:left;
                background-color: #ffffff;
                margin:10px;
                border-radius: 10px;
            }

            #content p{
                padding:0 20px;
                font-size:1.5em;
            }
            
            ul li{
                list-style: none;
            }

        </style>
    </head>
    <body>
        <div id="content">
            <div>
                <p>๊ณต์ง€์‚ฌํ•ญ</p>
                <ul>
                    <li>๊ฒŒ์‹œ๋ฌผ_01</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_02</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_03</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_04</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_05</li>
                </ul>
            </div>

            <div>
                <p>๊ณต์ง€์‚ฌํ•ญ</p>
                <ul>
                    <li>๊ฒŒ์‹œ๋ฌผ_01</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_02</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_03</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_04</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_05</li>
                </ul>
            </div>
            <div>
                <p>๊ณต์ง€์‚ฌํ•ญ</p>
                <ul>
                    <li>๊ฒŒ์‹œ๋ฌผ_01</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_02</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_03</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_04</li>
                    <li>๊ฒŒ์‹œ๋ฌผ_05</li>
                </ul>
            </div>
        </div>
    </body>
</html>

๐Ÿ“Œ box-sizing , border

โœ… box-sizing: border-box : border์„ ์•ˆ์ชฝ์œผ๋กœ

โœ… box-sizing: content-box : border์„ ๋ฐ”๊นฅ์ชฝ์œผ๋กœ

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            body{
                margin:0; background-color: gray;
            }

            div{
                width:200px; height:200px;
                margin:10px; padding:10px; border:10px solid orange;
            }

            div:nth-child(1){
                margin:0; border:0; padding:0; background-color: green;
            }

            div:nth-child(2){
                border-style: dashed;
                background-color: orchid;
                /* ์•ˆ์ชฝ์œผ๋กœ */
                box-sizing: border-box;
            }

            div:nth-child(3){
                background-color: blue;
                /* ๋ฐ”๊นฅ์ชฝ์œผ๋กœ */
                box-sizing: content-box;
            }
        </style>
    </head>
    <body>
        <div>200x200</div>
        <div>200x200</div>
        <div>200x200</div>
    </body>
</html><!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            body{
                margin:0; background-color: gray;
            }

            div{
                width:200px; height:200px;
                margin:10px; padding:10px; border:10px solid orange;
            }

            div:nth-child(1){
                margin:0; border:0; padding:0; background-color: green;
            }

            div:nth-child(2){
                border-style: dashed;
                background-color: orchid;
                /* ์•ˆ์ชฝ์œผ๋กœ */
                box-sizing: border-box;
            }

            div:nth-child(3){
                background-color: blue;
                /* ๋ฐ”๊นฅ์ชฝ์œผ๋กœ */
                box-sizing: content-box;
            }
        </style>
    </head>
    <body>
        <div>200x200</div>
        <div>200x200</div>
        <div>200x200</div>
    </body>
</html>

๐Ÿ“Œ background-image

โœ… background-size:50%; background-repeat:no-repeat;

background-attachment:fixed; : ์Šคํฌ๋กค๋ฐ”๋ฅผ ๋‚ด๋ ค๋„ ์ด๋ฏธ์ง€๊ฐ€ ๊ณ ์ •๋œ ์œ„์น˜์— ์žˆ์Œ.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            div:first-child{
                width:80%;
                margin:0 auto; height:400px;
               background-image:url("9.PNG");
               background-size: 100%;
            }
            div:nth-child(2){
                width:80%;
                margin:0 auto; height:400px;
               background-image:url("9.PNG");
               background-size: 50%;
               
            }

            div:nth-child(3){
                width:80%;
                margin:0 auto; height:400px;
               background-image:url("9.PNG");
               background-size: 30%;
               background-attachment: fixed;               
            }

            div:last-child{
                width:80%;
                margin:0 auto; height:400px;
               background-image:url("9.PNG");
               background-size: 50%;
               background-repeat: no-repeat;
            }
        </style>
    </head>
    <body>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </body>
</html>
profile
FE Programmer

0๊ฐœ์˜ ๋Œ“๊ธ€