WEB/HTML+CSS+JS

CSS ๋‚ด์šฉ์ •๋ฆฌ - 3

kite707 2020. 12. 30.

div ์™€ span ํƒœ๊ทธ 

divํƒœ๊ทธ๋Š” block level element์ด๊ณ  spanํƒœ๊ทธ๋Š” inline element์ด๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ์™€ ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ž.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <div>NAVIGATION</div>
    <div>ARTICLE</div>
  </body>
</html>

div ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ ๊ฒฐ๊ณผ

์ €๊ธฐ์„œ div๋ฅผ span์œผ๋กœ ๋ฐ”๊ฟ”์ฃผ๋ฉด? ์•„๋ž˜์™€ ๊ฐ™์ด ๋œ๋‹ค.

span ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ ๊ฒฐ๊ณผ

grid ๊ธฐ๋ณธ๊ฐœ๋… ์ •๋ฆฌ 

CSS์˜ grid๊ธฐ๋Šฅ์„ ์ด์šฉํ•˜๋ฉด ๋‹ค์–‘ํ•œ ๋ ˆ์ด์•„์›ƒ๋“ค์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ์ €๋ฒˆ์‹œ๊ฐ„์— ์šฐ๋ฆฌ๊ฐ€ ๋งŒ๋“ค๊ณ ์ž ํ–ˆ๋˜ ์‚ฌ์ดํŠธ์—์„œ CSS๊ด€๋ จ ๊ธ€์„ ์นธ ์˜†์— ๋‚˜๋ž€ํžˆ ๋ฐฐ์น˜ํ•˜๊ธฐ ์œ„ํ•ด ์ด ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋‹ค.

 

grid๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋จผ์ € ๋ฐฐ์น˜ํ•  ์•„์ดํ…œ๋“ค(๊ตฌ์„ฑ์š”์†Œ, ์ฆ‰ ๋ฐฐ์น˜ํ•˜๊ณ  ์‹ถ์€ ๊ฒƒ๋“ค)์„ ๊ทธ๋ฆฌ๋“œ ์ปจํ…Œ์ด๋„ˆ๋กœ ๊ฐ์‹ธ์ค˜์•ผ ํ•œ๋‹ค. ์ง์ ‘ ์ฝ”๋“œ๋ฅผ ๋ณด๋„๋ก ํ•˜์ž.

ํ‘œ์‹œ๋œ 18๋ฒˆ๊ณผ 21๋ฒˆ์ค„์ด ๊ทธ๋ฆฌ๋“œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ง€์ •ํ•˜๋Š” ๋ถ€๋ถ„๋“ค์ด๋‹ค.

๊ทธ๋ฆฌ๊ณ  7๋ฒˆ์งธ ์ค„๋ถ€ํ„ฐ {}๋กœ ๋ฌถ์—ฌ์žˆ๋Š” ๋ถ€๋ถ„๋“ค์ด ๋ฐฐ์น˜๋ฅผ ํ•˜๋Š” ๋ถ€๋ถ„์ด๋‹ค. 

๋จผ์ € ๊ทธ๋ฆฌ๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ์œ„ํ•ด ์ปจํ…Œ์ด๋„ˆ์— ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ๊ผญ ์ž‘์„ฑํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ๊ทธ๋ฆฌ๋“œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ •์˜ํ•˜๊ธฐ ์œ„ํ•œ ์ฝ”๋“œ์ด๋‹ค.

display:grid;

 ๊ทธ๋ฆฌ๊ณ  ๋‹ค์Œ์œผ๋กœ ์•„์ดํ…œ๋“ค์„ ๋ฐฐ์น˜ํ•ด๋ณด์ž. ๋ฐฉ๋ฒ•์€ ๋‘๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค. columns์ˆœ์œผ๋กœ ๋ฐฐ์น˜ํ•˜๊ฑฐ๋‚˜ row์ˆœ์œผ๋กœ ๋ฐฐ์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค. 

์ฆ‰ column ์ˆœ์œผ๋กœ ๋ฐฐ์น˜ํ•˜๋ฉด ๊ฐ€๋กœ๋กœ, row์ˆœ์œผ๋กœ ๋ฐฐ์น˜ํ•˜๋ฉด ์„ธ๋กœ๋กœ ์ˆœ์„œ๋Œ€๋กœ ๋†“์ด๊ฒŒ ๋œ๋‹ค.

์šฐ๋ฆฌ๋Š” ๊ฐ€๋กœ๋กœ ๋‚ด์šฉ์„ ๋ฐฐ์น˜ํ•  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— column์ˆœ์œผ๋กœ ๋ฐฐ์น˜ํ•  ๊ฒƒ์ด๋‹ค. ์ด๋Ÿด๋•Œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•ด์ค€๋‹ค.

grid-template-columns: (์ฒซ๋ฒˆ์งธ ์•„์ดํ…œ์ด ์ฐจ์ง€ํ•˜๋Š” ๊ณต๊ฐ„ํฌ๊ธฐ) (๋‘๋ฒˆ์งธ ") (์„ธ๋ฒˆ์งธ ") ...

row์ˆœ์œผ๋กœ ๋ฐฐ์น˜ํ•˜๋ ค๋ฉด columns๋ถ€๋ถ„์„ row๋กœ๋งŒ ๋ฐ”๊พธ๊ณ  ๋˜‘๊ฐ™์ด ์จ์ฃผ๋ฉด ๋œ๋‹ค.

ํฌ๊ธฐ๋Š” OOOpx ์ด๋ ‡๊ฒŒ ํฌ๊ธฐ๋ฅผ ์ž‘์„ฑํ•˜๊ฑฐ๋‚˜ fr(fraction - ์ผ๋ถ€)์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ์ œ๋ฅผ ๋ณด๋ฉด ์ดํ•ด๊ฐ€ ์‰ฌ์šธ๊ฒƒ์ด๋‹ค.

 

๋จผ์ € ์œ„์—์„œ ๋ณธ ์ฝ”๋“œ์˜ ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ž.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      #grid{
        border:5px solid pink;
        display:grid;
        grid-template-columns: 150px 1fr;
      }
      div{
        border:5px solid gray;
      }
    </style>
  </head>
  <body>
    <div id="grid">
    <div>NAVIGATION</div>
    <div>ARTICLE</div>
    </div>
  </body>
</html>

์ด๋ ‡๊ฒŒ ์ฒซ๋ฒˆ์งธ  column์˜ ํฌ๊ธฐ๋Š” ๊ณ ์ •๋˜๊ณ  ๋‘๋ฒˆ์งธ column์˜ ํฌ๊ธฐ๋Š” ํŽ˜์ด์ง€ ํฌ๊ธฐ์— ๋”ฐ๋ผ ๋ฐ”๋€๋‹ค.

์ด์ œ fr์„ ์‚ฌ์šฉํ•œ ์˜ˆ์ œ๋ฅผ ๋ณด์ž. ์ฝ”๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      #grid{
        border:5px solid pink;
        display:grid;
        grid-template-columns: 1fr 2fr 1fr;
      }
      div{
        border:5px solid gray;
      }
    </style>
  </head>
  <body>
    <div id="grid">
    <div>NAVIGATION</div>
    <div>ARTICLE</div>
    <div>HAHAHAHA</div>
    </div>
  </body>
</html>

์ด๋Ÿด๊ฒฝ์šฐ ํ™”๋ฉด์„ 1 : 2 : 1 ๋กœ ๋ถ„ํ• ํ•˜์—ฌ ์ฐจ์ง€ํ•˜๊ฒŒ ๋œ๋‹ค.

 

caniuse ์‚ฌ์ดํŠธ ์†Œ๊ฐœ 

๊ฐ•์˜๋ฅผ ๋“ฃ๋‹ค๋ณด๋‹ˆ ์œ ์šฉํ•œ ์‚ฌ์ดํŠธ๋ฅผ ์†Œ๊ฐœํ•ด์ฃผ์…”์„œ ์—ฌ๊ธฐ์—๋„ ์ž‘์„ฑํ•˜๋ ค ํ•œ๋‹ค. ๋ฐฉ๊ธˆ ์‚ฌ์šฉํ•œ grid๊ธฐ๋Šฅ์˜ ๊ฒฝ์šฐ์—๋„ ๋ชจ๋“   ์›น๋ธŒ๋ผ์šฐ์ €์—์„œ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜์ง€๋Š” ์•Š๋‹ค. ๊ทธ๋ž˜์„œ ํ•ด๋‹น๊ธฐ๋Šฅ์„ ์–ด๋Š ์›น์‚ฌ์ดํŠธ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€, ๋Œ€๋žต ๋ช‡ %์˜ ์‚ฌ๋žŒ์ด ์ด ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๋ณด์—ฌ์ฃผ๋Š” ์‚ฌ์ดํŠธ๊ฐ€ ์žˆ๋‹ค. 

https://caniuse.com/

 

Can I use... Support tables for HTML5, CSS3, etc

 

caniuse.com

๋ฐฉ๊ธˆ ๋ฐฐ์šด grid๊ธฐ๋Šฅ์„ ๊ฒ€์ƒ‰ํ•ด๋ณด๋ฉด ์ด๋ ‡๊ฒŒ ์–ด๋Š ์›น ๋ธŒ๋ผ์šฐ์ €์—์„œ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•œ์ง€(์ดˆ๋ก) ๋ถˆ๊ฐ€๋Šฅํ•œ์ง€(๋นจ๊ฐ•) ์•Œ ์ˆ˜์žˆ๋‹ค.

 

๊ทธ๋ฆฌ๋“œ ์จ๋จน๊ธฐ

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

<!doctype html>
<html>
<head>
  <title>WEB - CSS</title>
  <meta charset="utf-8">
  <style>
    body{
      margin:0;
    }
    #active {
      color:red;
    }
    .saw {
      color:gray;
    }
    a {
      color:black;
      text-decoration: none;
    }
    h1 {
      font-size:45px;
      text-align: center;
      border-bottom:1px solid gray;
      margin:0;
      padding:20px;
    }
    ol{
      border-right:1px solid gray;
      width:100px;
      margin:0;
      padding:20px;
    }
  </style>
</head>
<body>
  <h1><a href="index.html">WEB</a></h1>
  <ol>
    <li><a href="1.html" class="saw">HTML</a></li>
    <li><a href="2.html" class="saw" id="active">CSS</a></li>
    <li><a href="3.html">JavaScript</a></li>
  </ol>
  <h2>CSS</h2>
  <p>
    Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation of a document written in a markup language.[1] Although most often used to set the visual style of web pages and user interfaces written in HTML and XHTML, the language can be applied to any XML document, including plain XML, SVG and XUL, and is applicable to rendering in speech, or on other media. Along with HTML and JavaScript, CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications.
  </p>
  </body>
  </html>

 

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

<!doctype html>
<html>
<head>
  <title>WEB - CSS</title>
  <meta charset="utf-8">
  <style>
    body{
      margin:0;
    }
    a {
      color:black;
      text-decoration: none;
    }
    h1 {
      font-size:45px;
      text-align: center;
      border-bottom:1px solid gray;
      margin:0;
      padding:20px;
    }
    ol{
      border-right:1px solid gray;
      width:100px;
      margin:0;
      padding:20px;
    }
    #grid{
      display: grid;
      grid-template-columns: 150px 1fr;
    }
    #grid ol{
      padding-left:33px;
    }
    #grid #article{
      padding-left:25px;
    }
  </style>
</head>
<body>
  <h1><a href="index.html">WEB</a></h1>
  <div id="grid">
    <ol>
      <li><a href="1.html">HTML</a></li>
      <li><a href="2.html">CSS</a></li>
      <li><a href="3.html">JavaScript</a></li>
    </ol>
    <div id="article">
        <h2>CSS</h2>
        <p>
          Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation of a document written in a markup language.[1] Although most often used to set the visual style of web pages and user interfaces written in HTML and XHTML, the language can be applied to any XML document, including plain XML, SVG and XUL, and is applicable to rendering in speech, or on other media. Along with HTML and JavaScript, CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications.
        </p>
      </div>
  </div>
  </body>
  </html>

'WEB > HTML+CSS+JS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

CSS ๋‚ด์šฉ์ •๋ฆฌ - ์„ ํƒ์ž  (0) 2020.12.31
CSS ๋‚ด์šฉ์ •๋ฆฌ - 4  (0) 2020.12.31
CSS ๋‚ด์šฉ์ •๋ฆฌ - 2  (0) 2020.12.29
CSS ๋‚ด์šฉ์ •๋ฆฌ - 1  (0) 2020.12.22
HTML ๊ธฐ์ดˆ ๋‚ด์šฉ ์ •๋ฆฌ - 4  (0) 2020.12.06

๋Œ“๊ธ€