8. font 관련 속성들      -바닥부터 시작하는 CSS-

 

font family - font의 특정 이름을 말함.(: "Times New Roman", "Arial" )

generic family : font의 유형에 따라 분류한 것으로 serif(명조계열), sans-serif(고딕계열), monospace(고정 폭을 가진 폰트), fantasy(꾸밈계열), cursive(필기체 계열) 등의 다섯 종류가 있다.

 

1. font-family 속성

wep page에 사용될 font를 지정한다.

여러 개의 font 지정이 가능하며 앞에 있는 것이 우선 지정됨.

없으면 차례로 다음 font 확인하여 적용됨.

맨 뒤에는 generic family를 지정하여 앞서 지정한 font들이 사용자 컴퓨터 시스템에 없을 경우에는 유사 계열의 font로 

대체되게 한다.

font명에 공백이 있으면 반드시 따옴표 사용.

font 명칭은 콤마로 분류한다.

 

8-1

  1. <html>
  2. <head>
  3. <style>
  4. p.serif {
  5. font-family: "Times New Roman", Times, serif;
  6. }
  7. p.sansserif {
  8. font-family: Arial, Helvetica, sans-serif;
  9. }
  10. </style>
  11. </head>
  12. <body>
  13. <h1>CSS font-family</h1>
  14. <p class="serif">Times New Roman font: The snow glows white on the mountain tonight</p>
  15. <p class="sansserif">Arial font: The snow glows white on the mountain tonight</p>
  16. </body>
  17. </html>

 

2. font-style 속성

주로 이탤릭체로 바꿀 때 사용됨.

속성 값: normal, italic, oblique(이탤릭과 거의 같음)

8-2

  1. <html>
  2. <head>
  3. <style>
  4. p.normal {
  5. font-style: normal;
  6. }
  7. p.italic {
  8. font-style: italic;
  9. }
  10. p.oblique {
  11. font-style: oblique;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <p class="normal">normal style: Life is venture or nothing</p>
  17. <p class="italic">italic style: Life is venture or nothing</p>
  18. <p class="oblique">oblique style: Life is venture or nothing</p>
  19. </body>
  20. </html>

 

 

3. font-size 속성

글자의 크기를 절대 값 또는 상대 값으로 지정.

기본 값은 16px=1em.

8-3

  1. <html>
  2. <head>
  3. <style>
  4. h1 {
  5. font-size: 40px;
  6. }
  7. h2 {
  8. font-size: 30px;
  9. }
  10. p {
  11. font-size: 14px;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <h1>heading 1: Whatever you do, make it pay.
  17. </h1>
  18. <h2>heading 2: Whatever you do, make it pay.
  19. </h2>
  20. <p>paragraph1: Do not count the eggs beore they hatch.</p>
  21. <p>paragraph2: Do not count the eggs beore they hatch.</p>
  22. </body>
  23. </html>

See the Pen CSS 8-3 by byungchoo (@byungchoo) on CodePen.

Tip: px를 사용하면 브라우저의 pagezoom시킬 때 글자도 커진다.

em을 사용하면 브라우저 메뉴 중 resize text를 사용해 크기조절이 가능.

 

8-4

  1. <html>
  2. <head>
  3. <style>
  4. h1 {
  5. font-size: 2.5em;
  6. /* 40px/16=2.5em */
  7. }
  8. h2 {
  9. font-size: 1.875em;
  10. /* 30px/16=1.875em */
  11. }
  12. p {
  13. font-size: 0.875em;
  14. /* 14px/16=0.875em */
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <h1>This is heading 1</h1>
  20. <h2>This is heading 2</h2>
  21. <p>This is a paragraph.</p>
  22. <p>Specifying the font-size in em allows all major browsers to resize the text.
  23. Unfortunately, there is still a problem with older versions of IE. When resizing
  24. the text, it becomes larger/smaller than it should.</p>
  25. </body>
  26. </html>

 

<body> 태그에 font-size%를 지정하고 다른 부분에 em을 사용함으로 구 버전 IE에서 발생하는 문제를 해결할 수 있다.

8-5

  1. <html>
  2. <head>
  3. <style>
  4. body {
  5. font-size: 100%;
  6. }
  7. h1 {
  8. font-size: 2.5em;
  9. }
  10. h2 {
  11. font-size: 1.875em;
  12. }
  13. p {
  14. font-size: 0.875em;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <h1>heading 1: Pain past is pleasure.</h1>
  20. <h2>heading 2: Pain past is pleasure.</h2>
  21. <p>This is a paragraph: Step by step goes a long way.</p>
  22. <p>Specifying the font-size in percent and em displays the same size in all
  23. major browsers, and allows all browsers to resize the text!</p>
  24. </body>
  25. </html>

이렇게 하면 모든 브라우저에서 같은 크기의 글자를 출력할 수 있고 zoomresize 도 가능하다.

 


4. font-weight 속성

font의 두께를 지정한다.

normal, bolder, bold( <b> 태그와 동일), lighter

숫자를 이용한 경우 : 100(가장 가늘게)~400(normal)~900(가장 굵게)

8-6

  1. <html>
  2. <head>
  3. <style>
  4. p.normal {
  5. font-weight: normal;
  6. }
  7. p.light {
  8. font-weight: lighter;
  9. }
  10. p.thick {
  11. font-weight: bold;
  12. }
  13. p.thicker {
  14. font-weight: 900;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <p class="normal">Rome was not built in a day.</p>
  20. <p class="light">Rome was not built in a day.</p>
  21. <p class="thick">Rome was not built in a day.</p>
  22. <p class="thicker">Rome was not built in a day.</p>
  23. </body>
  24. </html>

 

5. font-variant 속성

normal, small-caps(영문 소문자를 작은 대문자로 바꿈)

8-7

  1. <html>
  2. <head>
  3. <style>
  4. p.normal {
  5. font-variant: normal;
  6. }
  7. p.small {
  8. font-variant: small-caps;
  9. }
  10. </style>
  11. </head>
  12. <body>
  13. <p class="normal">Little by Little Does the Trick.</p>
  14. <p class="small">Little by Little Does the Trick.</p>
  15. </body>
  16. </html>


Posted by star story :

Snippet :: Code View :: "+location.href+'
'+b+"

");top.consoleRef.document.close()}$(".snippet-container").each(function(b){$(this).find("a.snippet-text").click(function(){var d=$(this).parents(".snippet-wrap").find(".snippet-formatted");var c=$(this).parents(".snippet-wrap").find(".snippet-textonly");d.toggle();c.toggle();if(c.is(":visible")){$(this).html("html")}else{$(this).html("text")}return false});$(this).find("a.snippet-window").click(function(){var c=$(this).parents(".snippet-wrap").find(".snippet-textonly").html();a(c);$(this).blur();return false})});$(".snippet-toggle").each(function(b){$(this).click(function(){$(this).parents(".snippet-container").find(".snippet-wrap").toggle()})})});