Text

1. ๊ฐœ์š”

ํ…์ŠคํŠธ ์Šคํƒ€์ผ์€ ์‚ฌ์šฉํ•˜๋Š” ๊ธ€์ž์˜ ๋ชจ์–‘์ƒˆ๋ฅผ ์ง€์ •ํ•˜๋Š” ๊ธ€๊ผด ์Šคํƒ€์ผ๊ณผ ์›น ๋ฌธ์„œ์— ํ‘œ์‹œ๋˜๋Š” ํ…์ŠคํŠธ๋ฅผ ์ง€์ •ํ•˜๋Š” ๋ฌธ๋‹จ ์Šคํƒ€์ผ์ด ์žˆ๋‹ค.


2. line-height ํ”„๋กœํผํ‹ฐ

ํ…์ŠคํŠธ์˜ ๋†’์ด๋ฅผ ์ง€์ •ํ•œ๋‹ค. ํ•œ ๋ฌธ๋‹จ์ด ๋‘ ์ค„์ด ๋„˜์œผ๋ฉด ์ค„ ๊ฐ„๊ฒฉ์ด ์ƒ๊ธด๋‹ค. ์ค„ ๊ฐ„๊ฒฉ์ด ๋„ˆ๋ฌด ์ข๊ฑฐ๋‚˜ ๋„“์œผ๋ฉด ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง„๋‹ค. ์ด๋•Œ line-height ์†์„ฑ์„ ์ด์šฉํ•˜๋ฉด ์ค„ ๊ฐ„๊ฒฉ์„ ์›ํ•˜๋Š” ๋งŒํผ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ๋‹ค.

<!DOCTYPE html>
<html>
  <head>
    <style>
      .small {
        line-height: 70%;
      }
      .large {
        line-height: 1.5;
      }
      .x-large {
        line-height: 3;
      }
    </style>
  </head>
  <body>
    <p>
      ๊ธฐ๋ณธ ์ค„ ๊ฐ„๊ฒฉ<br />
      ๊ธฐ๋ณธ ์ค„ ๊ฐ„๊ฒฉ<br />
    </p>
    <p class="small">
      ์ข์€ ์ค„ ๊ฐ„๊ฒฉ<br />
      ์ข์€ ์ค„ ๊ฐ„๊ฒฉ<br />
      line-height: 70%
    </p>
    <p class="large">
      ํฐ ์ค„ ๊ฐ„๊ฒฉ<br />
      ํฐ ์ค„ ๊ฐ„๊ฒฉ<br />
      line-height: 1.5
    </p>
    <p class="x-large">
      ๋งค์šฐ ํฐ ์ค„ ๊ฐ„๊ฒฉ<br />
      ๋งค์šฐ ํฐ ์ค„ ๊ฐ„๊ฒฉ<br />
      line-height: 3
    </p>
  </body>
</html>

๋‹ค์Œ์€ ์ˆ˜์ง ์ค‘์–‘ ์ •๋ ฌ ์˜ˆ์ œ์ด๋‹ค. a์š”์†Œ์˜ line-height ๊ฐ’๊ณผ a์š”์†Œ๋ฅผ ๊ฐ์‹ธ๋Š” div ์š”์†Œ์˜ height ๊ฐ’์„ ์ผ์น˜์‹œํ‚จ๋‹ค.

<!DOCTYPE html>
<html>
  <head>
    <style>
      .btn {
        width: 80px;
        height: 40px;
        background-color: orchid;
        border-radius: 40px;
      }
      .btn > a {
        display: block;
        color: aliceblue;
        text-align: center;
        text-decoration: none;
        line-height: 40px;
      }
    </style>
  </head>
  <body>
    <div class="btn">
      <a class="btn" href="#">Click</a>
    </div>
  </body>
</html>

3. letter-spacing ํ”„๋กœํผํ‹ฐ

๊ธ€์ž ์‚ฌ์ด์˜ ๊ฐ„๊ฒฉ์„ ์ง€์ •ํ•œ๋‹ค.

<!DOCTYPE html>
<html>
  <head>
    <style>
      .ex1 {
        letter-spacing: -2px;
      }
      .ex2 {
        letter-spacing: 2px;
      }
      .ex3 {
        letter-spacing: 10px;
      }
    </style>
  </head>
  <body>
    <p>default letter spacing</p>
    <p class="ex1">letter-spacing: -2px</p>
    <p class="ex2">letter-spacing: 2px</p>
    <p class="ex3">letter-spacing: 10px</p>
  </body>
</html>

4. text-align ํ”„๋กœํผํ‹ฐ

ํ…์ŠคํŠธ์˜ ์ˆ˜ํ‰ ์ •๋ ฌ์„ ์ •์˜ํ•œ๋‹ค. ํ•œ๊ธ€ ๋ฌธ์„œ์—์„œ ํ”ํžˆ ์‚ฌ์šฉํ•˜๋Š” ์™ผ์ชฝ ์ •๋ ฌ, ์˜ค๋ฅธ์ชฝ ์ •๋ ฌ, ์–‘์ชฝ ์ •๋ ฌ, ๊ฐ€์šด๋ฐ ์ •๋ ฌ ๋“ฑ์„ ์›น ๋ฌธ์„œ์—์„œ๋„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

์•„๋ž˜์˜ ํ‘œ๋Š” text-align์˜ ํ”„๋กœํผํ‹ฐ๊ฐ’์ด๋‹ค.

์ข…๋ฅ˜
์„ค๋ช…

start

ํ˜„์žฌ ํ…์ŠคํŠธ ์ค„์˜ ์‹œ์ž‘ ์œ„์น˜์— ๋งž์ถ”์–ด ๋ฌธ๋‹จ์„ ์ •๋ ฌํ•œ๋‹ค.

end

ํ˜„์žฌ ํ…์ŠคํŠธ ์ค„์˜ ๋ ์œ„์น˜์— ๋งž์ถ”์–ด ๋ฌธ๋‹จ์„ ์ •๋ ฌํ•œ๋‹ค.

left

์™ผ์ชฝ์— ๋งž์ถ”์–ด ๋ฌธ๋‹จ์„ ์ •๋ ฌํ•œ๋‹ค.

right

์˜ค๋ฅธ์ชฝ์— ๋งž์ถ”์–ด ๋ฌธ๋‹จ์„ ์ •๋ ฌํ•œ๋‹ค.

center

๊ฐ€์šด๋ฐ์— ๋งž์ถ”์–ด ๋ฌธ๋‹จ์„ ์ •๋ ฌํ•œ๋‹ค.

justify

์–‘์ชฝ์— ๋งž์ถ”์–ด ๋ฌธ๋‹จ์„ ์ •๋ ฌํ•œ๋‹ค.

match-parent

๋ถ€๋ชจ ์š”์†Œ๋ฅผ ๋”ฐ๋ผ ๋ฌธ๋‹จ์„ ์ •๋ ฌํ•œ๋‹ค.

<!DOCTYPE html>
<html>
  <head>
    <style>
      p {
        background-color: antiquewhite;
      }
      .start {
        text-align: start;
      }
      .end {
        text-align: end;
      }
      .left {
        text-align: left;
      }
      .right {
        text-align: right;
      }
      .center {
        text-align: center;
      }
      .justify {
        text-align: justify;
      }
    </style>
  </head>
  <body>
    <p class="start">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio esse in
      amet quos aliquam temporibus dicta adipisci, magnam, corrupti velit quis
      fugiat voluptatum provident possimus assumenda quaerat totam delectus
      tempore.
    </p>
    <p class="end">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio esse in
      amet quos aliquam temporibus dicta adipisci, magnam, corrupti velit quis
      fugiat voluptatum provident possimus assumenda quaerat totam delectus
      tempore.
    </p>
    <p class="left">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio esse in
      amet quos aliquam temporibus dicta adipisci, magnam, corrupti velit quis
      fugiat voluptatum provident possimus assumenda quaerat totam delectus
      tempore.
    </p>
    <p class="right">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio esse in
      amet quos aliquam temporibus dicta adipisci, magnam, corrupti velit quis
      fugiat voluptatum provident possimus assumenda quaerat totam delectus
      tempore.
    </p>
    <p class="center">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio esse in
      amet quos aliquam temporibus dicta adipisci, magnam, corrupti velit quis
      fugiat voluptatum provident possimus assumenda quaerat totam delectus
      tempore.
    </p>
    <p class="justify">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio esse in
      amet quos aliquam temporibus dicta adipisci, magnam, corrupti velit quis
      fugiat voluptatum provident possimus assumenda quaerat totam delectus
      tempore.
    </p>
  </body>
</html>

5. text-decoration ํ”„๋กœํผํ‹ฐ

text-decoration ํ”„๋กœํผํ‹ฐ๋Š” ํ…์ŠคํŠธ์— ๋ฐ‘์ค„์„ ๊ธ‹๊ฑฐ๋‚˜ ์ทจ์†Œ์„ ์„ ํ‘œ์‹œํ•œ๋‹ค. ๋งํฌ์˜ underline๋ฅผ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ํ…์ŠคํŠธ์— underline, overline, line-through๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

<!DOCTYPE html>
<html>
  <head>
    <style>
      a {
        text-decoration: none;
      }
      p:nth-of-type(1) {
        text-decoration: overline;
      }
      p:nth-of-type(2) {
        text-decoration: line-through;
      }
      p:last-child {
        text-decoration: underline;
      }
    </style>
  </head>
  <body>
    <a href="#">text-decoratoin: none</a>
    <p>text-decoration: overline</p>
    <p>text-decoration: line-through</p>
    <p>text-decoration: underline</p>
  </body>
</html>

6. white-space ํ”„๋กœํผํ‹ฐ

white space๋Š” ๊ณต๋ฐฑ(space), ๋“ค์—ฌ์“ฐ๊ธฐ(tab), ์ค„๋ฐ”๊ฟˆ(line break)์„ ์˜๋ฏธํ•œ๋‹ค. html์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์—ฐ์†๋œ ๊ณต๋ฐฑ, ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” 1๋ฒˆ๋งŒ ์‹คํ–‰๋˜๋ฉฐ ์ค„๋ฐ”๊ฟˆ์€ ๋ฌด์‹œ๋œ๋‹ค. ๋˜ํ•œ ํ…์ŠคํŠธ๋Š” ๋ถ€๋ชจ์˜ ๊ฐ€๋กœ ์˜์—ญ์„ ๋ฒ—์–ด๋‚˜์ง€ ์•Š๊ณ  ์ž๋™ ์ค„๋ฐ”๊ฟˆ(wrap)๋œ๋‹ค. white-space ํ”„๋กœํผํ‹ฐ๋Š” ์ด๋Ÿฌํ•œ ๊ธฐ๋ณธ ๋™์ž‘์„ ์ œ์–ดํ•˜๊ธฐ ์œ„ํ•œ ํ”„๋กœํผํ‹ฐ๋‹ค.

ํ”„๋กœํผํ‹ฐ
line break
space/tab
wrapping(์ž๋™์ค„๋ฐ”๊ฟˆ)

normal

๋ฌด์‹œ

1๋ฒˆ๋งŒ ๋ฐ˜์˜

O

nowrap

๋ฌด์‹œ

1๋ฒˆ๋งŒ ๋ฐ˜์˜

X

pre

๋ฐ˜์˜

๊ทธ๋Œ€๋กœ ๋ฐ˜์˜

X

pre-wrap

๋ฐ˜์˜

๊ทธ๋Œ€๋กœ ๋ฐ˜์˜

O

pre-line

๋ฐ˜์˜

1๋ฒˆ๋งŒ ๋ฐ˜์˜

O

<!DOCTYPE html>
<html>
  <head>
    <style>
      body {
        display: grid;
        grid-template-columns: 1fr 1fr;
      }
      div {
        width: 150px;
        height: 150px;
        border: 1px solid blueviolet;
        margin-bottom: 120px;
      }
      h3 {
        margin: 0;
      }
      .nomal {
        white-space: normal;
      }
      .nowrap {
        white-space: nowrap;
      }
      .pre {
        white-space: pre;
      }
      .pre-wrap {
        white-space: pre-wrap;
      }
      .pre-line {
        white-space: pre-line;
      }
    </style>
  </head>
  <body>
    <div class="nomal">
      <h3>normal</h3>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore quo hic
      aspernatur deserunt veritatis nemo, facilis totam autem laborum tempora
      distinctio quae cum ut maxime obcaecati eligendi porro vitae praesentium.
    </div>
    <div class="nowrap">
      <h3>nowrap</h3>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore quo hic
      aspernatur deserunt veritatis nemo, facilis totam autem laborum tempora
      distinctio quae cum ut maxime obcaecati eligendi porro vitae praesentium.
    </div>
    <div class="pre">
      <h3>pre</h3>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore quo hic
      aspernatur deserunt veritatis nemo, facilis totam autem laborum tempora
      distinctio quae cum ut maxime obcaecati eligendi porro vitae praesentium.
    </div>
    <div class="pre-wrap">
      <h3>pre-wrap</h3>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore quo hic
      aspernatur deserunt veritatis nemo, facilis totam autem laborum tempora
      distinctio quae cum ut maxime obcaecati eligendi porro vitae praesentium.
    </div>
    <div class="pre-line">
      <h3>pre-line</h3>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore quo hic
      aspernatur deserunt veritatis nemo, facilis totam autem laborum tempora
      distinctio quae cum ut maxime obcaecati eligendi porro vitae praesentium.
    </div>
  </body>
</html>

7. text-overflow ํ”„๋กœํผํ‹ฐ

๋ถ€๋ชจ ์˜์—ฌ๊ธใ„น ๋ฒ—์–ด๋‚œ wrapping(์ž๋™์ค„๋ฐ”๊ฟˆ)์ด ๋˜์ง€ ์•Š์€ ํ…์ŠคํŠธ์˜ ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ•์„ ์ •์˜ํ•œ๋‹ค.

  • ์กฐ๊ฑด

    • width ํ”„๋กœํผํ‹ฐ๊ฐ€ ์ง€์ •๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ block๋ ˆ๋ฒจ ์š”์†Œ๋กœ ๋ณ€๊ฒฝํ•ด์•ผ ํ•œ๋‹ค.

    • ์ž๋™ ์ค„๋ฐ”๊ฟˆ์„ ๋ฐฉ์ง€ํ•˜๋ ค๋ฉด white-space ํ”„๋กœํผํ‹ฐ๋ฅผ nowrap์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.

    • overflow ํ”„๋กœํผํ‹ฐ์— ๋ฐ˜๋“œ์‹œ visible ์ด์™ธ์˜ ๊ฐ’์ด ์ง€์ •๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.

์•„๋ž˜๋Š” text-overflow ํ”„๋กœํผํ‹ฐ์— ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœํผํ‹ฐ ๊ฐ’์ด๋‹ค.

ํ”„๋กœํผํ‹ฐ ๊ฐ’
์„ค๋ช…

clip

์˜์—ญ์„ ๋ฒ—์–ด๋‚œ ํ…์ŠคํŠธ๋ฅผ ํ‘œ์‹œํ•˜์ง€ ์•Š๋Š”๋‹ค.(๊ธฐ๋ณธ๊ฐ’)

ellipsis

์˜์—ญ์„ ๋ฒ—์–ด๋‚œ ํ…์ŠคํŠธ๋ฅผ ์ž˜๋ผ๋‚ด์–ด ๋ณด์ด์ง€ ์•Š๊ฒŒ ํ•˜๊ณ  ๋ง์ค„์ž„ํ‘œ(...)๋ฅผ ํ‘œ์‹œํžŒ๋‹ค.

<!DOCTYPE html>
<html>
  <head>
    <style>
      div {
        width: 150px;
        height: 150px;
        border: 1px solid blueviolet;
        white-space: nowrap;
        overflow: hidden;
        display: inline-block;
      }
      h3 {
        margin: 0;
      }
      .clip {
        text-overflow: clip;
      }
      .ellipsis {
        text-overflow: ellipsis;
      }
    </style>
  </head>
  <body>
    <div class="clip">
      <h3>clip</h3>
      Lorem ipsum dolor sit amet consectetur adipisicing elit.
    </div>
    <div class="ellipsis">
      <h3>ellipsis</h3>
      Lorem ipsum dolor sit amet consectetur adipisicing elit.
    </div>
  </body>
</html>

8. word-wrap ํ”„๋กœํผํ‹ฐ

ํ•œ ๋‹จ์–ด์˜ ๊ธธ์ด๊ฐ€ ๊ธธ์–ด์„œ ๋ถ€๋ชจ ์˜์—ญ์„ ๋ฒ—์–ด๋‚œ ํ…์ŠคํŠธ์˜ ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ•์„ ์ •์˜ํ•œ๋‹ค.

์‚ฌ์šฉ๋ฒ• word-wrap: break-word;


9. word-break ํ”„๋กœํผํ‹ฐ

word-wrap ํ”„๋กœํผํ‹ฐ์™€ ๊ฐ™์ด ํ•œ ๋‹จ์–ด์˜ ๊ธธ์ด๊ฐ€ ๊ธธ์–ด์„œ ๋ถ€๋ชจ ์˜์—ญ์„ ๋ฒ—์–ด๋‚œ ํ…์ŠคํŠธ์˜ ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ•์„ ์ •์˜ํ•œ๋‹ค. word-wrap ํ”„๋กœํผํ‹ฐ ๊ฒฝ์šฐ ๋‹จ์–ด๋ฅผ ์–ด๋Š ์ •๋„๋Š” ๊ณ ๋ คํ•˜์—ฌ ๊ฐœํ–‰ํ•˜์ง€๋งŒ word-break: break-all;๋Š” ๋‹จ์–ด๋ฅผ ๊ณ ๋ คํ•˜์ง€ ์•Š๊ณ  ๋ถ€๋ชจ ์˜์—ญ์— ๋งž์ถ”์–ด ๊ฐ•์ œ ๊ฐœํ–‰ํ•œ๋‹ค.

์‚ฌ์šฉ๋ฒ• word-break: break-all;

<!DOCTYPE html>
<html>
  <head>
    <style>
      body {
        display: flex;
        justify-content: space-around;
      }
      div {
        width: 150px;
        height: 300px;
        border: 1px solid black;
        margin-bottom: 10px;
      }
      div:nth-of-type(2) {
        word-wrap: break-word;
      }
      div:nth-of-type(3) {
        word-break: break-all;
      }
    </style>
  </head>
  <body>
    <div>abcdefghijklmnopqrstuvwxyz https://www.teachercan.com/</div>
    <div>
      word-wrap: break-word; abcdefghijklmnopqrstuvwxyz
      https://www.teachercan.com/
    </div>
    <div>
      word-break: break-all; abcdefghijklmnopqrstuvwxyz
      https://www.teachercan.com/
    </div>
  </body>
</html>

10. text-transform ํ”„๋กœํผํ‹ฐ

์˜๋ฌธ์ž๋ฅผ ํ‘œ๊ธฐํ•  ๋•Œ ํ…์ŠคํŠธ์˜ ๋Œ€์†Œ ๋ฌธ์ž๋ฅผ ์›ํ•˜๋Š” ๋Œ€๋กœ ๋ฐ”๊ฟ€ ๋•Œ text-transform ํ”„๋กœํผํ‹ฐ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ํ•œ๊ธ€์—๋Š” ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š๊ณ  ์˜๋ฌธ์ž์—๋งŒ ์ ์šฉ๋œ๋‹ค.

์•„๋ž˜๋Š” text-transform ํ”„๋กœํผํ‹ฐ๊ฐ’์ด๋‹ค.

์ข…๋ฅ˜
์„ค๋ช…

capitalize

๊ฐ ๋‹จ์–ด์˜ ์ฒซ ๋ฒˆ์งธ ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.

uppercase

๋ชจ๋“  ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.

lowercase

๋ชจ๋“  ๊ธ€์ž๋ฅผ ์†Œ๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.

<!DOCTYPE html>
<html>
  <head>
    <style>
      body {
        display: flex;
        justify-content: space-around;
      }
      .ex1 {
        text-transform: capitalize;
      }
      .ex2 {
        text-transform: uppercase;
      }
      .ex3 {
        text-transform: lowercase;
      }
    </style>
  </head>
  <body>
    <span class="ex1">hello world</span>
    <span class="ex2">hello world</span>
    <span class="ex3">HELLOW WORLD</span>
  </body>
</html>

11. Conclusion

text๊ด€๋ จ ํ”„๋กœํผํ‹ฐ๋„ ๋งŽ์ด ์‚ฌ์šฉ์„ ํ–ˆ์ง€๋งŒ white-space, text-overflow, word-wrap, word-break ํ”„๋กœํผํ‹ฐ๋Š” ํ‹ฐ์ฒ˜์บ”์„ ๋งŒ๋“ค ๋•Œ๋งŒ ์‚ฌ์šฉํ•˜์—ฌ ์ต์ˆ™ํ•˜์ง€ ์•Š๋Š” ํ”„๋กœํผํ‹ฐ์ด๋‹ค. ๊ทธ๋งŒํผ ๋‹ค๋ฅธ ํ”„๋กœํผํ„ฐ์— ๋น„ํ•ด ๋น„์ค‘์ด ๋–จ์–ด์ง€๋Š” ๊ฑฐ ๊ฐ™๋‹ค. ํ•˜์ง€๋งŒ ์›น ํŽ˜์ด์ง€๋ฅผ ๋งŒ๋“ค๋ฉด์„œ ํ•„์š”ํ•œ ์ƒํ™ฉ์ด ์˜ฌ ์ˆ˜ ์žˆ๊ธฐ์— ํ•ด๋‹น ํ”„๋กœํผํ‹ฐ์˜ ํŠน์ง•์„ ์ž˜ ์•Œ์•„๋‘๊ณ  ์žˆ์ž.


์ฐธ๊ณ 

poiemaweb 2-7 ํฐํŠธ์™€ ํ…์ŠคํŠธ ๋„์„œ - HTML + CSS + ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์›น ํ‘œ์ค€์˜ ์ •์„


๐Ÿ‘†

๐Ÿ“… 2022-07-19

Last updated