Language/HTML & CSS

[HTML & CSS] [์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ ์›น] HTML & CSS ๊ธฐ์ดˆ

Ella_K 2022. 7. 1. 19:36

๐Ÿ”ฅ HTML , CSS ๊ธฐ๋ณธ ๋‚ด์šฉ

HTML

  • ๊ตฌ์—ญ๊ณผ ํ…์ŠคํŠธ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ฝ”๋“œ
  • head ์™€ body๋กœ ๊ตฌ์„ฑ๋จ
  • head ์•ˆ์—๋Š” ํŽ˜์ด์ง€์˜ ์†์„ฑ์ •๋ณด (meta, script, link, title) ๋ฅผ ๋‹ด์Œ
  • body ์•ˆ์—๋Š” ํŽ˜์ด์ง€์˜ ๋‚ด์šฉ์„ ๋‹ด๋Š”๋‹ค.
  • ๊ตฌ์—ญ์„ ๋งŒ๋“ค๋ ค๋ฉด divํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ๋‹ค. div๋กœ ๋ฌถ์—ฌ์ ธ ์žˆ๋Š” ๊ฒƒ์€ ๋‚ด์šฉ๋ฌผ์ด ๋ณ€๊ฒฝ๋˜๋ฉด ๊ฐ™์ด ๋ณ€๊ฒฝ๋œ๋‹ค. (block element)
  • ๋ฌธ์ž ์ผ๋ถ€๋งŒ ์„ ํƒํ•ด์„œ ์ง€์ •ํ• ๋ ค๋ฉด spanํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ๋‹ค. (inline element)
  • ํŠน์ • ๋ถ€๋ถ„์„ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด์„œ class์™€ id๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ์ง€์ • ๋ฒ”์œ„๋Š” class > id ์ด๋‹ค.
  • class ๋Š” ๋ฌด์–ธ๊ฐ€๋ฅผ ๊ทธ๋ฃนํ•‘ํ•œ๋‹ค๋Š” ๋ง. ๊ทธ๋ฃนํ•‘ํ•˜๊ณ  ์‹ถ์€ ๊ฒƒ๋“ค์„ ๊ฐ™์€ class๋กœ ์ง€์ •. ex> ๋ฐ˜
  • id๋Š” ๋ฌด์–ธ๊ฐ€๋ฅผ ์‹๋ณ„ํ•œ๋‹ค๋Š” ๋ง.  ํ•˜๋‚˜๋งŒ ์กด์žฌํ•  ์ˆ˜ ์žˆ์Œ. ์ •ํ™•ํ•˜๊ฒŒ ํ•˜๋‚˜๋งŒ ํƒ€๊ฒŸํŒ…. ex> ํ•™๋ฒˆ
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ | HTML ๊ธฐ์ดˆ</title>
</head>

<body>
    <!-- ๊ตฌ์—ญ์„ ๋‚˜๋ˆ„๋Š” ํƒœ๊ทธ๋“ค -->
    <div>๋‚˜๋Š” ๊ตฌ์—ญ์„ ๋‚˜๋ˆ„์ฃ </div>
    <p>๋‚˜๋Š” ๋ฌธ๋‹จ์ด์—์š”</p>
    <ul>
        <li> bullet point!1 </li>
        <li> bullet point!2 </li>
    </ul>

    <!-- ๊ตฌ์—ญ ๋‚ด ์ฝ˜ํ…์ธ  ํƒœ๊ทธ๋“ค -->
    <h1>h1์€ ์ œ๋ชฉ์„ ๋‚˜ํƒ€๋‚ด๋Š” ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค. ํŽ˜์ด์ง€๋งˆ๋‹ค ํ•˜๋‚˜์”ฉ ๊ผญ ์จ์ฃผ๋Š” ๊ฒŒ ์ข‹์•„์š”. ๊ทธ๋ž˜์•ผ ๊ตฌ๊ธ€ ๊ฒ€์ƒ‰์ด ์ž˜ ๋˜๊ฑฐ๋“ ์š”.</h1>
    <h2>h2๋Š” ์†Œ์ œ๋ชฉ์ž…๋‹ˆ๋‹ค.</h2>
    <h3>h3~h6๋„ ๊ฐ์ž์˜ ์—ญํ• ์ด ์žˆ์ฃ . ๋น„์ค‘์€ ์ž‘์ง€๋งŒ..</h3>
    <hr>
    span ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: ํŠน์ • <span style="color:red">๊ธ€์ž</span>๋ฅผ ๊พธ๋ฐ€ ๋•Œ ์จ์š”
    <hr>
    a ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: <a href="http://naver.com/"> ํ•˜์ดํผ๋งํฌ </a>
    <hr>
    img ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: <img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" />
    <hr>
    input ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: <input type="text" />
    <hr>
    button ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: <button> ๋ฒ„ํŠผ์ž…๋‹ˆ๋‹ค</button>
    <hr>
    textarea ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค: <textarea>๋‚˜๋Š” ๋ฌด์—‡์ผ๊นŒ์š”?</textarea>
</body>

</html>

 

CSS

  • <head> ~ </head> ์•ˆ์— <style> ~ <style> ๋กœ ๊ณต๊ฐ„์„ ๋งŒ๋“ค์–ด ์ž‘์„ฑ
  • HTML body ์•ˆ์— ๋‚ด์šฉ๋ฌผ๋“ค์— ์ง€์ •ํ•œ class  ๋˜๋Š” id์ด๋ฆ„์„ ์ด์šฉํ•˜์—ฌ style์„ ๋จน์ธ๋‹ค.
  • ์˜ˆ๋ฅผ ๋“ค์–ด ์•„๋ž˜ ์ฝ”๋“œ์—์„œ 'mytitle' ํด๋ž˜์Šค๋ฅผ ๊ฐ€๋ฆฌํ‚ฌ ๋•Œ, .mytitle{...}๋ฅผ ์ด์šฉํ•˜์—ฌ style์„ ๋จน์ธ๋‹ค.
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ | ๋กœ๊ทธ์ธํŽ˜์ด์ง€</title>
    <style>
        .mytitle {
            color: white;
            width: 300px;
            height: 200px;
            background-image: url('~.jpg');
            background-position: center;
            background-size: cover;
            
            border-radius: 10px;
            text-align: center;
            padding-top: 40px;
        }
    </style>
</head>

<body>
    <div class="mytitle">
        <h1>๋กœ๊ทธ์ธ ํŽ˜์ด์ง€</h1>
        <h5>์•„์ด๋””, ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”</h5>
    </div>
</body>

</html>

 

  • class ์ค‘์—์„œ ํŠน์ • ๋ถ€๋ถ„๋งŒ style์„ ๋จน์ด๊ณ  ์‹ถ์„ ๋•Œ 'id' ๋ฅผ ์ด์šฉํ•œ๋‹ค.
  • ์•„๋ž˜ 'first' id๋ฅผ ๊ฐ€๋ฆฌํ‚ฌ ๋•Œ, #first{...}๋ฅผ ์ด์šฉํ•˜์—ฌ ์Šคํƒ€์ผ์„ ๋จน์ธ๋‹ค. 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS</title>
    <style>
        span{
            font-weight: bold;
            color: orange;
        }
        .js{
            color: red;
        }
        #first{
            color: blue;
        }

    </style>
</head>
<body>
    <h1>WEB</h1>
    <h2>JavaScript</h2>
    <p>
    <span id="first" class="js">JavaScript</span>, often abbreviated JS, is a programming language that is one of the core technologies of the World Wide Web, alongside <span>HTML</span> and <span>CSS</span>.[11] As of 2022, 98% of websites use <span class="js">JavaScript</span> on the client side for web page behavior,[12] often incorporating third-party libraries.[13] All major web browsers have a dedicated JavaScript engine to execute the code on users' devices.

    <span class="js">JavaScript</span> is a high-level, often just-in-time compiled language that conforms to the ECMAScript standard.[14] It has dynamic typing, prototype-based object-orientation, and first-class functions. It is multi-paradigm, supporting event-driven, functional, and imperative programming styles. It has application programming interfaces (APIs) for working with text, dates, regular expressions, standard data structures, and the Document Object Model (DOM).

    The ECMAScript standard does not include any input/output (I/O), such as networking, storage, or graphics facilities. In practice, the web browser or other runtime system provides <span class="js">JavaScript</span> APIs for I/O.

    <span class="js">JavaScript</span> engines were originally used only in web browsers, but are now core components of some servers and a variety of applications. The most popular runtime system for this usage is Node.js.

    Although Java and <span class="js">JavaScript</span> are similar in name, syntax, and respective standard libraries, the two languages are distinct and differ greatly in design.
    </p>
</body>
</html>

span > class > id
class ๋ฅผ ์ด์šฉํ•ด์„œ ๊ด‘๋ฒ”์œ„ ํ•˜๊ฒŒ ํšจ๊ณผ๋ฅผ ์ฃผ๊ณ , ๊ทธ ์ค‘์—์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌํ•˜๊ณ  ์‹ถ์€ ํƒœ๊ทธ๋“ค์„ id ์„ ํƒ์ž๋กœ ํšจ๊ณผ๋ฅผ ์ค€๋‹ค.

 

  • css ํŒŒ์ผ ๋ถ„๋ฆฌ: html ํŒŒ์ผ์ด ์žˆ๋Š” ๊ฐ™์€ ํด๋”์— cssํŒŒ์ผ ๋งŒ๋“ค๊ณ , head์— ํƒœ๊ทธ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
<link rel="stylesheet" type="text/css" href = "(cssํŒŒ์ผ์ด๋ฆ„).css">

 

์ž์ฃผ์“ฐ์ด๋Š” CSS

  • width, height : ๊ตฌ์—ญ์˜ ํฌ๊ธฐ ์ง€์ •
  • color: ๊ธ€์ž ์ƒ‰ ์ง€์ •
  • text-align: text ์ •๋ ฌ ๋ฐฉ๋ฒ•
  • background-image: url(๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ์ €์žฅ ๋งํฌ)
  • background-size: ๋ฐฐ๊ฒฝ ํฌ๊ธฐ ์ง€์ •
  • background-postition: ๋ฐฐ๊ฒฝ ์œ„์น˜
  • background-image, background-size, background-position ์„ธ๊ฐœ ๊ฐ™์ด ๋‹ค๋‹˜
  • border-radius: ํ…Œ๋‘๋ฆฌ๋ฅผ ๋‘ฅ๊ธ€๊ฒŒ ๋งŒ๋“œ๋Š” ์†์„ฑ
  • margin:  ์œ„ ์˜ค๋ฅธ์ชฝ ์•„๋ž˜ ์™ผ์ชฝ ์ˆœ์„œ๋กœ ๋ฐ”๊นฅ ์—ฌ๋ฐฑ ์ง€์ • 
/* 20px 20px 20x 20px์™€ ๊ฐ™์Œ ์œ„ ์˜ค๋ฅธ์ชฝ ์•„๋ž˜ ์™ผ์ชฝ 20px์”ฉ ๋„์–ด๋ผ*/
margin: 20px

/* ์œ„20px ์˜ค๋ฅธ์ชฝauto ์•„๋ž˜0px ์™ผ์ชฝauto์”ฉ ๋„์–ด๋ผ*/
margin: 20px auto 0 auto;
  • padding: ์œ„ ์˜ค๋ฅธ์ชฝ ์•„๋ž˜ ์™ผ์ชฝ ์ˆœ์„œ๋กœ ์•ˆ์ชฝ ์—ฌ๋ฐฑ ์ง€์ • 
padding: 5px /* 4๋ฉด์ด ๋ชจ๋‘ 5px */

padding-top:5px;
padding-right:7px;
padding-bottom:3px;
padding-left:0px;

padding: 5px 7px 3px 0px

 

CSS ๊ฟ€ํŒ๋“ค

  • ์ด๋ฏธ์ง€ ์–ด๋‘ก๊ฒŒ ํ•˜๊ธฐ
background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5), url(~.jpg))

 

  • ๋‚ด์šฉ๋ฌผ ๊ฐ€์šด๋ฐ๋กœ ์˜ฎ๊ธฐ๊ธฐ
/* 4๊ฐœ ๊ฐ™์ด ๋‹ค๋‹˜  */
display: flex;
flex-direction: column; 
justify-content: center;
align-items: center;
์—ด ๊ธฐ์ค€์œผ๋กœ ๊ฐ€์šด๋ฐ๋กœ ์˜ฎ๊ธธ๋ ค๋ฉด flex-direction: column;
ํ–‰ ๊ธฐ์ค€์œผ๋กœ ๊ฐ€์šด๋ฐ๋กœ ์˜ฎ๊ธธ๋ ค๋ฉด flex direction: row;

 

  • ๋ฒ„ํŠผ ์œ„๋กœ ๋งˆ์šฐ์Šค ์˜ฌ๋ ธ์„ ๋•Œ ํšจ๊ณผ ๋„ฃ๊ธฐ
.ํด๋ž˜์Šค > button:hover{
   ํšจ๊ณผ
}
/* button์ด hover๋ฌ์„ ๋•Œ ์„ ์ด ๊ตต์–ด์ง€๋Š” ํšจ๊ณผ*/
.mytitle > button:hover{
    /* ๊ฒฝ๊ณ„: ๊ตต๊ธฐ2px ์‹ค์„  ํฐ์ƒ‰ */
    border: 2px solid white;
}

 

  • box shadow
/* none | x-position, y-position, blur, spread, color | inset | initial | inherit*/
box-shadow: 0px 0px 3px 0px gray;
none: ๊ทธ๋ฆผ์ž ํšจ๊ณผ ์—†์• ๊ธฐ
x-position: ๊ฐ€๋กœ ์œ„์น˜. ์–‘์ˆ˜๋ฉด ์˜ค๋ฅธ์ชฝ์—, ์Œ์ˆ˜๋ฉด ์™ผ์ชฝ์— ๊ทธ๋ฆผ์ž๊ฐ€ ๋งŒ๋“ค์–ด์ง„๋‹ค.
y-position: ์„ธ๋กœ ์œ„์น˜. ์–‘์ˆ˜๋ฉด ์•„๋ž˜์ชฝ์—, ์Œ์ˆ˜๋ฉด ์œ„์ชฝ์— ๊ทธ๋ฆผ์ž๊ฐ€ ๋งŒ๋“ค์–ด์ง„๋‹ค.
blur: ๊ทธ๋ฆผ์ž๋ฅผ ํ๋ฆฟํ•˜๊ฒŒ ๋งŒ๋“ ๋‹ค. ๊ฐ’์ด ํด ์ˆ˜๋ก ๋” ํ๋ ค์ง„๋‹ค.
spread: ์–‘์ˆ˜๋ฉด ๊ทธ๋ฆผ์ž๋ฅผ ํ™•์žฅํ•˜๊ณ , ์Œ์ˆ˜๋ฉด ๊ทธ๋ฆผ์ž๋ฅผ ์ถ•์†Œํ•œ๋‹ค.
color: ๊ทธ๋ฆผ์ž ์ƒ‰
inset: ๊ทธ๋ฆผ์ž๋ฅผ ์š”์†Œ์˜ ์•ˆ์ชฝ์— ๋งŒ๋“ ๋‹ค.
initial: ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.
inherit: ๋ถ€๋ชจ ์š”์†Œ์˜ ์†์„ฑ๊ฐ’์„ ์ƒ์†๋ฐ›๋Š”๋‹ค.

https://www.codingfactory.net/10628 ์ฐธ๊ณ 

 

  • ์ฒ˜์Œ์— ์•ˆ๋‚˜์˜ค๊ฒŒ ํ•˜๊ธฐ
display: none;

 

  • ์ด๋ชจํ‹ฐ์ฝ˜ ๋ชจ์Œ์ง‘
http://emojihomepage.com/

https://kr.piliapp.com/facebook-symbols/

 

  • ๋ชจ๋ฐ”์ผ์—์„œ๋„ ์ž˜๋ณด์ด๋„๋ก ๋„“์ด ์ง€์ •ํ•˜๊ธฐ
/* ์ตœ๋Œ€๋กœ 500px ๊นŒ์ง€๋งŒ ์ปค์งˆ ์ˆ˜ ์žˆ๊ณ  ๊ทธ ์ „๊นŒ์ง€๋Š” 95%๋งŒ ์ฑ„์›Œ์ง€๋ฉด ๋˜*/
max-width: 500px;
width: 95%;
max-width๋กœ ์ตœ๋Œ€ ๋„“์ด๋ฅผ ์ง€์ •ํ•˜๊ณ ,
์ตœ๋Œ€ ๋„“์ด๋ณด๋‹ค ์ž‘์€ ๋„“์ด๋ฅผ ๊ฐ€์ง€๋Š” display์—์„œ ๋ช‡ %๋กœ ๋ณด์ผ์ง€ width๋กœ ์ง€์ •ํ•œ๋‹ค.

 

๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์‚ฌ์šฉํ•˜๊ธฐ

https://getbootstrap.com/

 

Bootstrap

The most popular HTML, CSS, and JS library in the world.

getbootstrap.com

  • ๋ถ€ํŠธ์ŠคํŠธ๋žฉ: ์˜ˆ์œ CSS๋ฅผ ๋ฏธ๋ฆฌ ๋ชจ์•„๋‘” ๊ฒƒ
  • bootstrap ์ ์šฉ์€ CSS ํŒŒ์ผ ๋ถ„๋ฆฌ์™€ ์›๋ฆฌ๊ฐ€ ๋™์ผ (CSS์˜ ํŒŒ์ผ์ด ์ธํ„ฐ๋„ท ์–ด๋”˜๊ฐ€์— ์žˆ๋‹ค๋Š” ์ ์ด ๋‹ค๋ฆ„)

 


Source