[๐Ÿ’ป ์ฝ”๋“œ์Šคํ…Œ์ด์ธ  FE 44๊ธฐ] ๋ถ€ํŠธ์บ ํ”„ - ๊ณ„์‚ฐ๊ธฐ ๋ชฉ์—… ๋งŒ๋“ค๊ธฐ(๋งˆ๋ฌด๋ฆฌ)

JiEunยท2023๋…„ 2์›” 17์ผ
0
post-thumbnail

โœ”๏ธ ์‹œ์ž‘

๊ณ„์‚ฐ๊ธฐ ๋ชฉ์—… ๋งŒ๋“ค๊ธฐ๋ฅผ ๋งˆ๋ฌด๋ฆฌํ–ˆ๋‹ค.
์‹ค๋ ฅ์žˆ๋Š” ๋ถ„๋“ค์ด ๋งŽ์œผ์…”์„œ ์–ด๋–ป๊ฒŒ ํ•˜๋ฉด ๋‚ด ๊ณ„์‚ฐ๊ธฐ์— ์ฐจ๋ณ„์ ์„ ์ค„ ์ˆ˜ ์žˆ์„๊นŒ?๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉฐ ์ž‘์—…์„ ๋งˆ๋ฌด๋ฆฌํ•œ ๊ฑฐ ๊ฐ™๋‹ค.
์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ์™€ ๋ฐ˜์‘ํ˜•์„ ์ถ”๊ฐ€ํ•ด ์ œ์ถœํ–ˆ๋‹ค.


๐Ÿ“ ๊ณ„์‚ฐ๊ธฐ ๋ชฉ์—… ๋งŒ๋“ค๊ธฐ

๐Ÿ’ป HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>๊ณ„์‚ฐ๊ธฐ ๋ชฉ์—…</title>
  <link rel="stylesheet" href="./style.css">
</head>
<body>
  <section id="container">
    <div class="calculator">
      <!--๊ฒฐ๊ณผ ํ™”๋ฉด-->
      <div class="result-display">
        <span class="procedure">500 + 50</span>
        <p class="result">500 </p>
      </div>
       <!--buttons-->
      <div class="buttons">
        <div class="btn-row">
          <button class="operator sm-font">AC</button>
          <button class="operator">ยฑ</button>
          <button class="operator sm-font">%</button>
          <button class="operator">รท</button>
        </div>
        <div class="btn-row">
          <button class="num">7</button>
          <button class="num">8</button>
          <button class="num">9</button>
          <button class="operator">ร—</button>
        </div>
        <div class="btn-row">
          <button class="num">4</button>
          <button class="num">5</button>
          <button class="num">6</button>
          <button class="operator">-</button>
        </div>
        <div class="btn-row">
          <button class="num">1</button>
          <button class="num">2</button>
          <button class="num">3</button>
          <button class="operator">+</button>
        </div>
        <div class="btn-row">
          <button class="num">0</button>
          <button class="num">.</button>
          <button class="btn-result">=</button>
        </div>
      </div>
    </div>
  </section>
</body>
</html>

โœ”๏ธ ์ข…์ด์— ๊ทธ๋ฆฌ๋ฉด์„œ ์ปจํ…์ธ ๋ฅผ ์–ด๋–ป๊ฒŒ ๋‚˜๋ˆŒ์ง€ ๊ตฌ์ƒํ–ˆ๋‹ค.
โœ”๏ธ id, class ์ด๋ฆ„ ์„ค์ •์„ ์ž˜ํ•ด์•ผํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.
โœ”๏ธ div๋ฅผ ๋งŽ์ด ์“ฐ๊ณ  ์‹ถ์ง€ ์•Š์•„์„œ ์ƒํ™ฉ์— ๋งž๋Š” ํƒœ๊ทธ๋ฅผ ์ž‘์„ฑํ–ˆ๋‹ค.(์‹œ๋ฉ˜ํ‹ฑ์€ ์ƒ๊ฐ ๋ณด๋‹ค ์–ด๋ ต๋‹ค..)

๐Ÿ’ป CSS

@font-face {
    font-family: 'GmarketSans';
    font-weight: 300;
    font-style: normal;
    src: url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansLight.eot');
    src: url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansLight.eot?#iefix') format('embedded-opentype'),
         url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansLight.woff2') format('woff2'),
         url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansLight.woff') format('woff'),
         url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansLight.ttf') format("truetype");
    font-display: swap;
} 
@font-face {
    font-family: 'GmarketSans';
    font-weight: 500;
    font-style: normal;
    src: url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansMedium.eot');
    src: url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansMedium.eot?#iefix') format('embedded-opentype'),
         url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansMedium.woff2') format('woff2'),
         url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansMedium.woff') format('woff'),
         url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansMedium.ttf') format("truetype");
    font-display: swap;
} 
@font-face {
    font-family: 'GmarketSans';
    font-weight: 700;
    font-style: normal;
    src: url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansBold.eot');
    src: url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansBold.eot?#iefix') format('embedded-opentype'),
         url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansBold.woff2') format('woff2'),
         url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansBold.woff') format('woff'),
         url('https://cdn.jsdelivr.net/gh/webfontworld/gmarket/GmarketSansBold.ttf') format("truetype");
    font-display: swap;
} 
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0px;
    font-family: 'GmarketSans',sans-serif;
    font-size: 16px;
}
body {
    margin: 0;
    padding: 0;
    background-image: linear-gradient(315deg, #060047, #3A328C); 
}
button {
    cursor: pointer;
}
#container {
    display: flex;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}
.calculator {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 393px;
    height: 698px;
    background-color: #150E60 ;
    border-radius: 30px;   
    padding: 40px;
    box-shadow: 8px 8px 50px 0 rgba(5, 0, 69, 0.8),inset 2px 2px 0 0 #3A328C, inset -2px -2px 0 0 #120c57;
    transition: 0.3s;
    animation-play-state: paused;
}
.calculator:hover {
    animation: line-st ease-in 3s infinite;
}
@keyframes line-st {
    0%{
        box-shadow: 5px 5px 40px 0 rgba(5, 0, 69, 0.8),inset 2px 2px 0 0 #3A328C, inset -2px -2px 0 0 #0e0752;
    }
    25%{
        box-shadow: 5px 5px 40px 0 rgba(5, 0, 69, 0.8),inset -2px 2px 0 0 #3A328C, inset -2px 2px 0 0 #0e0752;
    }
    65%{
        box-shadow: 5px 5px 40px 0 rgba(5, 0, 69, 0.8),inset 2px -2px 0 0 #3A328C, inset 2px -2px 0 0 #0e0752;
    }
    100%{
        box-shadow: 5px 5px 40px 0 rgba(5, 0, 69, 0.8),inset 2px 2px 0 0 #3A328C, inset -2px -2px 0 0 #0e0752;
    }
}
.result-display, .buttons {
    width: 100%;
}
.result-display {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;
    flex-grow: 1;
    padding-bottom: 30px;
    margin-bottom: 30px;
    border-bottom: 2px solid #3A328C;
}
.result-display .procedure {
    color: #3A328C;
    font-size: 1.15rem;
    padding-bottom: 10px;
}
.result-display .result {
    color: #fff;
    font-size: 2.5rem;
    font-weight: 700;
}
.buttons {
    flex-grow: 3;
    display: flex;
    flex-direction: column;
}
.buttons .btn-row {
    display: flex;
    flex-grow: 1;
    align-items: center;
    gap: 8px;
}
.buttons .btn-row button {
    position: relative;
    flex: 1 70px;
    height: 75px;
    line-height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-size: 1.5rem;
    transition: 0.3s;
    z-index: 1;
    overflow: hidden;
}
.buttons .btn-row button::after{
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    border-radius: 100px;
    transition: 0.3s;
    z-index: -1;
    transform: scale(0);
}
.buttons .btn-row button:hover {
    box-shadow: 0px 10px 20px 0 rgba(5, 0, 69, 0.8);
    transform: translateY(-3px);
}
.buttons .btn-row button:hover::after {
    background-color: rgba(0, 0, 0, 0.11);
    transform: scale(1);
}
.buttons .btn-row button:active {
    border: 2px solid #ffffff08;
    box-shadow: inset 3px 3px 0 0 rgba(0,0,0, 0.3);
    box-shadow: none;
    transform: translateY(0);
}
.buttons .btn-row  .operator { 
 background-color: #3A328C;
}
.buttons .btn-row .num {
    background-color: #060147;
}
.buttons .btn-row  .sm-font {
    font-size: 1rem;
}
.buttons .btn-row:last-child .btn-result { 
    flex-grow: 100;
    border-radius: 50px;
    background-color: #DC005E;
}

@media (max-width:768px) {
    .calculator {
        width: 100%;
        height: 100vh;
        border-radius: 0;
        box-shadow: none;
    }
    .calculator:hover {
        animation-play-state: paused;
        animation: none;
        box-shadow: none;
    }
    .result-display {
        border-bottom: 0;
        margin-bottom: 0;
    }
    .result-display .result {
        font-size: 3.1rem;
    }
    .buttons .btn-row button {
        flex: 1;
        height: 100%;
        border-radius: 0%;
    }
    .buttons .btn-row {
        gap: 0;
    }
    .buttons .btn-row:last-child .btn-result {
        border-radius: 0;
        flex-grow: 0.665;
    }
    .buttons .btn-row button:hover {
        box-shadow: 0;
        transform: translateY(0);
        box-shadow: 0 0 0 0;
    }
    .buttons .btn-row button:hover::after {
        transform: scale(1);
        border-radius: 0;
    }
    .buttons .btn-row button:active {
        transform: translateY(1px);
        border: 0;
        box-shadow: inset 3px 3px 5px 0 rgba(0,0,0, 0.1),inset -3px -3px 5px 0 rgba(0,0,0, 0.1);
    }   
}

โœ”๏ธ ๋‹จ์ƒ‰ ๋ฐฐ๊ฒฝ ๋Œ€์‹  ๊ทธ๋ผ๋ฐ์ด์…˜์„ ๋„ฃ์–ด์ฃผ์—ˆ๋‹ค.
โœ”๏ธ ๊ณ„์‚ฐ๊ธฐ ํ…Œ๋‘๋ฆฌ๋ฅผ ๊ทธ๋ผ๋ฐ์ด์…˜์œผ๋กœ ์ฃผ๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ ์ดํ›„ padding์š”์†Œ ์ถ”๊ฐ€์‹œ ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด box-shadow๋กœ ๋ณ€๊ฒฝํ•ด ์ฃผ์—ˆ๋‹ค.
โœ”๏ธ ๊ณ„์‚ฐ๊ธฐ์— ๋งˆ์šฐ์Šค hover ๋  ๊ฒฝ์šฐ ํ…Œ๋‘๋ฆฌ์— animation์š”์†Œ๋ฅผ ๋„ฃ์–ด์ฃผ์—ˆ๋‹ค.
โœ”๏ธ @media์ฟผ๋ฆฌ๋ฅผ ์ด์šฉํ•ด ๋ฐ˜์‘ํ˜•์œผ๋กœ ์ž‘์—…ํ–ˆ๋‹ค.

โœ”๏ธ ๋ฐ˜์‘ํ˜• ์ž‘์—…ํ•˜๋ฉด์„œ ๋ฒ„ํŠผ์„ ๋‘ฅ๊ธ€๊ฒŒ ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ ์ƒ๊ฐ๋ณด๋‹ค ์–ด๋ ค์›Œ ๋„ค๋ชจ๋‚˜๊ฒŒ ์ˆ˜์ •ํ–ˆ๋‹ค. (๋‹ค์Œ์— ๋‹ค์‹œ ์ˆ˜์ •ํ•ด ๋ณด์ž.)

๐Ÿ“ ์™„์„ฑ๋ฌผ


gif๋กœ ๋ณ€ํ™˜ํ–ˆ๋Š”๋ฐ ๋ฒ„๋ฒ…๊ฑฐ๋ ค์„œ ์•„์‰ฝ๋‹ค.ใ… 


โœ๏ธ ๋งˆ์น˜๋ฉฐ

์ด๋ฒˆ ์ฒซ ํŽ˜์–ด ํ™œ๋™์„ ํ†ตํ•ด ๊ฐ์ž ๋งŒ๋“  ๊ณ„์‚ฐ๊ธฐ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•˜๋Š” ์‹œ๊ฐ„์„ ๊ฐ€์กŒ๋‹ค. ๋˜ํ•œ ์„œ๋กœ ๊ถ๊ธˆํ•œ๊ฒŒ ์žˆ์œผ๋ฉด ์–ด๋–ป๊ฒŒ ์ž‘์—…ํ–ˆ๋Š”์ง€๋„ ์„ค๋ช… ํ•˜๋ฉด์„œ ์„œ๋กœ ์ •๋ณด๋ฅผ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

๋‹คํ–‰์ด๋„ ํŽ˜์–ด๋ถ„๋„ ์นœ์ ˆํ•˜์…จ๊ณ  ์นญ์ฐฌ์„ ์•„๋‚Œ์—†์ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•  ๋”ฐ๋ฆ„์ด์˜€๋‹ค.
ํŽ˜์–ด๋ถ„๊ป˜ ๋„์›€์ด ๋˜๊ณ ์ž ๋„์™€๋“œ๋ฆด๊ฑฐ ์—†๋Š”์ง€ ๋ฌผ์–ด๋ณด๊ธฐ๋„ ํ•˜๊ณ  ์ž๋ฃŒ๋„ ๊ณต์œ ํ–ˆ๋˜๊ฑฐ ๊ฐ™๋‹ค. ํŽ˜์–ด๋ถ„๊ป˜์„œ ๊ธ์ •์ ์œผ๋กœ ๋ด์ฃผ์‹œ๊ธฐ๋„ ํ–ˆ๊ณ  ๋„์›€์ด ๋˜์„œ ๋‹คํ–‰์ด๋‹ค.

์ดํ›„ ํŽ˜์–ด ํ™œ๋™์„ ํ†ตํ•ด์„œ๋„ ์ข‹์€ ์˜ํ–ฅ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์„๊ฑธ๋กœ ์˜ˆ์ƒ๋œ๋‹ค.

๊ณ„์‚ฐ๊ธฐ ๋ชฉ์—…์„ ๋งŒ๋“œ๋ฉด์„œ ๋‹ค๋ฅธ ์ˆ˜๊ฐ•์ƒ๋ถ„๋“ค์˜ ๊ณผ์ œ๋ฌผ์— ๋น„ํ•ด ๋‚ด๊ฐ€ ๋งŒ๋“ ๊ฑด ๋ญ”๊ฐ€ ํ‹€์— ๋ฐ•ํ˜€ ์žˆ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๋‹ค.๋‹ค์Œ์—” ๋‚˜์˜ ๊ฐœ์„ฑ์„ ์‚ด๋ ค ๋งŒ๋“ค์–ด ๋ณด์ž.

CSS์—์„œ ๋ณ€์ˆ˜๋ฅผ ์ด์šฉํ•ด ๋‹คํฌ๋ชจ๋“œ ์ž‘์—…์„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ดํ›„ ๊ณผ์ œ๋ฌผ์€ ํ•ด๋‹น ์š”์†Œ๋ฅผ ์ ์šฉํ•ด ๋ด์•ผ๊ฒ ๋‹ค.

๊ณต๋ถ€ํ•  ๋•Œ ์ฐธ๊ณ ํ•˜๊ธฐ ์ข‹์€ ์‚ฌ์ดํŠธ

๐Ÿ”— https://velog.io/@rmaomina/darkmode-toggle-button
๐Ÿ”— https://inpa.tistory.com/entry/CSS-%F0%9F%92%8D-%EB%B2%84%ED%8A%BC-%EB%94%94%EC%9E%90%EC%9D%B8-%EB%AA%A8%EC%9D%8C
๐Ÿ”— https://developer.mozilla.org/ko/docs/Web/CSS/CSS_Animations/Using_CSS_animations

profile
๐Ÿ’ป ํ”„๋ก ํŠธ์—”๋“œ๋ฅผ ๋ชฉํ‘œ๋กœ ์„ฑ์žฅ ์ค‘! (์•Œ์•„๋ดค๋˜ ๋‚ด์šฉ ๋“ฑ์„ ์ •๋ฆฌํ•˜๊ธฐ)

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