WEB/HTML+CSS+JS

[HTML+CSS+JavaScript]ํƒ€์ดํ•‘ ํšจ๊ณผ ๋žœ๋”ฉ ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ

kite707 2021. 1. 13.

https://www.youtube.com/watch?v=e56H5n1SvEs&t=2s

์œ„ ๊ฐ•์˜๋ฅผ ๋ณด๊ณ  ๋น„์ฃผ์–ผ ์ŠคํŠœ๋””์˜ค ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜์˜€๋‹ค.


HTML

1. ํŒŒ์ผ ์ƒ์„ฑํ•˜๊ธฐ

index.html, main.js, style.cssํŒŒ์ผ์„ ๊ฐ๊ฐ ์ƒ์„ฑํ•œ๋‹ค. VScode์—์„œ๋Š” !+<tap>ํ‚ค๋ฅผ ๋ˆ„๋ฅด๋ฉด html์˜ ๊ธฐ๋ณธ ๊ตฌ์กฐ๊ฐ€ ์ž๋™์™„์„ฑ๋œ๋‹ค. ์ด์™€ ๊ฐ™์ด div.wrap์„ bodyํƒœ๊ทธ์— ์ž…๋ ฅํ•œ ๋’ค <tap>ํ‚ค๋ฅผ ๋ˆ„๋ฅด๋ฉด <div class="wrap"></div>๋กœ ์ž๋™ ์™„์„ฑ์ด ๋œ๋‹ค.

<!--index.html-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Typing text</title>
</head>
<body>
    <div class="wrap">

    </div>
</body>
</html>

 

2. ์•„์ด์ฝ˜ ํฐํŠธ ์‚ฌ์šฉํ•˜๊ธฐ

๊ตฌ๊ธ€์— material icon์ด๋ผ๊ณ  ๊ฒ€์ƒ‰ํ•˜๋ฉด ๋งจ ์œ„์— ์•„๋ž˜์™€ ๊ฐ™์€ ๋งํฌ๊ฐ€ ๋œฌ๋‹ค.

https://material.io/resources/icons/?style=baseline

 

Material Icons

Get Material Icons

material.io

๋“ค์–ด๊ฐ€์„œ ๊ฐ€์žฅ ๋จผ์ € ๋ณด์ด๋Š” ์•„๋ž˜ ํ™”๋ฉด์„ ๋ณด์ž.

๊ฐ€์šด๋ฐ์— develpoer guide๋ฅผ ๋ณด๋ฉด ์•„์ด์ฝ˜ ํฐํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋งŽ์€ ๋ฐฉ๋ฒ•๋“ค์ด ๋‚˜์™€์žˆ๋‹ค.

๊ทธ์ค‘ ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์ธ ๋งํฌ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ index.html์˜ headํƒœ๊ทธ์— ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•˜๋ฉด ๋œ๋‹ค.

<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">

์ด์ œ ์›นํŽ˜์ด์ง€์—์„œ ๋งˆ์Œ์— ๋“œ๋Š” ์•„์ด์ฝ˜์„ ํ•˜๋‚˜ ๊ณจ๋ผ ํด๋ฆญํ•œ ๋’ค

ํ™”์‚ดํ‘œ๊ฐ€ ์žˆ๋Š” ๋ถ€๋ถ„์„ ๋ˆ„๋ฅด๋ฉด ์ฝ”๋“œ๊ฐ€ ๋œฌ๋‹ค. ๋‚ด๊ฐ€ ์„ ํƒํ•œ ์•„์ด์ฝ˜์˜ ๊ฒฝ์šฐ์—๋Š”

<span class="material-icons">
important_devices
</span>

์ด๋Ÿฐ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค.

<!--index.html-->
<!DOCTYPE html>
<html lang="en">
<head>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Typing text</title>
</head>
<body>
    <div class="wrap">
        <h1><span class="material-icons">
            important_devices
        </span>
    </h1>    
    </div>
</body>
</html>

์ฆ‰ ์œ„์™€ ๊ฐ™์ด ์ž…๋ ฅํ•˜๋ฉด (ํ•ด๋‹น ์•„์ด์ฝ˜์ด ์›นํŽ˜์ด์ง€์—์„œ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์ด๋ผ๋Š” ์˜๋ฏธ๋ฅผ ๋ถ€์—ฌํ•˜๊ธฐ ์œ„ํ•ด <h1>ํƒœ๊ทธ๋กœ ๊ฐ์‹ธ์ฃผ์—ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ๊ณ ๋ฅธ ์•„์ด์ฝ˜์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

3. ๊ธ€์ž ์‚ฝ์ž…ํ•˜๊ธฐ

์™„์„ฑ๋œ ์›นํŽ˜์ด์ง€๋ฅผ ๋‹ค์‹œ ๋ณด๋ฉด

์ด๋ ‡๊ฒŒ ๋‘ ์ค„์˜ ๊ธ€์ž๊ฐ€ ๋‚˜์˜จ๋‹ค. ์ฒซ๋ฒˆ์งธ ์ค„์— ์žˆ๋Š” ๊ธ€์ž๋Š” ์กฐ๊ธˆ ํฌ๊ณ  ๊ธ€์”จ๊ฐ€ ๊ตต๋‹ค. ์ด๋ ‡๊ฒŒ ๋‹ค๋ฅธ ํŠน์ง•์„ ์ ์šฉํ•˜๋ ค๋ฉด ๊ธ€์ž์— ๊ฐ๊ฐ ๋‹ค๋ฅธ ํด๋ž˜์Šค์™€ ์•„์ด๋””๋ฅผ ๋ถ€์—ฌํ•˜๋ฉด ๋œ๋‹ค.

๋‚ด์šฉ์ด ์„œ๋กœ ์ถฉ๋Œํ•  ๋•Œ id>class>ํƒœ๊ทธ ์ˆœ์œผ๋กœ ์ ์šฉ๋œ๋‹ค.

์—ฌ๊ธฐ์„œ๋„ ์œ„์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. id๋Š” # class๋Š” .์„ ์ด์šฉํ•˜๋‹ˆ ์•„๋ž˜์™€ ๊ฐ™์ด ์ž…๋ ฅํ•˜๊ณ  <tap>ํ‚ค๋ฅผ ๋ˆ„๋ฅด๋ฉด

p#dynamic.lg-text
<!-- <tapํ‚ค> -->
<p id="dynamic" class="lg-text"></p> 

์ด๋ ‡๊ฒŒ ์ž๋™ ์™„์„ฑ์ด ๋œ๋‹ค.

๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ๋ฐ‘์˜ ์ค„ ๊ธ€์ž์— ๋Œ€ํ•ด์„œ๋Š” class์ด๋ฆ„์„ "sm-text"๋กœ ์ง€์ •ํ•ด ์ฃผ๋„๋ก ํ•˜์ž. ๊ทธ๋ฆฌ๊ณ  ๊ฐ ํƒœ๊ทธ ์•ˆ์— ๋„ฃ๊ณ ์‹ถ์€ ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

๋‚˜๋Š” ์ด๋ ‡๊ฒŒ ์ž…๋ ฅํ•˜์˜€๋‹ค.

<!--index.html-->
<!DOCTYPE html>
<html lang="en">
<head>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Typing text</title>
</head>
<body>
    <div class="wrap">
        <h1><span class="material-icons">
            important_devices
        </span>
    </h1>
    <p id="dynamic" class="lg-text">
        Learn to JavaScript
    </p>
    <p class="sm-text">
        kite707 | Computer Engineering
    </p>    
    </div>
</body>
</html>

์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ฉด ์›ํ•˜๋Š”๋Œ€๋กœ ์ž˜ ์ถœ๋ ฅ๋œ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๊ธฐ๊นŒ์ง€ ํ•˜๋ฉด html์„ ์ด์šฉํ•ด ๊ธฐ์ดˆ ๋ผˆ๋Œ€๋Š” ๋ชจ๋‘ ์žก์€ ๊ฒƒ์ด๋‹ค. ์ด์ œ CSS๋ฅผ ํ†ตํ•ด ๊ธ€์ž๋ฅผ ์›ํ•˜๋Š”๋Œ€๋กœ ๊พธ๋ฉฐ๋ณด๋„๋ก ํ•˜์ž.


CSS

htmlํŒŒ์ผ๊ณผ cssํŒŒ์ผ ์—ฐ๊ฒฐํ•˜๊ธฐ

style.cssํŒŒ์ผ์— ์ž…๋ ฅํ•œ ๋‚ด์šฉ์ด index.htmlํŒŒ์ผ์— ์ •์ƒ์ ์œผ๋กœ ์ ์šฉ๋˜๋„๋ก ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‘ ํŒŒ์ผ์„ ์—ฐ๊ฒฐํ•ด์•ผ ํ•œ๋‹ค. index.htmlํŒŒ์ผ headํƒœ๊ทธ ์•ˆ์— <link href="style.css" rel="stylesheet">๋ฅผ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•˜์ž. ์ „์ฒด ์ฝ”๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

<!--index.html-->
<!DOCTYPE html>
<html lang="en">
<head>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">
      <link href="style.css" rel="stylesheet">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Typing text</title>
</head>
<body>
    <div class="wrap">
        <h1><span class="material-icons">
            important_devices
        </span>
    </h1>
    <p id="dynamic" class="lg-text">
        Learn to JavaScript
    </p>
    <p class="sm-text">
        kite707 | Computer Engineering
    </p>    
    </div>
</body>
</html>

CSS๋ฅผ ์ด์šฉํ•ด ๋ฐฐ์น˜ํ•˜๊ธฐ

 

์ด์ œ style.css์—์„œ ๋ชจ๋“  ํƒœ๊ทธ์— ๋Œ€ํ•ด์„œ(*์„ ํƒ์ž ์ด์šฉ) margin๊ณผ padding๊ฐ’์„ ์—†์• ๊ณ  box-sizing์†์„ฑ์„ border-box๋กœ ์ง€์ •ํ•˜์ž.

content-box์™€ border-box
-content-box๋Š” ๊ธฐ๋ณธ CSS ๋ฐ•์Šค ํฌ๊ธฐ ๊ฒฐ์ •๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์š”์†Œ์˜ ๋„ˆ๋น„๋ฅผ 100 ํ”ฝ์…€๋กœ ์„ค์ •ํ•˜๋ฉด ์ฝ˜ํ…์ธ  ์˜์—ญ์ด 100 ํ”ฝ์…€ ๋„ˆ๋น„๋ฅผ ๊ฐ€์ง€๊ณ , ํ…Œ๋‘๋ฆฌ์™€ ์•ˆ์ชฝ ์—ฌ๋ฐฑ์€ ์ด์— ๋”ํ•ด์ง‘๋‹ˆ๋‹ค.
-border-box๋Š” ํ…Œ๋‘๋ฆฌ์™€ ์•ˆ์ชฝ ์—ฌ๋ฐฑ์˜ ํฌ๊ธฐ๋„ ์š”์†Œ์˜ ํฌ๊ธฐ๋กœ ๊ณ ๋ คํ•ฉ๋‹ˆ๋‹ค. ๋„ˆ๋น„๋ฅผ 100 ํ”ฝ์…€๋กœ ์„ค์ •ํ•˜๊ณ  ํ…Œ๋‘๋ฆฌ์™€ ์•ˆ์ชฝ ์—ฌ๋ฐฑ์„ ์ถ”๊ฐ€ํ•˜๋ฉด, ์ฝ˜ํ…์ธ  ์˜์—ญ์ด ์ค„์–ด๋“ค์–ด ์ด ๋„ˆ๋น„ 100 ํ”ฝ์…€์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ์ด ํŽธ์ด ํฌ๊ธฐ๋ฅผ ์กฐ์ ˆํ•  ๋•Œ ์‰ฝ์Šต๋‹ˆ๋‹ค.

์ถœ์ฒ˜ : https://developer.mozilla.org/ko/docs/Web/CSS/box-sizing

 

box-sizing - CSS: Cascading Style Sheets | MDN

box-sizing CSS ์†์„ฑ์€ ์š”์†Œ์˜ ๋„ˆ๋น„์™€ ๋†’์ด๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://g

developer.mozilla.org

content-box์˜ ๊ฒฝ์šฐ
border-box์˜ ๊ฒฝ์šฐ

์ด์–ด์„œ cssํŒŒ์ผ์„ ํ†ตํ•ด ๋ฐฐ๊ฒฝํ™”๋ฉด ์ƒ‰์„ ๋ฐ”๊พธ๊ณ  ๊ธ€์”จ๋ฅผ ๊ฐ€์šด๋ฐ์— ๋ฐฐ์น˜ํ•ด๋ณด์ž. ์ฝ”๋“œ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ์ž…๋ ฅํ•˜๋ฉด

/*style.css*/
*{
    margin:0;
    padding:0;
    box-sizing: border-box;
}
body{
    background-color:#0F5BFF;
}
.wrap{
    position:absolute;
    top:50%;
    left:50%;
}

 

์•„๋ž˜์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ๋‚˜์˜จ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ์˜๋„ํ•œ๋Œ€๋กœ ๊ธ€์”จ๊ฐ€ ์ •๊ฐ€์šด๋ฐ์— ์œ„์น˜ํ•˜์ง€ ์•Š๋Š”๋‹ค. 

์ฝ”๋“œ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•ด์„œ ์‚ดํŽด๋ณด์ž

/*style.css*/
*{
    margin:0;
    padding:0;
    box-sizing: border-box;
}
body{
    background-color:#0F5BFF;
}
.wrap{
    border: solid 5px;
    position:absolute;
    top:50%;
    left:50%;
}

 

 

์šฐ๋ฆฌ๊ฐ€ ๊ฐ€์šด๋ฐ์— ์œ„์น˜์‹œํ‚จ ๊ฒƒ์€ ์ƒ์ž์˜ ์™ผ์ชฝ ์œ„ ๋ชจ์„œ๋ฆฌ์ด๋‹ค. ์ด๊ฒƒ์„ ๋ณด์™„ํ•˜๊ธฐ ์œ„ํ•ด ์ฝ”๋“œ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•˜๋„๋ก ํ•˜์ž.

/*style.css*/
*{
    margin:0;
    padding:0;
    box-sizing: border-box;
}
body{
    background-color:#0F5BFF;
}
.wrap{
    position:absolute;
    top:50%;
    left:50%;
    transform: translate(-50%,-50%);
    color:white; /*๊ธ€์”จ๋ฅผ ํฐ์ƒ‰์œผ๋กœ ๋ฐ”๊พธ๊ธฐ ์œ„ํ•ด ์ถ”๊ฐ€๋œ ๋ถ€๋ถ„*/
    text-align: center; /*๊ฐ€์šด๋ฐ ์ •๋ ฌ์„ ์œ„ํ•ด ์ถ”๊ฐ€๋œ ๋ถ€๋ถ„*/
}

๊ธ€์”จ๊ฐ€ ๊ฐ€์šด๋ฐ์— ๋ฐฐ์น˜๊ฐ€ ๋˜์—ˆ๋‹ค.

์•„์ด์ฝ˜ ํฐํŠธ๊นŒ์ง€ ์†์„ฑ์ด ์ž˜ ์ ์šฉ๋œ ๊ฒƒ์œผ๋กœ ๋ณด์•„ ์•„์ด์ฝ˜ ํฐํŠธ๋Š” CSS์˜ ํ…์ŠคํŠธ์™€ ๊ด€๋ จ๋œ ์†์„ฑ์„ ๊ทธ๋Œ€๋กœ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

ํฐํŠธํฌ๊ธฐ ์กฐ์ ˆ ๋ฐ ์ปค์„œ๋ชจ์–‘ ๋งŒ๋“ค๊ธฐ

์šฐ์„  ํฐํŠธ ํฌ๊ธฐ ์กฐ์ ˆ์„ ์™„๋ฃŒํ•œ ์ƒํƒœ์˜ ์ฝ”๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

/*style.css*/
*{
    margin:0;
    padding:0;
    box-sizing: border-box;
}
body{
    background-color:#0F5BFF;
}
.wrap{
    position:absolute;
    top:50%;
    left:50%;
    transform: translate(-50%,-50%);
    color:white;
    text-align: center;
}
.material-icons{ /*์•„์ด์ฝ˜ ํฌ๊ธฐ*/
    font-size:10rem;
}

.lg-text{ /*์ฒซ๋ฒˆ์งธ ์ค„ ๊ธ€์ž ํฌ๊ธฐ*/
    font-size:2rem;
    font-weight:bold;
    margin-bottom:5px;
}

.sm-text{ /*๋‘๋ฒˆ์งธ ์ค„ ๊ธ€์ž ํฌ๊ธฐ*/
    font-size: 1.5rem;
}

์•„์ด์ฝ˜๊ณผ ๊ธ€์ž ํฌ๊ธฐ๊ฐ€ ์ ์ ˆํ•˜๊ฒŒ ์กฐ์ ˆ๋˜์—ˆ๋‹ค.

์ด์ œ ์ปค์„œ ๋ชจ์–‘์„ ๋งŒ๋“ค์–ด ๋ณด๋„๋ก ํ•˜์ž. dynamic์œผ๋กœ ๋ฌถ์ธ ๋ถ€๋ถ„์˜ ๋งจ ๋์— ์ปค์„œ๊ฐ€ ๋งŒ๋“ค์–ด ์ ธ์•ผ ํ•˜๋‹ˆ ์ฝ”๋“œ๋Š” #dynamic์œผ๋กœ ์‹œ์ž‘ํ•œ๋‹ค. ๊ฐ•์˜์—์„œ๋Š” ๊ฐ€์ƒ์š”์†Œ after๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๊ฐ€์ƒ์š”์†Œ๋Š” ํŠน์ • ๋ถ€๋ถ„์„ ์„ ํƒํ•œ๋‹ค. ์›์น™์ ์œผ๋กœ ๊ฐ€์ƒ ํด๋ž˜์Šค๋Š” ์ฝœ๋ก ์„ ํ•œ๊ฐœ(:) ๊ฐ€์ƒ ์š”์†Œ๋Š” ์ฝœ๋ก ์„ ๋‘๊ฐœ(::)์ฐ์ง€๋งŒ ํ•˜๋‚˜๋งŒ ์ฐ์–ด๋„ ๊ฑฐ์˜ ๋ชจ๋“  ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•œ๋‹ค.

์ถœ์ฒ˜ : http://blog.hivelab.co.kr/%EA%B3%B5%EC%9C%A0before%EC%99%80after-%EA%B7%B8%EB%93%A4%EC%9D%98-%EC%A0%95%EC%B2%B4%EB%8A%94/

์œ„์—๊ฐ€ ๋Œ€ํ‘œ์ ์ธ ๊ฐ€์ƒ ์š”์†Œ๋“ค์ด๊ณ  ๋” ๋งŽ์€ ์ •๋ณด๋Š” ์•„๋ž˜ ๋งํฌ์—์„œ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

https://developer.mozilla.org/ko/docs/Web/CSS/Pseudo-elements

 

์˜์‚ฌ ์š”์†Œ - CSS: Cascading Style Sheets | MDN

CSS ์˜์‚ฌ ์š”์†Œ(๊ฐ€์ƒ ์š”์†Œ)๋Š” ์„ ํƒ์ž์— ์ถ”๊ฐ€ํ•˜๋Š” ํ‚ค์›Œ๋“œ๋กœ, ์„ ํƒํ•œ ์š”์†Œ์˜ ์ผ๋ถ€๋ถ„์—๋งŒ ์Šคํƒ€์ผ์„ ์ž…ํž ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ::first-line์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฌธ๋‹จ ์ฒซ ์ค„์˜ ๊ธ€์”จ์ฒด๋งŒ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. p::firs

developer.mozilla.org

์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์ž.

/*style.css*/
*{
    margin:0;
    padding:0;
    box-sizing: border-box;
}
body{
    background-color:#0F5BFF;
}
.wrap{
    position:absolute;
    top:50%;
    left:50%;
    transform: translate(-50%,-50%);
    color:white;
    text-align: center;
}
.material-icons{ /*์•„์ด์ฝ˜ ํฌ๊ธฐ*/
    font-size:10rem;
}

.lg-text{ /*์ฒซ๋ฒˆ์งธ ์ค„ ๊ธ€์ž ํฌ๊ธฐ*/
    font-size:2rem;
    font-weight:bold;
    margin-bottom:5px;
}

.sm-text{ /*๋‘๋ฒˆ์งธ ์ค„ ๊ธ€์ž ํฌ๊ธฐ*/
    font-size: 1.5rem;
}

#dynamic{
    position:relative;
}

#dynamic::after{
    content:"";
    /*์ƒ์ž ๋ชจ์–‘์œผ๋กœ ๋ณด์ด๊ฒŒ ํ•จ*/
    display:block;
    /*dynamic๋‚ด์—์„œ ์˜ค๋ฅธ์ชฝ ๋์— ์œ„์น˜ํ•˜๋„๋ก ํ•จ*/
    position:absolute;
    top:0;
    right:0;
    /*์ƒ์ž์˜ ๊ตต๊ธฐ ๋ฐ ๊ธธ์ด*/
    width:4px;
    height:100%;
    /*์ƒ์ž์˜ ์ƒ‰๊น”*/
    background-color: white;
}

์ปค์„œ ๋ชจ์–‘์ด ์ž˜ ๋งŒ๋“ค์–ด์กŒ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ ๊ธ€์ž์˜ ๋์— ์ปค์„œ๊ฐ€ ์ƒ์„ฑ๋˜์–ด์•ผ ํ•˜๋Š”๋ฐ ์œ„ ์ฝ”๋“œ๋ฅผ ์ด์šฉํ•˜๋ฉด ๊ธ€์ž๋ฅผ ์ง€์›Œ๋„ ์ปค์„œ๊ฐ€ ์ƒ์ž์˜ ๋์— ์œ„์น˜ํ•˜๊ฒŒ ๋œ๋‹ค. ์ด๋ฅผ ๋ณด์™„ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” inline-block์†์„ฑ์„ ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ๋˜ ์ปค์„œ๊ฐ€ ๊นœ๋นก ๊นœ๋นก ํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด๋ ค๋ฉด ์ปค์„œ๊ฐ€ ๋ณด์ด์ง€ ์•Š๊ฒŒ ๋˜์—ˆ๋‹ค๊ฐ€ ๋ณด์ด๊ฒŒ ๋˜๋Š” ๊ฒƒ์ด ๋ฐ˜๋ณต ๋˜์–ด์•ผ ํ•œ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด ์ฝ”๋“œ๋ฅผ ์กฐ๊ธˆ ๋” ์ž‘์„ฑํ•˜์ž.

/*style.css*/
*{
    margin:0;
    padding:0;
    box-sizing: border-box;
}
body{
    background-color:#0F5BFF;
}
.wrap{
    position:absolute;
    top:50%;
    left:50%;
    transform: translate(-50%,-50%);
    color:white;
    text-align: center;
}
.material-icons{ /*์•„์ด์ฝ˜ ํฌ๊ธฐ*/
    font-size:10rem;
}

.lg-text{ /*์ฒซ๋ฒˆ์งธ ์ค„ ๊ธ€์ž ํฌ๊ธฐ*/
    font-size:2rem;
    font-weight:bold;
    margin-bottom:5px;
}

.sm-text{ /*๋‘๋ฒˆ์งธ ์ค„ ๊ธ€์ž ํฌ๊ธฐ*/
    font-size: 1.5rem;
}

#dynamic{
    position:relative;
    /*์ปค์„œ๊ฐ€ ๊ธ€์ž ๋์— ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์กด์žฌํ•˜๋„๋ก ์ถ”๊ฐ€๋œ ๋ถ€๋ถ„*/
    display:inline-block;
}

#dynamic::after{
    content:"";
    /*์ƒ์ž ๋ชจ์–‘์œผ๋กœ ๋ณด์ด๊ฒŒ ํ•จ*/
    display:block;
    /*dynamic๋‚ด์—์„œ ์˜ค๋ฅธ์ชฝ ๋์— ์œ„์น˜ํ•˜๋„๋ก ํ•จ*/
    position:absolute;
    top:0;
    right:0;
    /*์ƒ์ž์˜ ๊ตต๊ธฐ ๋ฐ ๊ธธ์ด*/
    width:4px;
    height:100%;
    /*์ƒ์ž์˜ ์ƒ‰๊น”*/
    background-color: white;
}

/*activeํด๋ž˜์Šค๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋  ๊ฒฝ์šฐ ์•ˆ๋ณด์ด๊ฒŒ ๋œ๋‹ค.*/
#dynamic.active::after{
    display: none;
}

๋งˆ์ง€๋ง‰ 3์ค„์— ์˜ํ•ด ์šฐ๋ฆฌ๊ฐ€ JavaScript๋ฅผ ํ†ตํ•ด dynamic์— active ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•  ๊ฒฝ์šฐ ์ปค์„œ๋Š” ์•ˆ๋ณด์ด๊ฒŒ ๋œ๋‹ค. ์œ„ ์ฝ”๋“œ์˜ ์‹คํ–‰ํ™”๋ฉด์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

์ปค์„œ๊ฐ€ ๊ธ€์ž๋์— ์™„์ „ํžˆ ๋ถ™์—ˆ๋‹ค.

์ปค์„œ์˜ ์œ„์น˜๋ฅผ ์กฐ๊ธˆ๋งŒ ์˜ค๋ฅธ์ชฝ์„ ์˜ฎ๊ธฐ๋ ค๋ฉด ์ฝ”๋“œ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

/*style.css*/
*{
    margin:0;
    padding:0;
    box-sizing: border-box;
}
body{
    background-color:#0F5BFF;
}
.wrap{
    position:absolute;
    top:50%;
    left:50%;
    transform: translate(-50%,-50%);
    color:white;
    text-align: center;
}
.material-icons{ 
    font-size:10rem;
}

.lg-text{ 
    font-size:2rem;
    font-weight:bold;
    margin-bottom:5px;
}

.sm-text{ 
    font-size: 1.5rem;
}

#dynamic{
    position:relative;
    display:inline-block;
}

#dynamic::after{
    content:"";
    display:block;
    position:absolute;
    top:0;
    right:-10px;  /*์ˆ˜์ •๋œ ๋ถ€๋ถ„*/
    width:4px;
    height:100%;
    background-color: white;
}


#dynamic.active::after{
    display: none;
}

JavaScript

1. main.js ํŒŒ์ผ๊ณผ index.htmlํŒŒ์ผ ์—ฐ๊ฒฐํ•˜๊ธฐ

์ด ์ฝ”๋“œ๋ฅผ index.html์˜ .bodyํƒœ๊ทธ ์•ˆ์— ๋„ฃ์œผ๋ฉด ๋‘ ํŒŒ์ผ์˜ ์—ฐ๊ฒฐ์ด ์™„๋ฃŒ๋œ๋‹ค.

<script src="main.js"></script>

index.html์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

<!--index.html-->
<!DOCTYPE html>
<html lang="en">
<head>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">
      <link href="style.css" rel="stylesheet">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Typing text</title>
</head>
<body>
    <div class="wrap">
        <h1><span class="material-icons">
            important_devices
        </span>
    </h1>
    <p id="dynamic" class="lg-text">
        Learn to JavaScript
    </p>
    <p class="sm-text">
        kite707 | Computer Engineering
    </p>    
    </div>
    <script src="main.js"></script>
</body>
</html>

2. ์ปค์„œ ๊นœ๋นก์ž„ ํšจ๊ณผ ์ฃผ๊ธฐ

toggle : ํ† ๊ธ€์ด๋ผ๋Š” ์šฉ์–ด๋Š” ์˜ค์ง ๋‘ ๊ฐ€์ง€ ์ƒํƒœ๋ฐ–์—๋Š” ์—†๋Š” ์ƒํ™ฉ์—์„œ, ์Šค์œ„์น˜๋ฅผ ํ•œ๋ฒˆ ๋ˆ„๋ฅด๋ฉด ํ•œ ๊ฐ’์ด ๋˜๊ณ , ๋‹ค์‹œ ํ•œ๋ฒˆ ๋ˆ„๋ฅด๋ฉด ๋‹ค๋ฅธ ๊ฐ’์œผ๋กœ ๋ณ€ํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค.

๊ฐ•์˜์—์„œ๋Š” toggleํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜๋Š”๋ฐ ์ด๋Š” jQuery์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ํ•จ์ˆ˜์ด๋‹ค.(๋”ฐ๋ผ์„œ ๋งŒ์•ฝ jQuery๊ฐ€ ์ปดํ“จํ„ฐ์— ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค๋ฉด ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ <head></head>์‚ฌ์ด์— ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•ด์•ผํ•œ๋‹ค.)

<script
  src="https://code.jquery.com/jquery-3.5.1.js"
  integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
  crossorigin="anonymous"></script>

toggleํ•จ์ˆ˜์˜ ์‚ฌ์šฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

"ID์ด๋ฆ„".toggle("class์ด๋ฆ„"); //class์ด๋ฆ„์˜ ๊ฒฝ์šฐ ์—†์„์‹œ ()๋งŒ ํ•ด๋„ ์‚ฌ์šฉ๊ฐ€๋Šฅ
//์ด์ „ ์ƒํƒœ์— ๋”ฐ๋ผ ํ˜„์žฌ ์ƒํƒœ๋ฅผ ๋ฐ˜๋Œ€๋กœ ๋ฐ”๊ฟ”์คŒ

์ด๋ฅผ setIntervalํ•จ์ˆ˜์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

//main.js
let target=document.querySelector("#dynamic");
function blink(){
    target.classList.toggle("active");
}
setInterval(blink, 500); //blinkํ•จ์ˆ˜๋ฅผ 0.5์ดˆ์— ํ•œ๋ฒˆ์”ฉ ํ˜ธ์ถœ

์ปค์„œ ๊นœ๋นก์ž„ ํšจ๊ณผ๊ฐ€ ์ž˜ ์ ์šฉ๋˜์—ˆ๋‹ค.

 

๋Œ“๊ธ€