게으른개발너D

[JS] Paint App 1 - style 본문

프로젝트/Side Project

[JS] Paint App 1 - style

lazyhysong 2023. 2. 14. 17:01

모든 브라우저에서 스타일을 동일하게 적용할 수 있도록 reset.css를 가져온다.

https://meyerweb.com/eric/tools/css/reset/

 

CSS Tools: Reset CSS

CSS Tools: Reset CSS The goal of a reset stylesheet is to reduce browser inconsistencies in things like default line heights, margins and font sizes of headings, and so on. The general reasoning behind this was discussed in a May 2007 post, if you're inter

meyerweb.com

코드를 모두 복사하여 reset.css 파일을 만들어 붙여넣기 한 후

style.css에서 이걸 import한다.

@import "reset.css";

 

 

1. canvas 만들기

index.html

<canvas id="jsCanvas" class="canvas"></canvas>

style.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: 30px;
}

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

요렇게 캔버스가 생성된다.

 

2. 색상 control button

canvas 밑에 색상을 선택할 수 있는 컨트롤을 만든다.

index.html

div.controls>div.controls_colors 입력 후 엔터

그 안에 div.control_color*9 입력 후 엔터를 치면

control_color라는 클래스를 가진 div가 9개 만들어진다.

<div class="controls">
   <div class="controls_colors">
      <div class="control_color" style="background-color: #2c2c2c;"></div>
      <div class="control_color" style="background-color: #fff;"></div>
      <div class="control_color" style="background-color: #ff0077;"></div>
      <div class="control_color" style="background-color: #ff4da0;"></div>
      <div class="control_color" style="background-color: #ff8bae;"></div>
      <div class="control_color" style="background-color: #ffd1dc;"></div>
      <div class="control_color" style="background-color: #c1b0ff;"></div>
      <div class="control_color" style="background-color: #b43ccc;"></div>
      <div class="control_color" style="background-color: #db69fd;"></div>
   </div>
</div>

background-color로 페인트칠 하고 싶은 색상 넣기

style.css

.controls {
    margin-top: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.controls .controls_colors {
    display: flex;
}
.controls_colors .control_color {
    width: 30px;
    height: 30px;
    cursor: pointer;
}
.controls_colors .control_color:first-child {
    border-radius: 10px 0 0 10px;
}
.controls_colors .control_color:last-child {
    border-radius: 0 10px 10px 0;
}
.control_color.active {
    position: relative;
}
.control_color.active:after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 70%;
    height: 70%;
    border-radius: 50%;
    border: 2px solid rgb(255, 253, 147);
}

 

 

 

 

3. 나머지 컨트롤 버튼들

pen과 fill(채우기)를 선택할 수 있고 save 할 수 있는 버튼을 만들 것이다.

index.html

div.controls_btns>button#jsMode+button#jsSave 입력

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

 

style.css

.controls .controls_range {
    margin-bottom: 15px;
}
.controls .controls_btns {
    margin-bottom: 15px;
}
.controls_btns button {
    all: unset;
    cursor: pointer;
    background-color: #fff;
    padding: 5px 0px;
    width: 50px;
    font-size: 14px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(50, 50, 93, 0.11);
    text-transform: uppercase;
    font-weight: 600;
    color: rgba(0,0,0,0.8);
}
.controls_btns button:active {
    transform: scale(0.98);
}

pen 두께를 조절 가능한 range를 만든다.

index.html

<div class="controls_range">
   <input type="range" id="jsRange" min="0.1" max="10.0" value="2.5" step="0.5" />
</div>

style.css

.controls .controls_range {
    margin-bottom: 15px;
}

 

'프로젝트 > Side Project' 카테고리의 다른 글

[JS] JavaScript Drum Kit  (0) 2023.03.24
[JS] Paint App 2 - handle JS  (0) 2023.02.14
[JS] Momentum App 6 - Style  (0) 2023.02.13
[JS] Momentum App 5 - Weather  (0) 2023.02.13
[JS] Momentum App 4 - To Do  (0) 2023.02.13
Comments