๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
JavaScript/Vanilla JS

[๋ฐ”๋‹๋ผJS๋กœ ๊ทธ๋ฆผํŒ ๋งŒ๋“ค๊ธฐ] Styles part Two

by ์ฝ”๋”ฉํ•˜๋Š” ๋ถ•์–ด 2021. 4. 23.
๋ฐ˜์‘ํ˜•

[์ถœ์ฒ˜-์œ ํŠœ๋ธŒ ๋…ธ๋งˆ๋“œ ์ฝ”๋” Nomad Coders]

https://youtu.be/bxeC0BYm8Y0

 

controlํ•˜๊ธฐ ์œ„ํ•ด์„  ๋‘ ๊ฐœ์˜ ๋ฒ„ํŠผ์ด ํ•„์š”ํ•จ. fill, save.

 

์ถ”๊ฐ€ํ•  ๋ถ€๋ถ„ โ–ผ

<div class="controls__btns">
    <button id="jsMode">Fill</button>
    <button id="jsSave">Save</button>
</div>

์ „์ฒด ์ฝ”๋“œ โ–ผ

<!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" />
    <link rel="stylesheet" href="styles.css" />
    <title>PaintJS</title>
</head>
<body>
    <canvas id="jsCanvas" class="canvas"></canvas>
    <div class="controls">
        <div class="controls__btns">
            <button id="jsMode">Fill</button>
            <button id="jsSave">Save</button>
        </div>
        <div class="controls__colors" id="jsColors">
            <div class="controls__color" style="background-color: black;"></div>
            <div class="controls__color" style="background-color: white"></div>
            <div class="controls__color" style="background-color: #ff3b3c"></div>
            <div class="controls__color" style="background-color: #ff9500"></div>
            <div class="controls__color" style="background-color: #ffcc00"></div>
            <div class="controls__color" style="background-color: #4cd963"></div>
            <div class="controls__color" style="background-color: #5ac8fa"></div>
            <div class="controls__color" style="background-color: #0579ff"></div>
            <div class="controls__color" style="background-color: #5856d6"></div>
        </div>
    </div>
    <script src="app.js"></script>
</body>
</html>

 

 

styles.css๋„ ์ˆ˜์ •ํ•ด์ค€๋‹ค.

@import "reset.css";

body {
    background-color: #f6f9fc;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 50px;
}

.canvas {
    width: 700px;
    height: 700px;
    background-color: white;
    border-radius: 15px;
    box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}

.controls {
    margin-top: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ์ถ”๊ฐ€ ์ˆ˜์ •ํ•œ ๋ถ€๋ถ„ */

.controls .controls__btns {
    margin-bottom: 30px;
}

.controls__btns button {
    all: unset;
    cursor: pointer;
    background-color: white;
    padding: 5px 0px;
    width: 80px;
    text-align: center;
    border-radius: 5px;
    box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
    border: 2px solid rgba(0, 0, 0, 0.2);
    color: rgba(0, 0, 0, 0.7);
    text-transform: uppercase;
    font-weight: 800;
    font-size: 12px;
}

.controls__btns button:active{
    transform: scale(0.98);
}

/* ↑ ์ด๊นŒ์ง€ ์ˆ˜์ •ํ•œ ๋ถ€๋ถ„! */

.controls .controls__colors {
    display: flex;
}

.controls__colors .controls__color {
    width: 50px;
    height: 50px;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}

 

์ ์šฉ ์™„๋ฃŒ

 

 

 

์ด์ œ button ์œ„์— Range input์„ ๋„ฃ์„ ๊ฒƒ์ž„.

 

์ถ”๊ฐ€ํ•  ๋ถ€๋ถ„ โ–ผ

<div class="controls__range">
    <input type="range" id="jsRange" />
</div>

์ „์ฒด ์ฝ”๋“œ โ–ผ

<!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" />
    <link rel="stylesheet" href="styles.css" />
    <title>PaintJS</title>
</head>
<body>
    <canvas id="jsCanvas" class="canvas"></canvas>
    <div class="controls">
        <div class="controls__range">
            <input type="range" id="jsRange" />
        </div>
        <div class="controls__btns">
            <button id="jsMode">Fill</button>
            <button id="jsSave">Save</button>
        </div>
        <div class="controls__colors" id="jsColors">
            <div class="controls__color" style="background-color: black;"></div>
            <div class="controls__color" style="background-color: white"></div>
            <div class="controls__color" style="background-color: #ff3b3c"></div>
            <div class="controls__color" style="background-color: #ff9500"></div>
            <div class="controls__color" style="background-color: #ffcc00"></div>
            <div class="controls__color" style="background-color: #4cd963"></div>
            <div class="controls__color" style="background-color: #5ac8fa"></div>
            <div class="controls__color" style="background-color: #0579ff"></div>
            <div class="controls__color" style="background-color: #5856d6"></div>
        </div>
    </div>
    <script src="app.js"></script>
</body>
</html>

 

 

styles.css๋„ ์ˆ˜์ •ํ•œ๋‹ค.

 

์ถ”๊ฐ€ํ•  ๋ถ€๋ถ„ โ–ผ

.controls .controls__range {
    margin-bottom: 30px;
}

์ „์ฒด ์ฝ”๋“œ โ–ผ

@import "reset.css";

body {
    background-color: #f6f9fc;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 50px;
}

.canvas {
    width: 700px;
    height: 700px;
    background-color: white;
    border-radius: 15px;
    box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}

.controls {
    margin-top: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.controls .controls__btns {
    margin-bottom: 30px;
}

.controls__btns button {
    all: unset;
    cursor: pointer;
    background-color: white;
    padding: 5px 0px;
    width: 80px;
    text-align: center;
    border-radius: 5px;
    box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
    border: 2px solid rgba(0, 0, 0, 0.2);
    color: rgba(0, 0, 0, 0.7);
    text-transform: uppercase;
    font-weight: 800;
    font-size: 12px;
}

.controls__btns button:active{
    transform: scale(0.98);
}

.controls .controls__colors {
    display: flex;
}

.controls__colors .controls__color {
    width: 50px;
    height: 50px;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}

.controls .controls__range {
    margin-bottom: 30px;
}

 

 

์ ์šฉํ•ด๋ณด๋ฉด์„œ ์ˆ˜์ •ํ•  ๋ถ€๋ถ„์„ index.html์—์„œ ์ˆ˜์ •ํ•ด์ค€๋‹ค.

 

์ถ”๊ฐ€ํ•  ๋ถ€๋ถ„ โ–ผ

<div class="controls__range">
    <input type="range" id="jsRange" min="0.1" max="5" value="2.5" step="0.1" />
</div>

์ „์ฒด ์ฝ”๋“œ โ–ผ

<!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" />
    <link rel="stylesheet" href="styles.css" />
    <title>PaintJS</title>
</head>
<body>
    <canvas id="jsCanvas" class="canvas"></canvas>
    <div class="controls">
        <div class="controls__range">
            <input type="range" id="jsRange" min="0.1" max="5" value="2.5" step="0.1" />
        </div>
        <div class="controls__btns">
            <button id="jsMode">Fill</button>
            <button id="jsSave">Save</button>
        </div>
        <div class="controls__colors" id="jsColors">
            <div class="controls__color" style="background-color: black;"></div>
            <div class="controls__color" style="background-color: white"></div>
            <div class="controls__color" style="background-color: #ff3b3c"></div>
            <div class="controls__color" style="background-color: #ff9500"></div>
            <div class="controls__color" style="background-color: #ffcc00"></div>
            <div class="controls__color" style="background-color: #4cd963"></div>
            <div class="controls__color" style="background-color: #5ac8fa"></div>
            <div class="controls__color" style="background-color: #0579ff"></div>
            <div class="controls__color" style="background-color: #5856d6"></div>
        </div>
    </div>
    <script src="app.js"></script>
</body>
</html>

 

 

๋งˆ์ง€๋ง‰์œผ๋กœ styles.css์— body ๋ถ€๋ถ„์˜ padding์„ ์ˆ˜์ •ํ•ด์ค€๋‹ค.

body {
    background-color: #f6f9fc;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 50px 0px;
}

 

๋‹ˆ๊ผฌ์Œค.... ์ฝ”๋”ฉ์†๋„๊ฐ€ ๋„ˆ๋ฌด ๋นจ๋ผ์š”... ์ œ์ž๋Š” ๊ฐ•์˜๋ฅผ ๋ช‡๋ฒˆ์ด๊ณ  ๋‹ค์‹œ ๋Œ๋ ค์„œ ๋ด…๋‹ˆ๋‹ค ํฌํ‘

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€