[CSS] transition/animation/display/border/margin/padding

XIXIยท2022๋…„ 5์›” 15์ผ
0

๋Œ€๊ตฌAI์Šค์ฟจ

๋ชฉ๋ก ๋ณด๊ธฐ
17/57
post-thumbnail

๐ŸŒฑ transition

โœ๏ธ์†๋„ ๊ณก์„ 

<style>
        .box5{
            width: 100px;
            height: 100px;
            background: #0094ff;
            margin: 100px;
        }

        /* ์†๋„ ๊ณก์„  */
        .box5{transition: transform 2s ease-in;}
        .box5:hover{transform: scale(2) perspective(120px) rotateX(180deg);}
</style>
  • transition: transform 2s ease-in โžช ํŠธ๋žœ์ง€์…˜ ๋ณ€ํ˜• 2์ดˆ๋กœ ease in(๋Š๋ฆฌ๊ฒŒ ์‹œ์ž‘)
  • transform: scale(2) perspective(120px) rotateX(180deg) โžช ๋ณ€ํ˜• ํฌ๊ธฐ 2๋ฐฐ๋กœ 3D ์›๊ทผ๊ฐ 120px๋กœ ํšŒ์ „ ๊ฐ๋„๋Š” x์ถ•์œผ๋กœ 180๋„
<body>
    <div class="box5"></div>
</body>

โœ๏ธ์†๋„

<style>
        #graph{
            width: 610px;
            border: 3px solid black;
        }

        .bar{
            width: 10px;
            height: 50px;
            background-color: orange;
            margin: 5px;
        }

        #graph:hover .bar{
            width: 600px;
            /* transition-property: width, background-color;
            transition-duration: 5s, 5s; */
            transition: all 5s ease;
        }

        /* ์†๋„ */
        .bar:nth-child(1){
            background-color: red;
            transition-timing-function: linear;
        }
        .bar:nth-child(2){ 
            background-color: blue;
            transition-timing-function: ease;
        }
        .bar:nth-child(3){
            background-color: green;
            transition-timing-function: ease-in;
        }
        .bar:nth-child(4){
            background-color: yellow;
            transition-timing-function: ease-out;
        }
        .bar:nth-child(5){
            background-color: pink;
            transition-timing-function: ease-in-out;
        }
</style>
  • transition: all 5s ease โžช ํŠธ๋žœ์ง€์…˜ ํ”„๋กœํผํ‹ฐ ์ „๋ถ€ 5์ดˆ ease(์ฒœ์ฒœํžˆ ์‹œ์ž‘ ๋นจ๋ผ์ง€๋‹ค ์ฒœ์ฒœํžˆ ๋)
  • transition-timing-function โžช ํŠธ๋žœ์ง€์…˜ ์†๋„ ๊ณก์„ 
  • linear โžช ์‹œ์ž‘๋ถ€ํ„ฐ ๋๊นŒ์ง€ ๊ฐ™์€ ์†๋„๋กœ ์ง„ํ–‰
  • ease โžช ์ฒœ์ฒœํžˆ ์‹œ์ž‘>์ ์  ๋นจ๋ผ์ง>์ฒœ์ฒœํžˆ ๋
  • ease-in โžช ๋Š๋ฆฌ๊ฒŒ ์‹œ์ž‘
  • ease-out โžช ๋Š๋ฆฌ๊ฒŒ ๋
  • ease-in-out โžช ๋Š๋ฆฌ๊ฒŒ ์‹œ์ž‘>๋Š๋ฆฌ๊ฒŒ ๋
  • cubic-Bezier(n, n, n, n) โžช ํ•จ์ˆ˜ ์ง์ ‘ ์ •์˜ํ•ด์„œ ์‚ฌ์šฉ
<body>
    <div id="graph">
        <div class="bar"></div>
        <div class="bar"></div>
        <div class="bar"></div>
        <div class="bar"></div>
        <div class="bar"></div>
    </div>
</body>

โœ๏ธanimation

<style>
        div{
            width: 100px;
            height: 100px;
            border: 1px solid black;
            margin: 50px;
        }

        #box{
            /* background-color: blue;
            animation-name: chang-bg;
            animation-duration: 3s;
            animation-iteration-count: 3;
            animation-direction: alternate;
            animation-timing-function: ease-in-out; */

            animation: chang-bg 3s 1s infinite alternate ease-in-out;
        }

        @keyframes chang-bg {
            from{background-color: blue;}
            50%{background-color: violet;}
            to{
                background-color: yellow;
                border-radius: 50%;
            }
        }
</style>
  • animation-name: chang-bg โžช ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ด๋ฆ„์€ chang-bg
  • animation-duration: โžช ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ง€์† ์‹œ๊ฐ„
  • animation-iteration-count โžช ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋ฐ˜๋ณต ํšŸ์ˆ˜
  • animation-direction: alternate โžช ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋ฐฉํ–ฅ: ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์•ž์œผ๋กœ ์žฌ์ƒ๋œ ๋‹ค์Œ ๋’ค๋กœ ์žฌ์ƒ

animation
์• ๋‹ˆ๋ฉ”์ด์…˜ ์ด๋ฆ„ | ์ง€์† ์‹œ๊ฐ„ | ๋ฐ˜๋ณต ํšŸ์ˆ˜ | ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋ฐฉํ–ฅ | ์†๋„ ๊ณก์„ 

  • @keyframes โžช ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ค‘๊ฐ„ ์ƒํƒœ ๊ธฐ์ˆ 
  • from{background-color: blue;} โžช ์‹œ์ž‘์€~ ๋ฐฐ๊ฒฝ์ƒ‰ ํŒŒ๋ž‘
  • 50%{background-color: violet;} โžช 50%์ง€์ ๋ถ€ํ„ฐ~ ๋ฐฐ๊ฒฝ์ƒ‰ ๋ณด๋ผ์ƒ‰
  • to{background-color: yellow; border-radius: 50%;} โžช ~๋กœ ๋ฐฐ๊ฒฝ์ƒ‰ ๋…ธ๋ž€์ƒ‰, ๋ชจ์„œ๋ฆฌ ๋‘ฅ๊ธ€๊ฒŒ 50%
<body>
    <div id="box"></div>
</body>

โœ๏ธbox-size

<style>
        .box1{
            width: 400px;
            height: 100px;
            padding: 10px;
            border: 1px solid black;
            background-color: #ff6a00;
        }

        .box2{
            width: 50%;
            height: 100px;
            padding: 10px;
            border: 1px solid black;
            background-color: #006eff;
        }
</style>

width ๋‹จ์œ„๋ฅผ px๋ฅผ ์“ฐ๋Š”์ง€, %๋ฅผ ์“ฐ๋Š”์ง€์— ๋”ฐ๋ผ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค๋ฅด๊ฒŒ ๋‚˜ํƒ€๋‚จ. %๋Š” ํ™”๋ฉด ๋น„์œจ์— ๋”ฐ๋ฅธ ๋น„์œจ๋กœ ๋ณ€๊ฒฝ๋˜์–ด ํ‘œํ˜„. px์€ ์ˆ˜์น˜ ๊ณ ์ •์œผ๋กœ ํ‘œํ˜„.

<body>
    <div class="box1"></div>
    <div class="box2"></div>
</body>

โœ๏ธdisplay

inline
์ฝ˜ํ…์ธ  ๋‚˜์—ด ์ˆ˜ํ‰ ์ง„ํ–‰. ์ฝ˜ํ…์ธ  ์˜์—ญ์„ ์ •์˜.

  • width/height ์ ์šฉ ๋ถˆ๊ฐ€
  • margin/padding-top/bottom ์ ์šฉ ๋ถˆ๊ฐ€
  • line-height ์›ํ•˜๋Š” ๋Œ€๋กœ ์ ์šฉ ๋ถˆ๊ฐ€(span์— ์ ์šฉ์•ˆ๋˜๊ณ  ๊ฐ์‹ธ๊ณ  ์žˆ๋Š” div ์ „์ฒด ํฌ๊ธฐ์—๋งŒ ์˜ํ–ฅ)

block
์ฝ˜ํ…์ธ  ๋‚˜์—ด ์ˆ˜์ง ์ง„ํ–‰. ๋ฐ•์Šคํ˜•ํƒœ๋กœ ์ฝ˜ํ…์ธ ๊ฐ€ ์œ„์น˜๋œ ์˜์—ญ ํ•œ ์ค„์„ ์ฐจ์ง€ํ•˜๋Š” ์˜์—ญ ์ •์˜.

inline-block
์ฝ˜ํ…์ธ  ๋‚˜์—ด ์ˆ˜ํ‰ ์ง„ํ–‰.

  • width/height ์ ์šฉ ๊ฐ€๋Šฅ
  • margin/padding-top/bottom ์ ์šฉ ๊ฐ€๋Šฅ
  • line-height ์ ์šฉ ๊ฐ€๋Šฅ

โœ๏ธdisplay

<style>
        div{
            margin: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

        img{width: 300px;}

        .visible{visibility: visible;}

        /* ํ™”๋ฉด์— ๋ณด์ด์ง€ ์•Š๊ณ  ๊ณต๊ฐ„๋„ ์ฐจ์ง€ํ•˜์ง€ ์•Š์Œ */
        .none{display: none; }

        /* ๊ณต๊ฐ„์€ ์ฐจ์ง€ํ•˜์ง€๋งŒ ๋‚ด์šฉ์€ ์•ˆ ๋ณด์—ฌ์คŒ */
        .hidden{visibility: hidden;}
</style>
  • display: none โžช ๊ณต๊ฐ„ ์ฐจ์ง€ ์—†์ด ํ™”๋ฉด์— ์•ˆ ๋ณด์ž„.
  • visibility: hidden โžช ๊ณต๊ฐ„ ์ฐจ์ง€ ํ•˜์ง€๋งŒ ๋‚ด์šฉ์€ ์•ˆ ๋ณด์ž„.
<body>
    <div>
        <img class="visible" src="./์„ ์ƒ๋‹˜ ์ž๋ฃŒ/์‹ค์Šต/de1.jpg">
        <img class="none" src="./์„ ์ƒ๋‹˜ ์ž๋ฃŒ/์‹ค์Šต/de2.jpg">
        <img class="visible" src="./์„ ์ƒ๋‹˜ ์ž๋ฃŒ/์‹ค์Šต/de3.jpg">
    </div>  
    
    <div>
        <img class="visible" src="./์„ ์ƒ๋‹˜ ์ž๋ฃŒ/์‹ค์Šต/de1.jpg">
        <img class="hidden"src="./์„ ์ƒ๋‹˜ ์ž๋ฃŒ/์‹ค์Šต/de2.jpg">
        <img class="visible" src="./์„ ์ƒ๋‹˜ ์ž๋ฃŒ/์‹ค์Šต/de3.jpg">
    </div>
</body>

display

โœ๏ธborder

<style>
		div {
			width:200px;
			height:100px;
			display:inline-block;
			margin:15px;			
			border-width:10px;  /* 2. ํ…Œ๋‘๋ฆฌ ๊ตต๊ธฐ : ์‚ฌ๋ฐฉ ๊ฐ™์€ ๊ฐ’, ๋‹ค๋ฅธ ๊ฐ’, ํ‚ค์›Œ๋“œ(thin, medium, thick) */
            border-top-color:aquamarine; /* 3. ์ƒ‰๊น”: ์‚ฌ๋ฐฉ ๊ฐ™์€ ๊ฐ’(border-color), ๋‹ค๋ฅธ ๊ฐ’(top, right, bottom, left ),*/
            /* 4. ์†์„ฑ ๋ฌถ์–ด ํ‘œํ˜„ ๊ฐ€๋Šฅ, ์ˆœ์„œ ์ƒ๊ด€ ์—†์Œ */
		}
       
		/* 1. ์„  ํ˜•ํƒœ */        
		.box1 {border-style:solid;}  /* ์‹ค์„  */
		.box2 {border-style:dotted;}  /* ์ ์„  */
		.box3 {border-style:dashed;}  /* ์„ ์œผ๋กœ ๋œ ์ ์„  */
        .box4 {border-style: double;}
        .box5 {border-style: groove;}
        .box6 {border-style: inset;}
        .box7 {border-style: outset;}
        .box8 {border-style: ridge;}
</style>
  • border-width โžช ์„  ๊ตต๊ธฐ
  • border-top-color โžช ์„  ์ƒ๋‹จ ์ƒ‰์ƒ
<body>
	<div class="box1">solid </div>
	<div class="box2">dotted </div>
	<div class="box3">dashed </div>
	<div class="box4">double </div>
	<div class="box5">groove </div>
	<div class="box6">inset </div>
	<div class="box7">outset </div>
	<div class="box8">ridge </div>
</body>

border

โœ๏ธborder-radius

<style>
		div {
			width: 300px; /* ๋„ˆ๋น„ */
			height: 200px; /* ๋†’์ด */
			margin: 20px; /* ์˜์—ญ๊ฐ„ ๋งˆ์ง„ */
			display: inline-block; /* ๊ฐ€๋กœ๋กœ ๋ฐฐ์น˜ */
			border:5px solid cadetblue; /* 2px์งœ๋ฆฌ ๋นจ๊ฐ• ์‹ค์„  */
		}
		.round {/* ์‚ฌ๋ฐฉ ๋™์ผ */			
			border-radius:20px;  /* ๋ชจ์„œ๋ฆฌ 20px ๋งŒํผ ๋ผ์šด๋”ฉ */
		}
		.round-top{/* ์œ„์ชฝ๋งŒ */			
			border-top-left-radius:20px;  
			border-top-right-radius:20px;  
		}
		.round-four {/* ์‚ฌ๋ฐฉ ๋‹ค๋ฅด๊ฒŒ */
			border-radius:70px 20px;  
		}

		/* ๋ชจ์„œ๋ฆฌ๋ฅผ ํƒ€์›์ฒ˜๋Ÿผ */		
		.round1 {border-top-left-radius:100px 50px;} /* ์™ผ์ชฝ ์œ„ ๋ผ์šด๋”ฉ */
		.round2 {border-bottom-right-radius:50% 30%;}
</style>
  • border-radius โžช ํ…Œ๋‘๋ฆฌ ๋‘ฅ๊ธ€๊ฒŒ
<body>
	<div class="round bg"></div>
	<div class="round-top bg"></div>
	<div class="round-four bg"></div>
	<br>
	<div class="round1"></div>
	<div class="round2"></div>
</body>

border-radius

โœ๏ธmargin-overlap

<style>
    * {
      box-sizing:border-box;
    }
		div {
			width:200px;  /* ๋„ˆ๋น„ */
			height:100px;  /* ๋†’์ด */
  		    margin:30px;  /* ๋งˆ์ง„ */
		}
    #box1 {
      background:rgb(0, 77, 243);
    }
    #box2 {
      background:rgb(255, 72, 0);
    }
    #box3 {
      background:rgb(18, 219, 0);
    }
</style>

margin-overlap
์š”์†Œ๋ฅผ ์„ธ๋กœ๋กœ ๋ฐฐ์น˜์‹œ ๋งˆ์ง„๊ณผ ๋งˆ์ง„์ด ๋งŒ๋‚˜๋ฉด ๋งˆ์ง„ ๊ฐ’์ด ํฐ ์ชฝ์œผ๋กœ ๊ฒน์ณ์ง€๋Š” ๊ฒƒ
-> ์—ฌ๋Ÿฌ ์š”์†Œ๋ฅผ ์„ธ๋กœ๋กœ ๋ฐฐ์น˜ํ•  ๋•Œ ๋งˆ์ง„์ด ๋„ˆ๋ฌด ์ปค์ง€๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ. ์œ„ํ•œ ๊ฒƒ ์œ„, ์•„๋ž˜ ๋งˆ์ง„์€ ํฐ ๊ฐ’์œผ๋กœ ํ•ฉ์ณ์ง€๊ณ 
์˜ค๋ฅธ์ชฝ ์™ผ์ชฝ ๋งˆ์ง„์€ ๋งŒ๋‚˜๋„ ์ค‘์ฒฉ๋˜์ง€ ์•Š๋Š”๋‹ค

<body>
	<div id="box1"></div>
	<div id="box2"></div>
	<div id="box3"></div>
</body>

margin-overlap

โœ๏ธpadding

ํŒจ๋”ฉ(padding)์ด๋ž€ ์ฝ˜ํ…์ธ  ์˜์—ญ๊ณผ ํ…Œ๋‘๋ฆฌ ์‚ฌ์ด์˜ ์—ฌ๋ฐฑ.

profile
Life is experience:)

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