CSS๋ฅผ HTML๋ฌธ์„œ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋„ค๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ์ค‘์—์„œ๋„ ๊ฐ€์žฅ ๋งŽ์ด ์“ฐ์ด๋Š” ๋ฐฉ๋ฒ•์€ inline CSS์™€ External CSS.

1. Embedded CSS - The <style> Element:

 <style> ์š”์†Œ๋ฅผ ์ด์šฉํ•ด์„œ <head>...</head> ํƒœ๊ทธ ๋‚ด์— ์‚ฝ์ž…ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. 

<head>
<style type="text/css" media="...">
Style Rules
............
</style>
</head>

์†์„ฑ:

 <style> ํƒœ๊ทธ ๋‚ด์˜ ์†์„ฑ๊ณผ ๊ฐ’์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Attribute Value Description
type text/css Specifies the style sheet language as a content-type (MIME type). This is required attribute.
media screen
tty
tv
projection
handheld
print
braille
aural
all
Specifies the device the document will be displayed on. Default value is all. This is optional attribute.

์˜ˆ์ œ:

<head>
<style type="text/css" media="all">
h1{
color: #36C;
}
</style>
</head>

2. Inline CSS - The style Attribute:

์ธ๋ผ์ธ CSS๋Š” ๊ทธ๋ƒฅ htmlํƒœ๊ทธ ์•ˆ์—๋‹ค๊ฐ€ ์จ๋„ฃ๋Š” ๊ฒƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์œผ๋กœ ์ด๋ ‡๊ฒŒ ์‚ฌ์šฉํ•˜์ฃ . ๊ทธ๋Ÿฌ๋‹ค๊ฐ€ ๋”ฐ๋กœ ๋ถ„๋ฆฌํ•ด์„œ ๊ด€๋ฆฌํ•ด์•ผ๋˜๋Š” ์Šคํƒ€์ผ์ด ์žˆ๋‹ค๋ฉด ์ด ๋‹ค์Œ์— ์„ค๋ช…ํ•œ External CSS๋ฅผ ์ด์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 

<element style="...style rules....">

์†์„ฑ:

Attribute Value Description
style style rules The value of style attribute is a combination of style declarations separated by semicolon (;).

์˜ˆ์ œ:

<h1 style ="color:#36C;"> This is inline CSS </h1>

 

์ ์šฉ๋œ ๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

This is inline CSS

3. External CSS - The <link> Element:

 <link> ์š”์†Œ๋ฅผ ์ด์šฉํ•˜์—ฌ HTML ๋ฌธ์„œ์— ์™ธ๋ถ€์—์„œ ์ •์˜๋œ CSSํŒŒ์ผ์„ ๋งํฌ์‹œํ‚ฌ ์ˆ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. 

๊ฐ„๋‹จํ•œ ๋ฌธ๋ฒ•์„ ํ•œ๋ฒˆ ๋ณผ๊นŒ์š”??

<head>
<link type="text/css" href="..." media="..." />
</head>

์†์„ฑ:

 <link> ํƒœ๊ทธ์˜ ์†์„ฑ๊ณผ ์†์„ฑ๊ฐ’๋“ค ์ž…๋‹ˆ๋‹ค. 

Attribute Value Description
type text/css Specifies the style sheet language as a content-type (MIME type). This attribute is required.
href URL Specifies the style sheet file having Style rules. This attribute is a required.
media screen
tty
tv
projection
handheld
print
braille
aural
all
Specifies the device the document will be displayed on. Default value is all. This is optional attribute.

์˜ˆ์ œ:

๊ฐ„๋‹จํ•˜๊ฒŒ mystyle.css ๋ฅผ ๋งŒ๋“ค์–ด ๋ด…์‹œ๋‹ค.

h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}

 

์ด์ œ mystyle.cssํŒŒ์ผ์„ HTML๋ฌธ์„œ์— ๋งํฌ๋ฅผ ์‹œ์ผœ๋ณผ๊นŒ์š”??

<head>
<link type="text/css" href="mystyle.css" media="all" />
</head>

4. Imported CSS - @import Rule:

@import ๋ฅผ ์ด์šฉํ•ด์„œ <link> ์š”์†Œ์ฒ˜๋Ÿผ ์Šคํƒ€์ผํŒŒ์ผ์— ๋งํฌ๋ฅผ ๊ฑธ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.  ๊ธฐ๋ณธ๋ฌธ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

<head>
@import "URL";
</head>

 

์•„๋ž˜์ฒ˜๋Ÿผ url()๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

<head>
@import url("URL");
</head>

์˜ˆ์ œ:

<head>
@import "mystyle.css";
</head>

CSS Rules Overriding ( ๊ทœ์น™ ์˜ค๋ฒ„๋ผ์ด๋”ฉ )

์ง€๊ธˆ๊นŒ์ง€ CSS๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋„ค๊ฐ€์ง€ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ด ๋„ค๊ฐ€์ง€ ๊ทœ์น™์ด ๋™์‹œ์— ์ ์šฉ์ด ๋œ๋‹ค๋ฉด ์–ด๋–ค์ผ์ด ๋ฒŒ์–ด์งˆ๊นŒ์š”??? ์„œ๋กœ์„œ๋กœ ์˜ค๋ฒ„๋ผ์ด๋”ฉ์„ ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ ๊ทธ ๊ทœ์น™์„ ํ•œ๋ฒˆ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. 

  • inline ์Šคํƒ€์ผ์ด ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•๋ณด๋‹ค ํ•ญ์ƒ ์ตœ์šฐ์„ ์‹œ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.  

  • <style>...</style> ํƒœ๊ทธ ๋‚ด์— ์ง€์ •๋œ ์Šคํƒ€์ผ๋“ค์€ ์™ธ๋ถ€ CSSํŒŒ์ผ์— ์ •์˜๋œ ๊ฐ’๋“ค๋ณด๋‹ค ์šฐ์„ ๊ถŒ์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

  • ์™ธ๋ถ€ CSSํŒŒ์ผ์€ ํ•ญ์ƒ ์ตœ์ €์šฐ์„ ๊ถŒ์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค. 

Handling old Browsers ( ๊ตฌ๋ฒ„์ „ ๋ธŒ๋ผ์šฐ์ € ์ฒ˜๋ฆฌ )

๊ตฌ๋ฒ„์ „ ๋ธŒ๋ผ์šฐ์ € ์ค‘์—๋Š” CSS๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์žˆ๊ณ  ์ด๋Ÿฐ ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ์šฉ์ž๋“ค์ด ์žˆ์„ ์ˆ˜๋„ ์žˆ๊ฒ ์ฃ . ๋งŒ์•ฝ ๊ทธ๋Ÿด๊ฒฝ์šฐ์—๋Š” CSS๋ฅผ ์ ์šฉํ•˜์ง€ ์•Š๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์ฒ˜๋Ÿผ <!-- ์™€  --> ๋กœ ๊ฐ์‹ธ์„œ ๋ง์ด์ฃ . 

<style type="text/css">
<!--
body, td {
   color: blue;
}
-->
</style>

CSS Comments ( ์ฃผ์„ )

CSS์—์„œ ์ฃผ์„์€ /* ์ฃผ์„์ฒ˜๋ฆฌ ํ•  ๋‚ด์šฉ */  ์ด๋ ‡๊ฒŒ ์“ฐ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ ์ค„์— ๊ฑธ์ณ๋„ ๊ด€๊ณ„ ์—†์Šต๋‹ˆ๋‹ค. 

์˜ˆ์ œ:

/* This is an external style sheet file */
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
/* end of 
style rules. */

 

 

 

 

 

 

Reference : http://www.tutorialspoint.com/css/css_inclusion.htm

 

 

 

 

 

 

'๐Ÿ’ป Programming > CSS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[CSS] 6. Background ( ๋ฐฐ๊ฒฝ ์„ค์ • )  (0) 2016.06.12
[CSS] 5. Colors ( ์ƒ‰๊น” )  (0) 2016.06.12
[CSS] 4. Units ( ๋‹จ์œ„ )  (0) 2016.06.12
[CSS] 2. Syntax ( ๋ฌธ๋ฒ•, ์‚ฌ์šฉ๋ฒ• )  (0) 2016.06.12
[CSS] 1. CSS๋ž€ ?  (0) 2016.06.11