๐Ÿ’ป Programming (358)

 

์ด๋ฒˆ์—๋Š” CSS ๋ฅผ ์ด์šฉํ•œ ์ด๋ฏธ์ง€ ๊ด€๋ จ ์†์„ฑ์„ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. 

  • The border property is used to set the width of an image border.

  • The height property is used to set the height of an image.

  • The width property is used to set the width of an image.

  • The -moz-opacity property is used to set the opacity of an image.

image border ์†์„ฑ

The border property of an image is used to set the width of an image border. This property can have a value in length or in %.

A width of zero pixels means no border.

Here is the example:

<img style="border:0px;" src="/images/css.gif" />
<br />
<img style="border:3px dashed red;" src="/images/css.gif" />

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

CSS Logo

 

 

image height ์†์„ฑ

The height property of an image is used to set the height of an image. This property can have a value in length or in %. While giving value in %, it applies it in respect of the box in which an image is available.

Here is the example:

<img style="border:1px solid red; height:100px;" 
        src="/images/css.gif" />
<br />
<img style="border:1px solid red; height:50%;" 
        src="/images/css.gif" />

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


 

 

image width ์†์„ฑ

The width property of an image is used to set the width of an image. This property can have a value in length or in %. While giving value in %, it applies it in respect of the box in which an image is available.

Here is the example:

<img style="border:1px solid red; width:100px;" 
        src="/images/css.gif" />
<br />
<img style="border:1px solid red; width:100%;" 
        src="/images/css.gif" />

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


 

 

-moz-opacity ์†์„ฑ

 -moz-opacity ์†์„ฑ์€ ์ด๋ฏธ์ง€์˜ opacity๋ฅผ ์„ค์ •ํ•˜๊ธฐ์œ„ํ•œ ์†์„ฑ์ž…๋‹ˆ๋‹ค. ์ด ์†์„ฑ์€ Mozilla์—์„œ ์ด๋ฏธ์ง€์˜ ํˆฌ๋ช…๋„๋ฅผ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. IE ๋Š” filter:alpha(opacity=x) ๋ฅผ ์‚ฌ์šฉํ•˜์ฃ .

Mozilla์—์„œ (-moz-opacity:x) ์†์„ฑ์„ ์‚ฌ์šฉํ•  ๋•Œ x ๊ฐ’์€ 0.0 ์—์„œ 1.0 ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ˆซ์ž๊ฐ€ ๋‚ฎ์„ ์ˆ˜๋ก ๋” ํˆฌ๋ช…ํ•ด์ง€์ฃ .  

In IE (filter:alpha(opacity=x)) x can be a value from 0 - 100. A lower value makes the element more transparent.

Here is the example:

<img style="border:1px solid red;-moz-opacity:0.4;filter:alpha(opacity=40);opacity:0.4;" src="/images/css.gif" />

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

 

 

 

 

 

 

 

 

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

 

 

 

 

 

์ด๋ฒˆ์—๋Š” CSS ์†์„ฑ์„ ์ด์šฉํ•ด์„œ ํ…์ŠคํŠธ๋ฅผ ์กฐ์ž‘ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

  • The color property is used to set the color of a text.

  • The direction property is used to set the text direction.

  • The letter-spacing property is used to add or subtract space between the letters that make up a word.

  • The word-spacing property is used to add or subtract space between the words of a sentence.

  • The text-indent property is used to indent the text of a paragraph.

  • The text-align property is used to align the text of a document.

  • The text-decoration property is used to underline, overline, and strikethrough text.

  • The text-transform property is used to capitalize text or convert text to uppercase or lowercase letters.

  • The white-space property is used to control the flow and formatting of text.

  • The text-shadow property is used to set the text shadow around a text.

 

ํ…์ŠคํŠธ ์ƒ‰๊น” ์„ค์ •

<p style="color:red;">
This text will be written in red.
</p>

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

This text will be written in red.

 

 

ํ…์ŠคํŠธ ๋ฐฉํ–ฅ ์„ค์ •

Following is the example which demonstrates how to set the direction of a text. Possible values are ltr or rtl.

<p style="direction:rtl;">
This text will be renedered from right to left
</p>

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

This text will be renedered from right to left

 

 

๋ฌธ์ž ์‚ฌ์ด์˜ ๊ณต๊ฐ„ ์„ค์ •

Following is the example which demonstrates how to set the space between characters. Possible values are normal or a number specifying space..

<p style="letter-spacing:5px;">
This text is having space between letters.
</p>

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

This text is having space between letters.

 

 

๋‹จ์–ด ์‚ฌ์ด์˜ ๊ณต๊ฐ„ ์„ค์ •

Following is the example which demonstrates how to set the space between words. Possible values are normal or a number specifying space..

<p style="word-spacing:5px;">
This text is having space between words.
</p>

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

This text is having space between words.

 

 

ํ…์ŠคํŠธ ์ธ๋ดํŠธ ์„ค์ •

Following is the example which demonstrates how to indent the first line of a paragraph. Possible values are % or a number specifying indent space..

<p style="text-indent:1cm;">
This text will have first line indented by 1cm
and this line will remain at its actual position
this is done by CSS text-indent property.
</p>

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

This text will have first line indented by 1cm
and this line will remain at its actual position
this is done by CSS text-indent property.

 

 

ํ…์ŠคํŠธ ์ •๋ ฌ ์„ค์ •

Following is the example which demonstrates how to align a text. Possible values are left, right, center, justify..

<p style="text-align:right;">
This will be right aligned.
</p>
<p style="text-align:center;">
This will be center aligned.
</p>
<p style="text-align:left;">
This will be left aligned.
</p>

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

This will be right aligned.

This will be center aligned.

This will be left aligned.

 

 

ํ…์ŠคํŠธ ๊พธ๋ฐˆ ์„ค์ •

Following is the example which demonstrates how to decorate a text. Possible values are none, underline, overline, line-through, blink..

<p style="text-decoration:underline;">
This will be underlined
</p>
<p style="text-decoration:line-through;">
This will be striked through.
</p>
<p style="text-decoration:overline;">
This will have a over line.
</p>
<p style="text-decoration:blink;">
This text will have blinking effect
</p>

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

This will be underlined

This will be striked through.

This will have a over line.

This text will have blinking effect

 

 

ํ…์ŠคํŠธ ๋Œ€์†Œ๋ฌธ์ž ์„ค์ •

Following is the example which demonstrates how to set the cases for a text. Possible values are none, capitalize, uppercase, lowercase..

<p style="text-transform:capitalize;">
This will be capitalized
</p>
<p style="text-transform:uppercase;">
This will be in uppercase
</p>
<p style="text-transform:lowercase;">
This will be in lowercase
</p>

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

This will be capitalized

This will be in uppercase

This will be in lowercase

 

 

ํ…์ŠคํŠธ white-space ์„ค์ •

Following is the example which demonstrates how white space inside an element is handled. Possible values are normal, pre, nowrap.

<p style="white-space:pre;">This text has a line break
and the white-space pre setting tells the browser to honor it
just like the HTML pre tag.</p>

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

This text has a line break and the white-space pre setting tells the browser to honor it just like the HTML pre tag.

 

 

ํ…์ŠคํŠธ ๊ทธ๋ฆผ์ž ์„ค์ •

Following is the example which demonstrates how to set the shadow around a text. This may not be supported by all the browsers.

<p style="text-shadow:4px 4px 8px blue;">
If your browser supports the CSS text-shadow property, 
this text will have a  blue shadow.</p>

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

If your browser supports the CSS text-shadow property, this text will have a blue shadow.

 

 

 

 

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

 

 

 

 

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” CSS๋ฅผ ์ด์šฉํ•ด์„œ ํฐํŠธ๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

  • font-family ๋Š” ํฐํŠธ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค. ( ๋‹์›€์ฒด, ๊ตด๋ฆผ์ฒด ๋ญ ์ด๋Ÿฐ๊ฒƒ๋“ค ์žˆ์ฃ ? ) 

  • font-style ๋Š” ํฐํŠธ๋ฅผ ์ฒด๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค. ( italic, oblique ) 

  • font-variant ๋Š” ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ์„ค์ •ํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค.

  • font-weight ๋Š” ํฐํŠธ์˜ ๊ตต๊ธฐ๋ฅผ ์„ค์ •ํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค. ( bold, light ) 

  • font-size ๋Š” ํฐํŠธ ์‚ฌ์ด์ฆˆ๋ฅผ ์„ค์ •ํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค.

  • font ๋Š” ํฐํŠธ๊ด€๋ จ ๋ชจ๋“  ์†์„ฑ์„ ํ•œ๋ฒˆ์— ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ํ•œ๋ฐฉ ์†์„ฑ์ž…๋‹ˆ๋‹ค.

 

ํฐํŠธ ํŒจ๋ฐ€๋ฆฌ ์„ค์ •ํ•˜๊ธฐ

์„ค์ • ๊ฐ€๋Šฅํ•œ ๊ฐ’์€ ๋ชจ๋“  ํฐํŠธ ํŒจ๋ฐ€๋ฆฌ ๊ฐ’์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ๋“ค๋ฉด aria, serif์™€ ๊ฐ™์€ ํฐํŠธ ์„œ์ฒด์ž…๋‹ˆ๋‹ค.  

<p style="font-family:georgia,garamond,serif;">
This text is rendered in either georgia, garamond, or the default
serif font depending on which font  you have at your system.
</p>

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

This text is rendered in either georgia, garamond, or the default
serif font depending on which font you have at your system.

 

 

ํฐํŠธ ์Šคํƒ€์ผ ์„ค์ •ํ•˜๊ธฐ

์„ค์ • ๊ฐ€๋Šฅํ•œ ๊ฐ’์€ normal, italic ๊ทธ๋ฆฌ๊ณ  oblique ์ž…๋‹ˆ๋‹ค. 

<p style="font-style:italic;">
This text will be rendered in italic style
</p>

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

This text will be rendered in italic style

 

 

ํฐํŠธ ๋ณ€์ข… ์„ค์ •ํ•˜๊ธฐ

๊ฐ€๋Šฅํ•œ ๊ฐ’์€ normal ๊ณผ small-caps๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

<p style="font-variant:small-caps;">
This text will be rendered as small caps
</p>

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

This text will be renedered as small caps

 

 

ํฐํŠธ ๋‘๊ป˜ ์„ค์ •ํ•˜๊ธฐ

ํฐํŠธ์˜ ๋‘๊ป˜๋ฅผ ์„ค์ •ํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค.

๊ฐ€๋Šฅํ•œ ๊ฐ’์€ normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900 ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

<p style="font-weight:bold;">
This font is bold.
</p>
<p style="font-weight:bolder;">
This font is bolder.
</p>
<p style="font-weight:900;">
This font is 900 weight.
</p>

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

This font is bold.

This font is bolder.

This font is 900 weight.

 

 

ํฐํŠธ ์‚ฌ์ด์ฆˆ ์„ค์ •ํ•˜๊ธฐ

๊ฐ€๋Šฅํ•œ ๊ฐ’์€ xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger, ๊ทธ๋ฆฌ๊ณ  ํ”ฝ์…€๊ฐ’ ๋˜๋Š” ํผ์„ผํŠธ ๊ฐ’์ž…๋‹ˆ๋‹ค.

<p style="font-size:20px;">
This font size is 20 pixels
</p>
<p style="font-size:10pt;">
This font size is small
</p>
<p style="font-size:14pt;">
This font size is large
</p>

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

This font size is 20 pixels

This font size is small

This font size is large

 

 

ํฐํŠธ ์‚ฌ์ด์ฆˆ adjust ์„ค์ •ํ•˜๊ธฐ

์ด๋ฒˆ์—๋Š” ํฐํŠธ์˜ ์‚ฌ์ด์ฆˆ adjust ์„ค์ •์„ ํ•˜๋Š” ๊ฒƒ์ด๋„ค์š”. ๊ฐ€๋Šฅํ•œ ๊ฐ’์€ ๋ชจ๋“  ์ˆซ์ž๊ฐ’์ž…๋‹ˆ๋‹ค.  

<p style="font-size-adjust:0.61;">
This text is using a font-size-adjust value.
</p>

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

This text is using a font-size-adjust value.

 

 

ํฐํŠธ ์ŠคํŠธ๋ ˆ์น˜ ์„ค์ •

๊ฐ€๋Šฅํ•œ ๊ฐ’์€ normal, wider, narrower, ultra-condensed, extra-condensed, condensed, semi-condensed, semi-expanded, expanded, extra-expanded, ultra-expanded ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์†์„ฑ์€ ์—ฌ๋Ÿฌ๋ถ„ ์ปดํ“จํ„ฐ์— ์žˆ๋Š” ํฐํŠธ๊ฐ€ 

<p style="font-stretch:ultra-expanded;">
If this doesn't appear to work, it is likely that 
your computer doesn't have a condensed or expanded 
version of the font being used.
</p>

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

If this doesn't appear to work, it is likely that your computer doesn't have a condensed or expanded version of the font being used.

 

 

ํฐํŠธ ์†์„ฑ ํ•œ๋ฒˆ์— ์„ค์ •ํ•˜๊ธฐ

<p style="font:italic small-caps bold 15px georgia;">
Applying all the properties on the text at once.
</p>

๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค

Applying all the properties on the text at once.

 

 

 

 

์ด์ƒ์œผ๋กœ ํฐํŠธ ๊ด€๋ จ ์†์„ฑ๋“ค์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค.

 

ํœด์šฐ~~~ ์Šฌ์Šฌ CSS๊ฐ€ ์žฌ๋ฏธ์žˆ์–ด ์ง€์‹œ๋‚˜์š”? ์ง€๊ฒจ์›Œ์ง€์‹œ๋‚˜์š”?

 

์ด์ œ ์‹œ์ž‘์ธ๋ฐ ๋ง์ด์ฃ  ใ…‹ใ…‹ใ…‹

 

ํ™”์ดํŒ…์ž…๋‹ˆ๋‹ค~~ 

 

 

 

 

 

 

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

 

 

 

 

 

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ๊ฐ์ข… HTML ํƒœ๊ทธ๋‚ด์—์„œ ์“ฐ์ด๋Š” ๋ฐฐ๊ฒฝ ๊ด€๋ จ ์†์„ฑ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ฐฐ๊ฒฝ๊ด€๋ จ ์†์„ฑ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒƒ๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค.

  •  background-color ๋Š” ๋ฐฐ๊ฒฝ ์ƒ‰์ƒ์„ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•œ ์†์„ฑ์ž…๋‹ˆ๋‹ค.

  •  background-image ๋Š” ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•œ ์†์„ฑ์ž…๋‹ˆ๋‹ค.

  •  background-repeat ๋Š” ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์˜ ๋ฐ˜๋ณต ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•œ ์†์„ฑ์ž…๋‹ˆ๋‹ค.

  •  background-position ๋Š” ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์˜ ์œ„์น˜๋ฅผ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•œ ์†์„ฑ์ž…๋‹ˆ๋‹ค.

  •  background-attachment ๋Š” ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์˜ ์Šคํฌ๋กค๋ง์„ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•œ ์†์„ฑ์ž…๋‹ˆ๋‹ค.

  •  background property is used as shorthand to specify a number of other background properties.

 

๋ฐฐ๊ฒฝ ์ƒ‰ ์„ค์ •ํ•˜๊ธฐ

<p style="background-color:yellow;">
This text has a yellow background color.
</p>

This will produce following result:

This text has a yellow background color.

 

 

 

๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ์„ค์ •ํ•˜๊ธฐ

<table style="background-image:url(/images/pattern1.gif);">
<tr><td>
This table has background image set.
</td></tr>
</table>

 

 

๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ๋ฐ˜๋ณตํ•˜๊ธฐ

<table style="background-image:url(/images/pattern1.gif); 
              background-repeat: repeat;">
<tr><td>
This table has background image which repeats multiple times.
</td></tr>
</table>

 

์•„๋ž˜ ์˜ˆ์ œ๋Š” ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ์„ธ๋กœ๋กœ ๋ฐ˜๋ณต์‹œํ‚ค๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

<table style="background-image:url(/images/pattern1.gif); 
              background-repeat: repeat-y;">
<tr><td>
This table has background image set which will repeat vertically.
</td></tr>
</table>

 

์•„๋ž˜๋Š” ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ๊ฐ€๋กœ๋กœ ๋ฐ˜๋ณต์‹œํ‚ค๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

<table style="background-image:url(/images/pattern1.gif); 
              background-repeat: repeat-x;">
<tr><td>
This table has background image set which will repeat horizontally.
</td></tr>
</table>

 

 

๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ์œ„์น˜ ์„ค์ •ํ•˜๊ธฐ

๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๋ฅผ ์™ผ์ชฝ์—์„œ 100 ํ”ฝ์…€ ๋–จ์–ด๋œจ๋ ค์„œ ์œ„์น˜์‹œํ‚ค๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค. 

<table style="background-image:url(/images/pattern1.gif); 
              background-position:100px;">
<tr><td>
Background image positioned 100 pixels away from the left.
</td></tr>
</table>

๋‹ค์œผ๋ฏ€ ์˜ˆ์ œ๋Š” ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์˜ ์œ„์น˜๋ฅผ ์™ผ์ชฝ์—์„œ 100 ํ”ฝ์…€ ๊ทธ๋ฆฌ๊ณ  ์œ„์—์„œ 200 ํ”ฝ์…€ ๋–จ์–ด์ง„ ๊ณณ์— ์œ„์น˜์‹œํ‚ค๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

<table style="background-image:url(/images/pattern1.gif); 
              background-position:100px 200px;">
<tr><td>
This table has background image positioned 100
pixels away from the left and 200 pixels from the top.
</td></tr>
</table>

 

 

๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ๊ณ ์ • ๋˜๋Š” ์Šคํฌ๋กค ์—ฌ๋ถ€ ์„ค์ •ํ•˜๊ธฐ

Background attachment determines whether a background image is fixed or scrolls with the rest of the page.

 

์•„๋ž˜ ์˜ˆ์ œ๋Š” ๋ฐฐ๊ฒฝ์ด๋ฏธ์ง€๋ฅผ ๊ณ ์ •์‹œํ‚ค๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค. 

<p style="background-image:url(/images/pattern1.gif); 
              background-attachment:fixed;">
This parapgraph has fixed background image.
</p>

์ด๋ฒˆ ์˜ˆ์ œ๋Š” ์Šคํฌ๋กค๋ง์„ ํ•ด์ฃผ๋Š” ์˜ˆ์ œ๋„ค์š”.

<p style="background-image:url(/images/pattern1.gif); 
              background-attachment:scroll;">
This parapgraph has scrolling background image.
</p>

 

 

๋ฐฐ๊ฒฝ ์†์„ฑ ํ•œ๊บผ๋ฒˆ์— ์„ค์ •ํ•˜๊ธฐ

background ์†์„ฑ์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ฐฐ๊ฒฝ๊ด€๋ จ ์†์„ฑ์„ ํ•œ๊บผ๋ฒˆ์— ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค. 

<p style="background:url(/images/pattern1.gif) repeat fixed;">
This parapgraph has fixed repeated background image.
</p>

 

 

 

 

 

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

 

 

 

 

 

 

 

 

๐Ÿ’ป Programming/CSS

[CSS] 5. Colors ( ์ƒ‰๊น” )

 

CSS ์—์„œ ์ƒ‰๊น”์„ ์ง€์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์ฒ˜๋Ÿผ 5๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค

FormatSyntaxExample
Hex Code#RRGGBBp{color:#FF0000;}
Short Hex Code#RGBp{color:#6A7;}
RGB %rgb(rrr%,ggg%,bbb%)p{color:rgb(50%,50%,50%);}
RGB Absolutergb(rrr,ggg,bbb)p{color:rgb(0,0,255);}
keywordaqua, black, etc.p{color:teal;}

 

์•„๋ž˜์—์„œ ์ข€ ๋” ์ž์„ธํžˆ ์•Œ์•„๋ณด๋„๋ก ํ•˜์ฃ . 


1. CSS Colors - Hex Codes ( 16์ง„์ˆ˜ RRGGBB ์ฝ”๋“œ )

16์ง„์ˆ˜ ์ฝ”๋“œ๋กœ ํ‘œํ˜„ํ•  ๋•Œ๋Š” # ๊ธฐํ˜ธ๋ฅผ ๋จผ์ € ๋ถ™์—ฌ์ฃผ๊ณ  6์ž๋ฆฌ์˜ RRGGBB ์ฝ”๋“œ๋ฅผ ๋„ฃ์–ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. RGB์˜ R์€ ๋นจ๊ฐ•, G๋Š” ์ดˆ๋ก, B๋Š” ํŒŒ๋ž‘์ž…๋‹ˆ๋‹ค. RR์ด๋ผ๋Š” ๊ฒƒ์€ ๋นจ๊ฐ•์„ ๋‚˜ํƒ€๋‚ด๋Š” 16์ง„์ˆ˜ ์ˆซ์ž๋ฅผ ๋งํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด 00๋ถ€ํ„ฐ FF๊นŒ์ง€์˜ ๊ฐ’์ด ๋ฉ๋‹ˆ๋‹ค. GG์™€ BB์—ญ์‹œ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค.

์•„๋ž˜๋Š” ์ด๋ ‡๊ฒŒ 16์ง„์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ์ƒ‰๊น”์„ ํ‘œ์‹œํ–ˆ์„ ๋•Œ ์–ด๋–ป๊ฒŒ ํ™”๋ฉด์— ๋ณด์—ฌ์ง€๋Š”์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ํ‘œ์ž…๋‹ˆ๋‹ค.


ColorColor HEX
 #000000
 #FF0000
 #00FF00
 #0000FF
 #FFFF00
 #00FFFF
 #FF00FF
 #C0C0C0
 #FFFFFF

 

 

CSS Colors - Short Hex Codes ( 16์ง„์ˆ˜ RGB ์ฝ”๋“œ )

์ด๋ฒˆ์—๋Š” ์ข€ ์งง๊ฒŒ ์“ฐ๋Š” RGB์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. ์œ„์—์„œ RRGGBB๋กœ ์“ฐ์˜€๋˜ ๊ฒƒ์ด RGB๋กœ ์ค„์–ด๋“  ๊ฒƒ์ด์ฃ . ๋‹ค๋ฅธ ์ ์€ ์œ„ ์—ฌ์„ฏ์ž๋ฆฌ RRGGBB์ฝ”๋“œ์—์„œ๋Š” ์ข€ ๋” ์„ธ๋ฐ€ํ•˜๊ฒŒ ์ƒ‰๊น”์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ˜๋ฉด RGB์ฝ”๋“œ์—์„œ๋Š” ์ข€ ๋‹จ์ˆœํ™”๋œ ์ƒ‰๊น”๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด์ฃ . ๊ทธ ์ด์œ ์ธ์ฆ‰์Šจ RR ๋‘๊ฐœ๋กœ ํ‘œ์‹œํ•  ์ˆ˜ ์ด์—ˆ๋˜ ๋นจ๊ฐ„๊ณ„์—ด ์ƒ‰์ƒ์„ Rํ•˜๋‚˜๋กœ๋งŒ ๋‚˜ํƒ€๋‚ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด RGB์ฝ”๋“œ์˜ #FFF์—์„œ R์„ ๋‚˜ํƒ€๋‚ด๋Š” F๋Š” RRGGBB์˜ RR๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค๋ฉด FF๊ฐ€ ๋˜๊ฒ ์ฃ . ๋งŒ์•ฝ RRGGBB์˜ RR๊ฐ’์— AD๊ฐ€ ๋“ค์–ด์žˆ์—ˆ๋‹ค๊ณ  ํ•˜๋ฉด ์ด๊ฒƒ์„ RGB๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์„ ๊นŒ์š”? ์•„๋‹™๋‹ˆ๋‹ค. ํ‘œํ˜„ํ•  ์ˆ˜ ์—†๊ฒ ์ฃ .
ColorColor HEX
 #000
 #F00
 #0F0
 #0FF
 #FF0
 #0FF
 #F0F
 #FFF

 

 

CSS Colors - RGB Values ( 10์ง„์ˆ˜ RGB ์ฝ”๋“œ )

์ด ๋ฐฉ๋ฒ•์€ rgb( ) ์†์„ฑ์„ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.  0 ๋ถ€ํ„ฐ 255 ์ˆซ์ž๋‚˜ ํผ์„ผํŠธ๋ฅผ ๊ฐ’์— ๋„ฃ์–ด์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

NOTE: ๋ชจ๋“  ๋ธŒ๋ผ์šฐ์ €๊ฐ€ rgb() ์†์„ฑ์„ ์ง€์›ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด ๋ฐฉ๋ฒ•์€ ๊ถŒ์žฅํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. 

 

ColorColor RGB
 rgb(0,0,0)
 rgb(255,0,0)
 rgb(0,255,0)
 rgb(0,0,255)
 rgb(255,255,0)
 rgb(0,255,255)
 rgb(255,0,255)
 rgb(192,192,192)
 rgb(255,255,255)

 

์˜ˆ์ œ :  

<body style="color:rgb(0,0,255); background-color:rgb(0,255,0);"> 

Building Color Codes:

์ƒ‰๊น” ์ฝ”๋“œ๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๋Š” ์นผ๋ผ ์ฝ”๋“œ ๋นŒ๋”๋ผ๋Š”๊ฒŒ ์žˆ๋„ค์š”.  HTML Color Code Builder.  

Browser Safe Colors:

์•„๋ž˜ ํ‘œ๋Š” ๋ธŒ๋ผ์šฐ์ €์˜ ์˜ํ–ฅ์ด๋‚˜ ์ปดํ“จํ„ฐ ๋””์Šคํ”Œ๋ ˆ์ด์˜ ์˜ํ–ฅ์„ ๊ฐ€์žฅ ์•ˆ๋ฐ›๋Š” ๊ทธ๋Ÿฐ ์นผ๋ผํ‘œ๋ผ๊ณ  ํ•˜๋„ค์š”. ์ด 216 ๊ฐœ์˜ ์ƒ‰๊น”์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์ƒ‰๊น”์„ ๋ณด๊ณ  ๋ง˜์—๋“œ๋Š”๊ฑฐ ์ฝ”๋“œ ๊ณจ๋ผ๋‹ค๊ฐ€ ์“ฐ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹น. ^____^

 

0000000000330000660000990000CC0000FF
0033000033330033660033990033CC0033FF
0066000066330066660066990066CC0066FF
0099000099330099660099990099CC0099FF
00CC0000CC3300CC6600CC9900CCCC00CCFF
00FF0000FF3300FF6600FF9900FFCC00FFFF
3300003300333300663300993300CC3300FF
3333003333333333663333993333CC3333FF
3366003366333366663366993366CC3366FF
3399003399333399663399993399CC3399FF
33CC0033CC3333CC6633CC9933CCCC33CCFF
33FF0033FF3333FF6633FF9933FFCC33FFFF
6600006600336600666600996600CC6600FF
6633006633336633666633996633CC6633FF
6666006666336666666666996666CC6666FF
6699006699336699666699996699CC6699FF
66CC0066CC3366CC6666CC9966CCCC66CCFF
66FF0066FF3366FF6666FF9966FFCC66FFFF
9900009900339900669900999900CC9900FF
9933009933339933669933999933CC9933FF
9966009966339966669966999966CC9966FF
9999009999339999669999999999CC9999FF
99CC0099CC3399CC6699CC9999CCCC99CCFF
99FF0099FF3399FF6699FF9999FFCC99FFFF
CC0000CC0033CC0066CC0099CC00CCCC00FF
CC3300CC3333CC3366CC3399CC33CCCC33FF
CC6600CC6633CC6666CC6699CC66CCCC66FF
CC9900CC9933CC9966CC9999CC99CCCC99FF
CCCC00CCCC33CCCC66CCCC99CCCCCCCCCCFF
CCFF00CCFF33CCFF66CCFF99CCFFCCCCFFFF
FF0000FF0033FF0066FF0099FF00CCFF00FF
FF3300FF3333FF3366FF3399FF33CCFF33FF
FF6600FF6633FF6666FF6699FF66CCFF66FF
FF9900FF9933FF9966FF9999FF99CCFF99FF
FFCC00FFCC33FFCC66FFCC99FFCCCCFFCCFF
FFFF00FFFF33FFFF66FFFF99FFFFCCFFFFFF

 

 

 

 

 

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

 

 

 

 

๐Ÿ’ป Programming/CSS

[CSS] 4. Units ( ๋‹จ์œ„ )

CSS ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋‹จ์œ„(Unit)

์‹ค์ œ๋กœ CSS๋กœ ๋ญ”๊ฐ€๋ฅผ ํ•˜๊ธฐ์ „์— ๊ธฐ๋ณธ๋ถ€ํ„ฐ ๋‹ค์ง€๊ณ  ๊ฐ€๋Š”๊ฒŒ ์ข‹๊ฒ ์ฃ ?

๊ทธ๋ž˜์„œ ์ด๋ฒˆ์—๋Š” ๊ฐ์ข… ์†์„ฑ๊ฐ’์— ์“ฐ์ด๋Š” ๋‹จ์œ„๋ฅผ ํ•œ๋ฒˆ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

CSS๋Š” ์ ˆ๋Œ€๊ฐ’์„ ๋‚˜ํƒ€๋‚ด๋Š” inches, centimeters, points ๋“ฑ๋“ฑ ๋ฟ ์•„๋‹ˆ๋ผ ์ƒ๋Œ€๊ฐ’์„ ๋‚˜ํƒ€๋‚ด๋Š” percentages๋‚˜ em ๋‹จ์œ„๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๋‹จ์œ„๋“ค์€ ์ž์ฃผ ์“ฐ์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ผญ ์งš๊ณ  ๋„˜์–ด๊ฐ€์‹œ๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

 

๋‹ค์Œ์€ ๋‹จ์œ„์™€ ๋‹จ์œ„์— ๋Œ€ํ•œ ์„ค๋ช… ๋ฐ ์‚ฌ์šฉ ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค. 

Unit Description Example
% ํผ์„ผํŠธ p {font-size: 16pt; line-height: 125%;}
cm ์„ผํ‹ฐ๋ฏธํ„ฐ div {margin-bottom: 2cm;}
em em ๋‹จ์œ„๋Š” ํฐํŠธ์˜ ์‚ฌ์ด์ฆˆ์™€ ๋™์ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํฐํŠธ์‚ฌ์ด์ฆˆ๋ฅผ 12pt๋กœ ์„ค์ •ํ•˜๋ฉด ๊ฐ em ๋‹จ์œ„๋Š” 12pt๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 2em์€ 24pt๊ฐ€ ๋˜๊ฒ ์ฃ  p {letter-spacing: 7em;}
ex ์ด ๊ฐ’์€ ํฐํŠธ์˜ x-๋†’์ด๊ฐ’์— ์ƒ๋Œ€์ ์ธ ๊ฐ’์ž…๋‹ˆ๋‹ค. x-๋†’์ด๊ฐ’์€ ํ•ด๋‹น ํฐํŠธ์˜ ์†Œ๋ฌธ์žx๊ฐ’์˜ ๋†’์ด์ž…๋‹ˆ๋‹ค. p {font-size: 24pt; line-height: 3ex;}
in ์ธ์น˜ p {word-spacing: .15in;}
mm ๋ฐ€๋ฆฌ๋ฏธํ„ฐ p {word-spacing: 15mm;}
pc picas๋ผ๋Š” ๋‹จ์œ„๋กœ 1 pica๋Š” 12 pt์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค; ๋”ฐ๋ผ์„œ, 1์ธ์น˜์—๋Š” 6 picas ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. p {font-size: 20pc;}
pt ํฌ์ธํŠธ ๋‹จ์œ„๋กœ 1 pt๋Š” 72๋ถ„์˜ 1 ์ธ์น˜์ž…๋‹ˆ๋‹ค. body {font-size: 18pt;}
px ์Šคํฌ๋ฆฐ ํ”ฝ์…€ ๋‹จ์œ„ p {padding: 25px;}

 

example์— ์žˆ๋Š” ๋‚ด์šฉ์„ css ํŒŒ์ผ์— ์ž‘์„ฑํ•ด์„œ ๊ผญ!! ํ…Œ์ŠคํŠธํ•ด๋ณด์„ธ์š”~

 

 

 

 

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

 

 

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

 

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

CSS๋Š” ์Šคํƒ€์ผ ๊ทœ์น™์„ ๋”ฐ๋ฅด๋Š”๋ฐ ์ด ์Šคํƒ€์ผ ๊ทœ์น™์—๋Š” ์„ธ๊ฐ€์ง€ ์š”์†Œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. 

  • ์…€๋ ‰ํ„ฐ : ์…€๋ ‰ํ„ฐ๋Š” HTML ํƒœ๊ทธ์˜ ์ด๋ฆ„์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ๋“ค๋ฉด <h1> ํƒœ๊ทธ์˜ h1์ด๋‚˜ <table> ํƒœ๊ทธ์˜ table์ด ์…€๋ ‰ํ„ฐ์ธ๊ฑฐ์ฃ .

  • ์†์„ฑ : ์†์„ฑ์€ htmlํƒœ๊ทธ ๋‚ด์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๊ทธ๋Ÿฐ ์†์„ฑ๋“ค์„ ๋งํ•ฉ๋‹ˆ๋‹ค. color๋‚˜ border๊ฐ™์€ ๊ฒƒ๋“ค์„ ๋งํ•˜๋Š”๊ฑฐ์ฃ .

  • ๊ฐ’ : ์ด ๊ฐ’์€ ์†์„ฑ์— ํ• ๋‹น๋˜๋Š” ๊ฐ’์„ ๋งํ•ฉ๋‹ˆ๋‹ค. color์†์„ฑ์ด red๊ฐ’์„ ๊ฐ–๋Š”๋‹ค ๋ญ ์ด๋Ÿฐ๊ฑฐ์ฃ .

์ด ์„ธ๊ฐ€์ง€ ์š”์†Œ๋ฅผ ํ•ฉํ•˜๋ฉด ๊ทธ๊ฒŒ๋ฐ”๋กœ ์•„๋ž˜์™€ ๊ฐ™์€ ์Šคํƒ€์ผ ๊ทœ์น™์ž…๋‹ˆ๋‹ค.

์…€๋ ‰ํ„ฐ { ์†์„ฑ : ๊ฐ’ }

์˜ˆ์ œ : ํ…Œ์ด๋ธ” ์…€๋ ‰ํ„ฐ์˜ ์†์„ฑ ์ง€์ •ํ•˜๊ธฐ

table{ border :1px solid #C00; }

์œ„ ์˜ˆ์ œ๊ฐ€ ๋ญํ•˜๋Š”๊ฑด์ง€ ์ดํ•ด๊ฐ€ ๋˜๋‚˜์š”? tableํƒœ๊ทธ์˜ ์†์„ฑ ์ค‘์— border ์†์„ฑ ๊ฐ’์„ 1px solid #C00 ๋กœ ์„ค์ •์„ ํ•œ๊ฒ๋‹ˆ๋‹ค.

 

์ž, ์ด์ œ ์–ด๋Š์ •๋„ ๊ฐ์ด ์˜ค๋‚˜์š”???  

 

๊ทธ๋Ÿผ ์ด์ œ ์…€๋ ‰ํ„ฐ๋“ค์ด ์–ด๋–ค ๊ฒƒ๋“ค์ด ์žˆ๋Š”์ง€๋„ ํ•œ๋ฒˆ ๋ด๋ณผ๊นŒ์š”? 

The Type Selectors ( ํƒ€์ž… ์…€๋ ‰ํ„ฐ )

h1ํƒœ๊ทธ๊ฐ€ ๋ญ”์ง€๋Š” ์ด๋ฏธ ์•„์‹œ๊ฒ ์ฃ ? ๋ ˆ๋ฒจ1 ํ—ค๋” ํƒœ๊ทธ์ฃ . ๊ทธ ํƒœ๊ทธ์˜ ์ƒ‰๊น” ์†์„ฑ์„ ์ง€์ •ํ•ด์ฃผ๋Š” ์˜ˆ์ œ๊ฐ€ ๋ฐ‘์— ์žˆ๊ตฐ์š”.

h1 { 
   color: #36CFFF; 
}

The Universal Selectors ( ์œ ๋‹ˆ๋ฒ„์„ค ์…€๋ ‰ํ„ฐ )

ํ•˜๋‚˜์˜ ํŠน์ •ํ•œ ์…€๋ ‰ํ„ฐ๋ฅผ ์„ ํƒํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๋ชจ๋“  ์…€๋ ‰ํ„ฐ์— ๋Œ€ํ•ด์„œ ์†์„ฑ์„ ์ง€์ •ํ•ด์ฃผ๊ณ  ์‹ถ์„๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์œ ๋‹ˆ๋ฒ„์„ค ์…€๋ ‰ํ„ฐ์ž…๋‹ˆ๋‹ค. * ๊ธฐํ˜ธ๋Š” "๋ชจ๋“ "์ด๋ผ๋Š” ์˜๋ฏธ๋ฅผ ๊ฐ–๊ณ ์žˆ์ฃ .

* { 
  color: #000000; 
}

๋ชจ๋“  ์…€๋ ‰ํ„ฐ(ํƒœ๊ทธ)์— ๋Œ€ํ•ด์„œ ์ƒ‰๊นŒ ์†์„ฑ๊ฐ’์„ ๊ฒ€์ •์œผ๋กœ ์„ค์ •ํ•œ ์˜ˆ์ œ์ฃ ? ์•„๋‹Œ๊ฐ€์š”? 

The Descendant Selectors ( ํ›„์† ์…€๋ ‰ํ„ฐ )

ํƒœ๊ทธ์•ˆ์— ๋˜ ๋‹ค๋ฅธ ํƒœ๊ทธ๊ฐ€ ๋“ค์–ด๊ฐˆ ์ˆ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿด๋•Œ ํ›„์† ์…€๋ ‰ํ„ฐ์— ๋Œ€ํ•ด์„œ๋งŒ ์ ์šฉ์„ ํ•˜๊ณ  ์‹ถ์€ ์†์„ฑ๊ฐ’์ด ์žˆ์„ํ…๋ฐ ๊ทธ๋Ÿด๋•Œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ์ œ๋Š” ulํƒœ๊ทธ ์•ˆ์— ์‚ฌ์šฉ๋œ emํƒœ๊ทธ์˜ ์†์„ฑ์„ ์ง€์ •ํ•ด์ฃผ๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

ul em {
  color: #000000; 
}

The Class Selectors ( ํด๋ž˜์Šค ์…€๋ ‰ํ„ฐ )

๋งŒ์•ฝ ํด๋ž˜์Šค ๋‹จ์œ„๋กœ ์†์„ฑ๊ฐ’์„ ์ง€์ •ํ•ด์ฃผ๊ณ  ์‹ถ๋‹ค๋ฉด ํด๋ž˜์Šค ์…€๋ ‰ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.  

์‚ฌ์šฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ (.)์„ ์ฐ๊ณ  ๋ถ™์—ฌ์„œ ํด๋ž˜์Šค๋ช…์„ ์จ์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 

.black {
  color: #000000; 
}

์œ„ ์˜ˆ์ œ๋Š” blackํด๋ž˜์Šค์— ์†ํ•œ ๋ชจ๋“  ํƒœ๊ทธ์˜ ์ƒ‰์„ ๊ฒ€์ •์ƒ‰(#000000)์œผ๋กœ ์ง€์ •ํ•ด์ฃผ๋Š” ์˜ˆ์ œ๋„ค์š” . ์ข€ ๋” ๋ฒ”์œ„๋ฅผ ์ขํ˜€์„œ ์•„๋ž˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜์‹ค ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.  

h1.black {
  color: #000000; 
}

 <h1> ํƒœ๊ทธ์ด๋ฉด์„œ blackํด๋ž˜์Šค์— ์†ํ•œ ํƒœ๊ทธ๋“ค์˜ ์ƒ‰๊น”์„ ๋ชจ๋‘ #000000์œผ๋กœ ์ง€์ •ํ•ด์ฃผ๋Š” ์˜ˆ์ œ๊ตฐ์š”.

 

# ์ฐธ๊ณ ๋กœ ์•„๋ž˜์ฒ˜๋Ÿผ ํ•˜๋‚˜์˜ ํƒœ๊ทธ์— ์—ฌ๋Ÿฌ๊ฐœ์˜ ํด๋ž˜์Šค๋ฅผ ๋ถ€์—ฌํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ๋„ ์•Œ๊ณ ๊ณ„์‹œ๋ฉด ์ข‹๊ฒ ๋„ค์š”:

<p class="center bold">
This para will be styled by the classes center and bold.
</p>

The ID Selectors ( ์•„์ด๋”” ์…€๋ ‰ํ„ฐ )

์ด๋ฒˆ์—๋Š” ์•„์ด๋”” ์…€๋ ‰ํ„ฐ์— ๋Œ€ํ•ด์„œ ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  ํƒœ๊ทธ์—๋Š” ์•„์ด๋””๋ฅผ ๋ถ€์—ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ๋ ‡๊ฒŒ ๋ถ€์—ฌ๋œ ์•„์ด๋””๋ฅผ ์…€๋ ‰ํŠธํ•˜๊ธฐ์œ„ํ•ด์„œ๋Š” # ๊ธฐํ˜ธ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. 

#black {
  color: #000000; 
}

์œ„ ์˜ˆ์ œ๋Š” id๊ฐ€ black์ธ ์š”์†Œ์˜ ์ƒ‰๊น”์„ ๊ฒ€์ •์œผ๋กœ ์ง€์ •ํ•˜๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

h1#black {
  color: #000000; 
}

์œ„ ์˜ˆ์ œ๋Š” <h1> ์š”์†Œ๋‚ด์˜ ๋ชจ๋“  ์š”์†Œ๋“ค ์ค‘์—์„œ id๊ฐ€ black์ธ ๋…€์„์—๊ฒŒ๋งŒ ๊ฒ€์ •์ƒ‰ ์†์„ฑ์„ ์ฃผ์—ˆ๋„ค์š”

์ด id์…€๋ ‰ํ„ฐ๊ฐ€ ๊ฐ€์žฅ ์œ ์šฉํ•˜๊ฒŒ ์“ฐ์ด๋Š” ๊ฒฝ์šฐ๋Š” ์•„๋ž˜์ฒ˜๋Ÿผ ํ›„์† ์…€๋ ‰ํ„ฐ๋“ค์—๊ฒŒ ์†์„ฑ์„ ๋ถ€์—ฌํ•  ๋•Œ์ž…๋‹ˆ๋‹ค.

#black h2 {
  color: #000000; 
}

์œ„ ์˜ˆ์ œ๋Š” ํƒœ๊ทธid๊ฐ€ black์ธ ํƒœ๊ทธ๋‚ด์˜ h2ํƒœ๊ทธ์˜ ์ƒ‰๊น” ์†์„ฑ๊ฐ’์„ ์ง€์ •ํ•ด์ฃผ๋Š” ์˜ˆ์ œ์ฃ ? ์•„๋‹Œ๊ฐ€์š”? ๋งž์Šต๋‹ˆ๋‹ค. 

The Child Selectors ( ์ž์‹ ์…€๋ ‰ํ„ฐ )

์œ„์—์„œ ๋งํ•œ ํ›„์† ์…€๋ ‰ํ„ฐ๋Š” descendant ๋ผ๊ณ ํ•˜์—ฌ ๋ชจ๋“  ํ›„์†๋“ค์— ๋Œ€ํ•ด ์ ์šฉ์ด ๋ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด ์ž์‹ ์…€๋ ‰ํ„ฐ๋Š” ์ง๊ณ„ ์ž์‹๋งŒ ํ•ด๋‹น์ด ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ์ œ๋ฅผ ํ•œ๋ฒˆ ๋ณด์‹ค๊นŒ์š”.

body > p {
  color: #000000; 
}

<body> ํƒœ๊ทธ ๋ฐ”๋กœ ๋ฐ‘์— ์žˆ๋Š” <p> ์— ๋Œ€ํ•ด์„œ๋งŒ ์ ์šฉ๋˜๋Š” ์Šคํƒ€์ผ์„ ์ •์˜ํ–ˆ๊ตฐ์š”. body์•ˆ์˜ div์•ˆ์—์„œ ์‚ฌ์šฉ๋œ pํƒœ๊ทธ๋Š” ์œ„ ์Šคํƒ€์ผ์˜ ์ ์šฉ์„ ๋ฐ›์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

The Attribute Selectors ( ์†์„ฑ ์…€๋ ‰ํ„ฐ )

์•„๋ž˜ ์˜ˆ์ œ๋Š” inputํƒœ๊ทธ์˜ type์†์„ฑ์ด text์ธ ๋…€์„๋“ค์˜ ์ƒ‰์„ ์ง€์ •ํ•ด์ฃผ๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

input[type="text"]{
  color: #000000; 
}

์œ„์— ์ •์˜๋œ ์Šคํƒ€์ผ์€ <input type="submit" /> ์š”์†Œ์—๋Š” ์ ์šฉ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์ด์ฃ .

์•„๋ž˜๋Š” ์†์„ฑ ์…€๋ ‰ํ„ฐ์˜ ์‚ฌ์šฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

  • p[lang]lang ์†์„ฑ์„ ๊ฐ–๋Š” ๋ชจ๋“  ๋ฌธ๋‹จ์š”์†Œ๋ฅผ ์„ ํƒ.

  • p[lang="fr"] - lang attribute์ด "fr"์ธ ๋ชจ๋“  ๋ฌธ๋‹จ ์š”์†Œ๋ฅผ ์„ ํƒ.

  • p[lang~="fr"] - lang ์†์„ฑ์ด "fr"์„ ํฌํ•จํ•˜๋Š” ๋ชจ๋“  ๋ฌธ๋‹จ ์š”์†Œ๋ฅผ ์„ ํƒ.

  • p[lang|="en"] - lang ์†์„ฑ์ด "en"์ด๊ฑฐ๋‚˜ ๋˜๋Š” "en"์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ฌธ๋‹จ ์š”์†Œ๋ฅผ ์„ ํƒ.

Multiple Style Rules ( ๋‹ค์ค‘ ์Šคํƒ€์ผ ๊ทœ์น™ )

์ง€๊ธˆ๊นŒ์ง€๋Š” ํ•˜๋‚˜์˜ ์š”์†Œ์— ํ•˜๋‚˜์˜ ์Šคํƒ€์ผ๋งŒ ์ ์šฉ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์š”์†Œ๋งˆ๋‹ค ์—ฌ๋Ÿฌ๊ฐœ์˜ ์†์„ฑ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์œผ๋‹ˆ ์—ฌ๋Ÿฌ๊ฐœ์˜ ์Šคํƒ€์ผ์„ ์ง€์ •ํ•  ์ˆ˜๋„ ์žˆ์–ด์•ผ๊ฒ ์ฃ ?  

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

์œ„ ์˜ˆ์ œ์ฒ˜๋Ÿผ ์„ธ๋ฏธ์ฝœ๋ก  (;) ์œผ๋กœ ์Šคํƒ€์ผ์„ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ •์˜ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ฐ„๋‹จํ•˜์ฃ ?

๊ฐ ์†์„ฑ์— ์ง€์ •๋œ ์†์„ฑ๊ฐ’๋“ค์— ๋Œ€ํ•ด์„œ๋Š” ์ด๊ฒŒ ๋ญ”๊ฐ€ ํ•˜์‹ค ์ˆ˜๋„ ์žˆ๋Š”๋ฐ ์‹ ๊ฒฝ์“ฐ์ง€๋งˆ์‹œ๊ณ  ์ผ๋‹จ ๋„˜์–ด๊ฐ€์„ธ์š”. ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐฐ์šฐ๋ฉด ๋ฉ๋‹ˆ๋‹ค ^___^ 

Grouping Selectors ( ์…€๋ ‰ํ„ฐ ๊ทธ๋ฃนํ™” )

๋‚ด๊ฐ€ ์ง€์ •ํ•œ ์Šคํƒ€์ผ์„ ์—ฌ๋Ÿฌ๊ฐœ์˜ ์š”์†Œ์— ํ•œ๊บผ๋ฒˆ์—!!!!  ์ ์šฉํ•˜๊ณ  ์‹ถ์œผ์‹œ๋‹ค๋ฉด!!!!

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

์œ„ ์˜ˆ์ œ๋Š” h1, h2 and h3 ์š”์†Œ์— ํ•œ๊บผ๋ฒˆ์— ์Šคํƒ€์ผ์„ ์ ์šฉ์‹œํ‚ค๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค. ์ˆœ์„œ๋Š” ์ „ํ˜€ ์ƒ๊ด€์ด ์—†๊ตฌ์š” ์ฝค๋งˆ๋ฅผ ์ด์šฉํ•ด์„œ ์…€๋ ‰ํ„ฐ๋“ค์„ ๊ตฌ๋ถ„์ง€์–ด์ฃผ์‹œ๋ฉด ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์ฒ˜๋Ÿผ ์•„์ด๋”” ์…€๋ ‰ํ„ฐ๋ฅผ ์ด์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

#content, #footer, #supplement {
position: absolute;
left: 510px;
width: 200px;
}

ํด๋ž˜์Šค ์…€๋ ‰ํ„ฐ๋‚˜ ๋‹ค๋ฅธ ์…€๋ ‰ํ„ฐ๋“ค์„ ํ•จ๊ป˜ ์‚ฌ์šฉํ•ด๋ณด๋Š” ์—ฐ์Šต๋„ ํ•ด๋ณด์„ธ์š” ^____^

 

 

 

 

Reference : http://www.tutorialspoint.com/css/css_syntax.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] 3. HTML์— CSS๋งํฌ - Associating Styles with HTML  (0) 2016.06.12
[CSS] 1. CSS๋ž€ ?  (0) 2016.06.11

jQuery provides a trivially simple interface for doing various kind of amazing effects. jQuery methods allow us to quickly apply commonly used effects with a minimum configuration.

This tutorial covers all the important jQuery methods to create visual effects.


์š”์†Œ ์ˆจ๊ธฐ๊ธฐ์™€ ๋ณด์ด๊ธฐ

The commands for showing and hiding elements are pretty much what we would expect: show() to show the elements in a wrapped set and hide() to hide them.

๋ฌธ๋ฒ•:

Here is the simple syntax for show() method:

[selector].show( speed, [callback] );

Here is the description of all the parameters:

  • speed: A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).

  • callback: This optional parameter represents a function to be executed whenever the animation completes; executes once for each element animated against.

Following is the simple syntax for hide() method:

[selector].hide( speed, [callback] );

Here is the description of all the parameters:

  • speed: A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).

  • callback: This optional parameter represents a function to be executed whenever the animation completes; executes once for each element animated against.

์˜ˆ์ œ:

Consider the following HTML file with a small JQuery coding:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {

     $("#show").click(function () {
        $(".mydiv").show( 1000 );
     });

     $("#hide").click(function () {
        $(".mydiv").hide( 1000 );
     });

   });

   </script>
   <style>
   .mydiv{ margin:10px;padding:12px;
      border:2px solid #666;
      width:100px;
      height:100px;
    }
  </style>
</head>
<body>
   <div class="mydiv">
      This is  SQUAR
   </div>

   <input id="hide" type="button" value="Hide" />   
   <input id="show" type="button" value="Show" />   

</body>
</html>

 

 

์š”์†Œ ํ† ๊ธ€๋ง

jQuery provides methods to toggle the display state of elements between revealed or hidden. If the element is initially displayed, it will be hidden; if hidden, it will be shown.

๋ฌธ๋ฒ•:

Here is the simple syntax for one of the toggle() methods:

[selector]..toggle([speed][, callback]);

Here is the description of all the parameters:

  • speed: A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).

  • callback: This optional parameter represents a function to be executed whenever the animation completes; executes once for each element animated against.

์˜ˆ์ œ:

We can animate any element, such as a simple <div> containing an image:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">

   $(document).ready(function() {
      $(".clickme").click(function(event){
          $(".target").toggle('slow', function(){
             $(".log").text('Transition Complete');
          });
      });

   });
   </script>
   <style>
   .clickme{ margin:10px;padding:12px;
      border:2px solid #666;
      width:100px;
      height:50px;
    }
   </style>
</head>
<body>
   <div class="content">
      <div class="clickme">Click Me</div>
      <div class="target">
         <img src="/images/jquery.jpg" alt="jQuery" />
      </div>
      <div class="log"></div>
</body>
</html>

 

 

JQuery ํšจ๊ณผ ๊ด€๋ จ ๋ฉ”์†Œ๋“œ ๋ชฉ๋ก

 

Methods and Description
animate( params, [duration, easing, callback] )
A function for making custom animations.
fadeIn( speed, [callback] )
Fade in all matched elements by adjusting their opacity and firing an optional callback after completion.
fadeOut( speed, [callback] )
Fade out all matched elements by adjusting their opacity to 0, then setting display to "none" and firing an optional callback after completion.
fadeTo( speed, opacity, callback )
Fade the opacity of all matched elements to a specified opacity and firing an optional callback after completion.
hide( )
Hides each of the set of matched elements if they are shown.
hide( speed, [callback] )
Hide all matched elements using a graceful animation and firing an optional callback after completion.
show( )
Displays each of the set of matched elements if they are hidden.
show( speed, [callback] )
Show all matched elements using a graceful animation and firing an optional callback after completion.
slideDown( speed, [callback] )
Reveal all matched elements by adjusting their height and firing an optional callback after completion.
slideToggle( speed, [callback] )
Toggle the visibility of all matched elements by adjusting their height and firing an optional callback after completion.
slideUp( speed, [callback] )
Hide all matched elements by adjusting their height and firing an optional callback after completion.
stop( [clearQueue, gotoEnd ])
Stops all the currently running animations on all the specified elements.
toggle( )
Toggle displaying each of the set of matched elements.
toggle( speed, [callback] )
Toggle displaying each of the set of matched elements using a graceful animation and firing an optional callback after completion.
toggle( switch )
Toggle displaying each of the set of matched elements based upon the switch (true shows all elements, false hides all elements).
jQuery.fx.off
Globally disable all animations.


UI ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ œ๊ณตํ•˜๋Š” ํšจ๊ณผ ๋ชฉ๋ก

To use these effects you would have to download jQuery UI Library jquery-ui-1.7.2.custom.min.js or latest version of this UI library from jQuery UI Library.

After extracting jquery-ui-1.7.2.custom.min.js file from the download, you would include this file in similar way as you include core jQuery Library file.

Methods and Description
Blind
Blinds the element away or shows it by blinding it in.
Bounce
Bounces the element vertically or horizontally n-times.
Clip
Clips the element on or off, vertically or horizontally.
Drop
Drops the element away or shows it by dropping it in.
Explode
Explodes the element into multiple pieces.
Fold
Folds the element like a piece of paper.
Highlight
Highlights the background with a defined color.
Puff
Scale and fade out animations create the puff effect.
Pulsate
Pulsates the opacity of the element multiple times.
Scale
Shrink or grow an element by a percentage factor.
Shake
Shakes the element vertically or horizontally n-times.
Size
Resize an element to a specified width and height.
Slide
Slides the element out of the viewport.
Transfer
Transfers the outline of an element to another.

 

 

 

 

Reference : http://www.tutorialspoint.com/jquery/jquery-effects.htm 

 

 

 

 

AJAX is an acronym standing for Asynchronous JavaScript and XML and this technology help us to load data from the server without a browser page refresh.

If you are new with AJAX, I would recommend you go through our Ajax Tutorial before proceeding further.

JQuery is a great tool which provides a rich set of AJAX methods to develope next generation web application.


๋ฐ์ดํƒ€ ๋กœ๋”ฉํ•˜๊ธฐ

This is very easy to load any static or dynamic data using JQuery AJAX. JQuery provides load() method to do the job:

๋ฌธ๋ฒ•:

Here is the simple syntax for load() method:

[selector].load( URL, [data], [callback] );

Here is the description of all the parameters:

  • URL: The URL of the server-side resource to which the request is sent. It could be a CGI, ASP, JSP, or PHP script which generates data dynamically or out of a database.

  • data: This optional parameter represents an object whose properties are serialized into properly encoded parameters to be passed to the request. If specified, the request is made using the POST method. If omitted, the GET method is used.

  • callback: A callback function invoked after the response data has been loaded into the elements of the matched set. The first parameter passed to this function is the response text recieved from the server and second parameter is the status code.

์˜ˆ์ œ:

Consider the following HTML file with a small JQuery coding:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   $(document).ready(function() {
      $("#driver").click(function(event){
          $('#stage').load('/jquery/result.html');
      });
   });
   </script>
</head>
<body>
   <p>Click on the button to load result.html file:</p>
   <div id="stage" style="background-color:blue;">
          STAGE
   </div>
   <input type="button" id="driver" value="Load Data" />
</body>
</html>

Here load() initiates an Ajax request to the specified URL /jquery/result.html file. After loading this file, all the content would be populated inside <div> tagged with ID stage. Assuming, our /jquery/result.html file has just one HTML line:

   <h1>THIS IS RESULT...</h1>

When you click the given button, then result.html file gets loaded. 


JSON ๋ฐ์ดํƒ€ ์ฝ์–ด์˜ค๊ธฐ

There would be a situation when server would return JSON string against your request. JQuery utility function getJSON() parses the returned JSON string and makes the resulting string available to the callback function as first parameter to take further action.

๋ฌธ๋ฒ•:

Here is the simple syntax for getJSON() method:

[selector].getJSON( URL, [data], [callback] );

Here is the description of all the parameters:

  • URL: The URL of the server-side resource contacted via the GET method.

  • data: An object whose properties serve as the name/value pairs used to construct a query string to be appended to the URL, or a preformatted and encoded query string.

  • callback: A function invoked when the request completes. The data value resulting from digesting the response body as a JSON string is passed as the first parameter to this callback, and the status as the second.

์˜ˆ์ œ:

Consider the following HTML file with a small JQuery coding:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   $(document).ready(function() {
      $("#driver").click(function(event){
          $.getJSON('/jquery/result.json', function(jd) {
             $('#stage').html('<p> Name: ' + jd.name + '</p>');
             $('#stage').append('<p>Age : ' + jd.age+ '</p>');
             $('#stage').append('<p> Sex: ' + jd.sex+ '</p>');
          });
      });
   });
   </script>
</head>
<body>
   <p>Click on the button to load result.html file:</p>
   <div id="stage" style="background-color:blue;">
          STAGE
   </div>
   <input type="button" id="driver" value="Load Data" />
</body>
</html>

Here JQuery utility method getJSON() initiates an Ajax request to the specified URL /jquery/result.json file. After loading this file, all the content would be passed to the callback function which finally would be populated inside <div> tagged with ID stage. Assuming, our /jquery/result.json file has following json formatted content:

{
"name": "Zara Ali",
"age" : "67",
"sex": "female"
}

When you click the given button, then result.json file gets loaded.


์„œ๋ฒ„๋กœ ๋ฐ์ดํƒ€ ์ „๋‹ฌํ•˜๊ธฐ

Many times you collect input from the user and you pass that input to the server for further processing. JQuery AJAX made it easy enough to pass collected data to the server using data parameter of any available Ajax method.

์˜ˆ์ œ:

This example demonstrate how can pass user input to a web server script which would send the same result back and we would print it:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   $(document).ready(function() {
      $("#driver").click(function(event){
          var name = $("#name").val();
          $("#stage").load('/jquery/result.php', {"name":name} );
      });
   });
   </script>
</head>
<body>
   <p>Enter your name and click on the button:</p>
   <input type="input" id="name" size="40" /><br />
   <div id="stage" style="background-color:blue;">
          STAGE
   </div>
   <input type="button" id="driver" value="Show Result" />
</body>
</html>

Here is the code written in result.php script:

<?php
if( $_REQUEST["name"] )
{
   $name = $_REQUEST['name'];
   echo "Welcome ". $name;
}
?> 

Now you can enter any text in the given input box and then click "Show Result" button to see what you have entered in the input box. 


JQuery์—์„œ ์‚ฌ์šฉ๋˜๋Š” AJAX ๋ฉ”์†Œ๋“œ ๋ชฉ๋ก

 

Methods and Description
jQuery.ajax( options )
Load a remote page using an HTTP request.
jQuery.ajaxSetup( options )
Setup global settings for AJAX requests.
jQuery.get( url, [data], [callback], [type] )
Load a remote page using an HTTP GET request.
jQuery.getJSON( url, [data], [callback] )
Load JSON data using an HTTP GET request.
jQuery.getScript( url, [callback] )
Loads and executes a JavaScript file using an HTTP GET request.
jQuery.post( url, [data], [callback], [type] )
Load a remote page using an HTTP POST request.
load( url, [data], [callback] )
Load HTML from a remote file and inject it into the DOM.
serialize( )
Serializes a set of input elements into a string of data.
serializeArray( )
Serializes all forms and form elements like the .serialize() method but returns a JSON data structure for you to work with.


JQuery AJAX ์ด๋ฒคํŠธ ๋ชฉ๋ก


Methods and Description
ajaxComplete( callback )
Attach a function to be executed whenever an AJAX request completes.
ajaxStart( callback )
Attach a function to be executed whenever an AJAX request begins and there is none already active.
ajaxError( callback )
Attach a function to be executed whenever an AJAX request fails.
ajaxSend( callback )
Attach a function to be executed before an AJAX request is sent.
ajaxStop( callback )
Attach a function to be executed whenever all AJAX requests have ended.
ajaxSuccess( callback )
Attach a function to be executed whenever an AJAX request completes successfully.

 

 

 

 

Reference : http://www.tutorialspoint.com/jquery/jquery-ajax.htm

 

 

 

 

We have the ability to create dynamic web pages by using events. Events are actions that can be detected by your Web Application.

Following are the examples events:

  • A mouse click
  • A web page loading
  • Taking mouse over an element
  • Submitting an HTML form
  • A keystroke on your keyboard
  • etc.

When these events are triggered you can then use a custom function to do pretty much whatever you want with the event. These custom functions call Event Handlers.


์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ๋ฐ”์ธ๋”ฉํ•˜๊ธฐ

Using the jQuery Event Model, we can establish event handlers on DOM elements with the bind() method as follows:

$('div').bind('click', function( event ){
   alert('Hi there!');
});

This code will cause the division element to respond to the click event; when a user clicks inside this division thereafter, the alert will be shown.

The full syntax of the bind() command is as follows:

selector.bind( eventType[, eventData], handler)

Following is the description of the parameters:

  • eventType: A string containing a JavaScript event type, such as click or submit. Refer to the next section for a complete list of event types.

  • eventData: This is optional parameter is a map of data that will be passed to the event handler.

  • handler: A function to execute each time the event is triggered.


์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์‚ญ์ œํ•˜๊ธฐ

Typically, once an event handler is established, it remains in effect for the remainder of the life of the page. There may be a need when you would like to remove event handler.

jQuery provides the unbind() command to remove an exiting event handler. The syntax of unbind() is as follows:

selector.unbind(eventType, handler)

or 

selector.unbind(eventType)

Following is the description of the parameters:

  • eventType: A string containing a JavaScript event type, such as click or submit. Refer to the next section for a complete list of event types.

  • handler: If provided, identifies the specific listener that has to be removed.


์ด๋ฒคํŠธ ํƒ€์ž…

The following are cross platform and recommended event types which you can bind using JQuery:

Event TypeDescription
blurOccurs when the element loses focus
changeOccurs when the element changes
clickOccurs when a mouse click
dblclickOccurs when a mouse double-click
errorOccurs when there is an error in loading or unloading etc.
focusOccurs when the element gets focus
keydownOccurs when key is pressed
keypressOccurs when key is pressed and released
keyupOccurs when key is released
loadOccurs when document is loaded
mousedownOccurs when mouse button is pressed
mouseenterOccurs when mouse enters in an element region
mouseleaveOccurs when mouse leaves an element region
mousemoveOccurs when mouse pointer moves
mouseoutOccurs when mouse pointer moves out of an element
mouseoverOccurs when mouse pointer moves over an element
mouseupOccurs when mouse button is released
resizeOccurs when window is resized
scrollOccurs when window is scrolled
selectOccurs when a text is selected
submitOccurs when form is submitted
unloadOccurs when documents is unloaded


์ด๋ฒคํŠธ ๊ฐ์ฒด

The callback function takes a single parameter; when the handler is called the JavaScript event object will be passed through it.

The event object is often unneccessary and the parameter is omitted, as sufficient context is usually available when the handler is bound to know exactly what needs to be done when the handler is triggered, however there are certail attributes which you would need to be accessed.

์ด๋ฒคํŠธ ์†์„ฑ

The following event properties/attributes are available and safe to access in a platform independent manner:

PropertyDescription
altKeySet to true if the Alt key was pressed when the event was triggered, false if not. The Alt key is labeled Option on most Mac keyboards.
ctrlKeySet to true if the Ctrl key was pressed when the event was triggered, false if not.
dataThe value, if any, passed as the second parameter to the bind() command when the handler was established.
keyCodeFor keyup and keydown events, this returns the key that was pressed.
metaKeySet to true if the Meta key was pressed when the event was triggered, false if not. The Meta key is the Ctrl key on PCs and the Command key on Macs.
pageXFor mouse events, specifies the horizontal coordinate of the event relative from the page origin.
pageYFor mouse events, specifies the vertical coordinate of the event relative from the page origin.
relatedTargetFor some mouse events, identifies the element that the cursor left or entered when the event was triggered.
screenXFor mouse events, specifies the horizontal coordinate of the event relative from the screen origin.
screenYFor mouse events, specifies the vertical coordinate of the event relative from the screen origin.
shiftKeySet to true if the Shift key was pressed when the event was triggered, false if not.
targetIdentifies the element for which the event was triggered.
timeStampThe timestamp (in milliseconds) when the event was created.
typeFor all events, specifies the type of event that was triggered (for example, click).
whichFor keyboard events, specifies the numeric code for the key that caused the event, and for mouse events, specifies which button was pressed (1 for left, 2 for middle, 3 for right)

 

 

์ด๋ฒคํŠธ ๊ฐ์ฒด์˜ ๋ฉ”์†Œ๋“œ

There is a list of methods which can be called on an Event Object:

MethodDescription
preventDefault()Prevents the browser from executing the default action.
isDefaultPrevented()Returns whether event.preventDefault() was ever called on this event object.
stopPropagation() Stops the bubbling of an event to parent elements, preventing any parent handlers from being notified of the event.
isPropagationStopped() Returns whether event.stopPropagation() was ever called on this event object.
stopImmediatePropagation() Stops the rest of the handlers from being executed.
isImmediatePropagationStopped()Returns whether event.stopImmediatePropagation() was ever called on this event object.


์ด๋ฒคํŠธ ์กฐ์ž‘ ๊ด€๋ จ ๋ฉ”์†Œ๋“œ

Following table lists down important event-related methods:

MethodDescription
bind( type, [data], fn )Binds a handler to one or more events (like click) for each matched element. Can also bind custom events.
die( type, fn )This does the opposite of live, it removes a bound live event.
hover( over, out )Simulates hovering for example moving the mouse on, and off, an object.
live( type, fn )Binds a handler to an event (like click) for all current - and future - matched element. Can also bind custom events.
one( type, [data], fn )Binds a handler to one or more events to be executed once for each matched element.
ready( fn )Binds a function to be executed whenever the DOM is ready to be traversed and manipulated.
toggle( fn, fn2, fn3,... )Toggle among two or more function calls every other click.
trigger( event, [data] )Trigger an event on every matched element.
triggerHandler( event, [data] )Triggers all bound event handlers on an element .
unbind( [type], [fn] )This does the opposite of bind, it removes bound events from each of the matched elements.


์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ๋ฉ”์†Œ๋“œ

jQuery also provides a set of event helper functions which can be used either to trigger an event to bind any event types mentioned above.

ํŠธ๋ฆฌ๊ฑฐ ๋ฉ”์†Œ๋“œ

Following is an example which would triggers the blur event on all paragraphs:

$("p").blur();

๋ฐ”์ธ๋”ฉ ๋ฉ”์†Œ๋“œ

Following is an example which would bind a click event on all the <div>:

$("div").click( function () { 
   // do something here
});

 

 

Here is a complete list of all the support methods provided by jQuery:

MethodDescription
blur( )Triggers the blur event of each matched element.
blur( fn )Bind a function to the blur event of each matched element.
change( )Triggers the change event of each matched element.
change( fn )Binds a function to the change event of each matched element.
click( )Triggers the click event of each matched element.
click( fn )Binds a function to the click event of each matched element.
dblclick( )Triggers the dblclick event of each matched element.
dblclick( fn )Binds a function to the dblclick event of each matched element.
error( )Triggers the error event of each matched element.
error( fn )Binds a function to the error event of each matched element.
focus( )Triggers the focus event of each matched element.
focus( fn )Binds a function to the focus event of each matched element.
keydown( )Triggers the keydown event of each matched element.
keydown( fn )Bind a function to the keydown event of each matched element.
keypress( )Triggers the keypress event of each matched element.
keypress( fn )Binds a function to the keypress event of each matched element.
keyup( )Triggers the keyup event of each matched element.
keyup( fn )Bind a function to the keyup event of each matched element.
load( fn )Binds a function to the load event of each matched element.
mousedown( fn )Binds a function to the mousedown event of each matched element.
mouseenter( fn )Bind a function to the mouseenter event of each matched element.
mouseleave( fn )Bind a function to the mouseleave event of each matched element.
mousemove( fn )Bind a function to the mousemove event of each matched element.
mouseout( fn )Bind a function to the mouseout event of each matched element.
mouseover( fn )Bind a function to the mouseover event of each matched element.
mouseup( fn )Bind a function to the mouseup event of each matched element.
resize( fn )Bind a function to the resize event of each matched element.
scroll( fn )Bind a function to the scroll event of each matched element.
select( )Trigger the select event of each matched element.
select( fn )Bind a function to the select event of each matched element.
submit( )Trigger the submit event of each matched element.
submit( fn )Bind a function to the submit event of each matched element.
unload( fn )Binds a function to the unload event of each matched element.

 

 

 

 

 

 Reference : http://www.tutorialspoint.com/jquery/jquery-events.htm

 

 

 

 

 

JQuery provides methods to manipulate DOM in efficient way. You do not need to write big code to modify the value of any element's attribute or to extract HTML code from a paragraph or division.

JQuery provides methods such as .attr(), .html(), and .val() which act as getters, retrieving information from DOM elements for later use.

์ปจํ…์ธ  ์กฐ์ž‘:

The html( ) method gets the html contents (innerHTML) of the first matched element.

Here is the syntax for the method:

selector.html( )

์˜ˆ์ œ:

Following is an example which makes use of .html() and .text(val) methods. Here .html() retrieves HTML content from the object and then .text( val ) method sets value of the object using passed parameter:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {

     $("div").click(function () {
      var content = $(this).html();
      $("#result").text( content );
    });

   });

   </script>
   <style>
      #division{ margin:10px;padding:12px;
                 border:2px solid #666;
                 width:60px;
               }
  </style>
</head>
<body>
   <p>Click on the square below:</p>
   <span id="result"> </span>
   <div id="division" style="background-color:blue;">
     This is Blue Square!!
   </div>
</body>
</html>

 

 

DOM ์š”์†Œ ๋ณ€๊ฒฝ

You can replace a complete DOM element with the specified HTML or DOM elements. The replaceWith( content ) method serves this purpose very well.

Here is the syntax for the method:

selector.replaceWith( content )

Here content is what you want to have instead of original element. This could be HTML or simple text.

์˜ˆ์ œ:

Following is an example which would replace division element with "<h1>JQuery is Great</h1>":

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {

     $("div").click(function () {
       $(this).replaceWith("<h1>JQuery is Great</h1>");
    });

   });

   </script>
   <style>
      #division{ margin:10px;padding:12px;
                 border:2px solid #666;
                 width:60px;
               }
  </style>
</head>
<body>
   <p>Click on the square below:</p>
   <span id="result"> </span>
   <div id="division" style="background-color:blue;">
     This is Blue Square!!
   </div>
</body>
</html>

 

 

DOM ์š”์†Œ ์‚ญ์ œ

There may be a situation when you would like to remove one or more DOM elements from the document. JQuery provides two methods to handle the situation.

The empty( ) method remove all child nodes from the set of matched elements where as the method remove( expr ) method removes all matched elements from the DOM.

Here is the syntax for the method:

selector.remove( [ expr ])

or 

selector.empty( )

You can pass optional paramter expr to filter the set of elements to be removed.

์˜ˆ์ œ:

Following is an example where elements are being removed as soon as they are clicked:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {

     $("div").click(function () {
       $(this).remove( );
    });

   });

   </script>
   <style>
      .div{ margin:10px;padding:12px;
             border:2px solid #666;
             width:60px;
           }
  </style>
</head>
<body>
   <p>Click on any square below:</p>
   <span id="result"> </span>
   <div class="div" style="background-color:blue;"></div>
   <div class="div" style="background-color:green;"></div>
   <div class="div" style="background-color:red;"></div>
</body>
</html>

 

 

DOM ์š”์†Œ ์ถ”๊ฐ€

There may be a situation when you would like to insert new one or more DOM elements in your existing document. JQuery provides various methods to insert elements at various locations.

The after( content ) method insert content after each of the matched elements where as the method before( content ) method inserts content before each of the matched elements.

Here is the syntax for the method:

selector.after( content )

or

selector.before( content )

Here content is what you want to insert. This could be HTML or simple text.

์˜ˆ์ œ:

Following is an example where <div> elements are being inserted just before the clicked element:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {

     $("div").click(function () {
       $(this).before('<div class="div"></div>' );
    });

   });

   </script>
   <style>
      .div{ margin:10px;padding:12px;
             border:2px solid #666;
             width:60px;
           }
  </style>
</head>
<body>
   <p>Click on any square below:</p>
   <span id="result"> </span>
   <div class="div" style="background-color:blue;"></div>
   <div class="div" style="background-color:green;"></div>
   <div class="div" style="background-color:red;"></div>
</body>
</html>

 

 

DOM ์กฐ์ž‘ ๊ด€๋ จ ๋ฉ”์†Œ๋“œ ๋ชฉ๋ก

 

MethodDescription
after( content )Insert content after each of the matched elements.
append( content )Append content to the inside of every matched element.
appendTo( selector )Append all of the matched elements to another, specified, set of elements.
before( content )Insert content before each of the matched elements.
clone( bool )Clone matched DOM Elements, and all their event handlers, and select the clones.
clone( )Clone matched DOM Elements and select the clones.
empty( )Remove all child nodes from the set of matched elements.
html( val )Set the html contents of every matched element.
html( )Get the html contents (innerHTML) of the first matched element.
insertAfter( selector )Insert all of the matched elements after another, specified, set of elements.
insertBefore( selector )Insert all of the matched elements before another, specified, set of elements.
prepend( content )Prepend content to the inside of every matched element.
prependTo( selector )Prepend all of the matched elements to another, specified, set of elements.
remove( expr )Removes all matched elements from the DOM.
replaceAll( selector )Replaces the elements matched by the specified selector with the matched elements.
replaceWith( content )Replaces all matched elements with the specified HTML or DOM elements.
text( val )Set the text contents of all matched elements.
text( )Get the combined text contents of all matched elements.
wrap( elem )Wrap each matched element with the specified element.
wrap( html )Wrap each matched element with the specified HTML content.
wrapAll( elem )Wrap all the elements in the matched set into a single wrapper element.
wrapAll( html )Wrap all the elements in the matched set into a single wrapper element.
wrapInner( elem )Wrap the inner child contents of each matched element (including text nodes) with a DOM element.
wrapInner( html )Wrap the inner child contents of each matched element (including text nodes) with an HTML structure.

 

 

 

 

Reference : http://www.tutorialspoint.com/jquery/jquery-dom.htm

 

 

 

 

 

The jQuery library supports nearly all of the selectors included in Cascading Style Sheet (CSS) specifications 1 through 3, as outlined on the World Wide Web Consortium's site.

Using JQuery library developers can enhance their websites without worrying about browsers and their versions as long as the browsers have JavaScript enabled.

Most of the JQuery CSS Methods do not modify the content of the jQuery object and they are used to apply CSS properties on DOM elements.


CSS ์†์„ฑ ์ ์šฉํ•˜๊ธฐ

This is very simple to apply any CSS property using JQuery method css( PropertyName, PropertyValue ).

Here is the syntax for the method:

selector.css( PropertyName, PropertyValue );

Here you can pass PropertyName as a javascript string and based on its value, PropertyValue could be string or integer.

์˜ˆ์ œ:

Following is an example which adds font color to the second list item.

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {
      $("li").eq(2).css("color", "red");
   });

   </script>
</head>
<body>
   <div>
   <ul>
     <li>list item 1</li>
     <li>list item 2</li>
     <li>list item 3</li>
     <li>list item 4</li>
     <li>list item 5</li>
     <li>list item 6</li>
   </ul>
   </div>
</body>
</html>

 

 

CSS ์†์„ฑ ๋‹ค์ค‘ ์ ์šฉํ•˜๊ธฐ

You can apply multiple CSS properties using a single JQuery method CSS( {key1:val1, key2:val2....). You can apply as many properties as you like in a single call.

Here is the syntax for the method:

selector.css( {key1:val1, key2:val2....keyN:valN})

Here you can pass key as property and val as its value as described above.

์˜ˆ์ œ:

Following is an example which adds font color as well as background color to the second list item.

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {
      $("li").eq(2).css({"color":"red", 
                         "background-color":"green"});
   });

   </script>
</head>
<body>
   <div>
   <ul>
     <li>list item 1</li>
     <li>list item 2</li>
     <li>list item 3</li>
     <li>list item 4</li>
     <li>list item 5</li>
     <li>list item 6</li>
   </ul>
   </div>
</body>
</html>

 

 

์š”์†Œ์˜ Width & Height ์„ธํŒ…ํ•˜๊ธฐ

The width( val ) and height( val ) method can be used to set the width and hieght respectively of any element.

์˜ˆ์ œ:

Following is a simple example which sets the width of first division element where as rest of the elements have width set by style sheet:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {
      $("div:first").width(100);
      $("div:first").css("background-color", "blue");
   });

   </script>
   <style>
   div{ width:70px; height:50px; float:left; margin:5px;
      background:red; cursor:pointer; }
  </style>
</head>
<body>
  <div></div>
  <div>d</div>
  <div>d</div>
  <div>d</div>
  <div>d</div>
</body>
</html>

 

 

JQuery CSS ๋ฉ”์†Œ๋“œ

๋‹ค์Œ์€ CSS ์†์„ฑ๊ณผ ๊ด€๋ จ์žˆ๋Š” ๋ชจ๋“  ๋ฉ”์†Œ๋“œ ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค. 

MethodDescription
css( name )Return a style property on the first matched element.
css( name, value )Set a single style property to a value on all matched elements.
css( properties )Set a key/value object as style properties to all matched elements.
height( val )Set the CSS height of every matched element.
height( )Get the current computed, pixel, height of the first matched element.
innerHeight( )Gets the inner height (excludes the border and includes the padding) for the first matched element.
innerWidth( )Gets the inner width (excludes the border and includes the padding) for the first matched element.
offset( )Get the current offset of the first matched element, in pixels, relative to the document
offsetParent( )Returns a jQuery collection with the positioned parent of the first matched element.
outerHeight( [margin] )Gets the outer height (includes the border and padding by default) for the first matched element.
outerWidth( [margin] )Get the outer width (includes the border and padding by default) for the first matched element.
position( )Gets the top and left position of an element relative to its offset parent.
scrollLeft( val )When a value is passed in, the scroll left offset is set to that value on all matched elements.
scrollLeft( )Gets the scroll left offset of the first matched element.
scrollTop( val )When a value is passed in, the scroll top offset is set to that value on all matched elements.
scrollTop( )Gets the scroll top offset of the first matched element.
width( val )Set the CSS width of every matched element.
width( )Get the current computed, pixel, width of the first matched element.

 

 

 

 

  

Reference : http://www.tutorialspoint.com/jquery/jquery-css.htm

 

 

 

 

jQuery is a very powerful tool which provides a variety of DOM traversal methods to help us select elements in a document randomly as well as in sequential method.

Most of the DOM Traversal Methods do not modify the jQuery object and they are used to filter out elements from a document based on given conditions.


์ธ๋ฑ์Šค๋ฅผ ์ด์šฉํ•œ ๋” ์š”์†Œ ์ฐพ๊ธฐ

Consider a simple document with the following HTML content:

<html>
<head>
<title>the title</title>
</head>
<body>
   <div>
   <ul>
     <li>list item 1</li>
     <li>list item 2</li>
     <li>list item 3</li>
     <li>list item 4</li>
     <li>list item 5</li>
     <li>list item 6</li>
   </ul>
   </div>
</body>
</html>
  • Above every list has its own index, and can be located directly by using eq(index) method as below example.

  • Every child element starts its index from zero, thus, list item 2 would be accessed by using $("li").eq(1) and so on.

์˜ˆ์ œ:

Following is a simple example which adds the color to second list item.

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {
      $("li").eq(2).addClass("selected");
   });

   </script>
   <style>
      .selected { color:red; }
  </style>
</head>
<body>
   <div>
   <ul>
     <li>list item 1</li>
     <li>list item 2</li>
     <li>list item 3</li>
     <li>list item 4</li>
     <li>list item 5</li>
     <li>list item 6</li>
   </ul>
   </div>
</body>
</html>

 

 

์š”์†Œ ํ•„ํ„ฐ๋งํ•˜๊ธฐ

The filter( selector ) method can be used to filter out all elements from the set of matched elements that do not match the specified selector(s). The selector can be written using any selector syntax.

์˜ˆ์ œ:

Following is a simple example which applies color to the lists associated with middle class:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {
      $("li").filter(".middle").addClass("selected");
   });

   </script>
   <style>
      .selected { color:red; }
  </style>
</head>
<body>
   <div>
   <ul>
     <li class="top">list item 1</li>
     <li class="top">list item 2</li>
     <li class="middle">list item 3</li>
     <li class="middle">list item 4</li>
     <li class="bottom">list item 5</li>
     <li class="bottom">list item 6</li>
   </ul>
   </div>
</body>
</html>

 

 

๋‚ด๋ถ€ ์š”์†Œ ์ฐพ๊ธฐ

The find( selector ) method can be used to locate all the descendent elements of a particular type of elements. The selector can be written using any selector syntax.

์˜ˆ์ œ:

Following is an example which selects all the <span> elements available inside different <p> elements:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">

   $(document).ready(function() {
      $("p").find("span").addClass("selected");
   });

   </script>
   <style>
      .selected { color:red; }
  </style>
</head>
<body>
   <p>This is 1st paragraph and <span>THIS IS RED</span></p>
   <p>This is 2nd paragraph and <span>THIS IS ALSO RED</span></p>
</body>
</html>

 

 

์œ ์šฉํ•œ JQuery DOM Traversing ๋ฉ”์†Œ๋“œ

 Following table lists down useful methods which you can use to filter out various elements from a list of DOM elements:

SelectorDescription
eq( index )Reduce the set of matched elements to a single element.
filter( selector )Removes all elements from the set of matched elements that do not match the specified selector(s).
filter( fn )Removes all elements from the set of matched elements that do not match the specified function.
is( selector )Checks the current selection against an expression and returns true, if at least one element of the selection fits the given selector.
map( callback )Translate a set of elements in the jQuery object into another set of values in a jQuery array (which may, or may not contain elements).
not( selector )Removes elements matching the specified selector from the set of matched elements.
slice( start, [end] )Selects a subset of the matched elements.

 

 

 

Following table lists down other useful methods which you can use to locate various elements in a DOM:

SelectorDescription
add( selector )Adds more elements, matched by the given selector, to the set of matched elements.
andSelf( )Add the previous selection to the current selection.
children( [selector])Get a set of elements containing all of the unique immediate children of each of the matched set of elements.
closest( selector )Get a set of elements containing the closest parent element that matches the specified selector, the starting element included.
contents( )Find all the child nodes inside the matched elements (including text nodes), or the content document, if the element is an iframe.
end( )Revert the most recent 'destructive' operation, changing the set of matched elements to its previous state .
find( selector )Searches for descendent elements that match the specified selectors.
next( [selector] )Get a set of elements containing the unique next siblings of each of the given set of elements.
nextAll( [selector] )Find all sibling elements after the current element.
offsetParent( )Returns a jQuery collection with the positioned parent of the first matched element.
parent( [selector] )Get the direct parent of an element. If called on a set of elements, parent returns a set of their unique direct parent elements.
parents( [selector] )Get a set of elements containing the unique ancestors of the matched set of elements (except for the root element).
prev( [selector] )Get a set of elements containing the unique previous siblings of each of the matched set of elements.
prevAll( [selector] )Find all sibling elements in front of the current element.
siblings( [selector] )Get a set of elements containing all of the unique siblings of each of the matched set of elements.

 

 

 

 

 

Reference : http://www.tutorialspoint.com/jquery/jquery-traversing.htm

 

 

 

 

 

Some of the most basic components we can manipulate when it comes to DOM elements are the properties and attributes assigned to those elements.

Most of these attributes are available through JavaScript as DOM node properties. Some of the more common properties are:

  • className

  • tagName

  • id

  • href

  • title

  • rel

  • src

Consider the following HTML markup for an image element:

<img id="myImage" src="image.gif" alt="An image" 
class="someClass" title="This is an image"/>

In this element's markup, the tag name is img, and the markup for id, src, alt, class, and title represents the element's attributes, each of which consists of a name and a value.

jQuery gives us the means to easily manipulate an element's attributes and gives us access to the element so that we can also change its properties.


์†์„ฑ๊ฐ’ ์ฝ์–ด์˜ค๊ธฐ

์†์„ฑ๊ฐ’์€ attr(name) ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ฝ์–ด์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ:

์•„๋ž˜ ์˜ˆ์ œ๋Š” em์š”์†Œ์˜ title์†์„ฑ์— ์ง€์ •๋œ ๊ฐ’์„ ์ฝ์–ด์™€์„œ div์š”์†Œ์— ์ถœ๋ ฅํ•˜๋Š” ์˜ˆ์ œ๋„ค์š”.

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">

   $(document).ready(function() {
      var title = $("em").attr("title");
      $("#divid").text(title);
   });

   </script>
</head>
<body>
   <div>
      <em title="Bold and Brave">This is first paragraph.</em>
      <p id="myid">This is second paragraph.</p>
      <div id="divid"></div>
   </div>
</body>
</html>

 

 

์†์„ฑ๊ฐ’ ์ˆ˜์ •ํ•˜๊ธฐ

 attr(name, value) ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ ํŠน์ • ์†์„ฑ๋ช…์— ๋Œ€ํ•œ ์†์„ฑ๊ฐ’์„ ์„ค์ •ํ•ด์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ:

์•„๋ž˜ ์˜ˆ์ œ๋Š” src ์†์„ฑ์— ํŠน์ • ํŒŒ์ผ๊ฒฝ๋กœ๋ฅผ ์„ค์ •ํ•ด์ฃผ๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">

   $(document).ready(function() {
      $("#myimg").attr("src", "/images/jquery.jpg");
   });

   </script>
</head>
<body>
   <div>
      <img id="myimg" src="/wongpath.jpg" alt="Sample image" />
   </div>
</body>
</html>

 

 

์Šคํƒ€์ผ ์ ์šฉํ•˜๊ธฐ

 addClass( classes ) ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ •์˜ํ•œ ์Šคํƒ€์ผ์„ ์ ์šฉ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.  ์—ฌ๋Ÿฌ๊ฐœ์˜ ํด๋ž˜์Šค๋ฅผ ์ŠคํŽ˜์ด์Šค๋ฅผ ๊ตฌ๋ถ„์ž๋กœ ์ง€์ •ํ•ด์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ:

์•„๋ž˜ ์˜ˆ์ œ๋Š” ๋ฌธ์„œ๋‚ด์˜ ๋ชจ๋“  em์š”์†Œ์— selected์Šคํƒ€์ผ์„ ์ ์šฉ์‹œํ‚ค๊ณ , id๊ฐ€ myid์ธ ์š”์†Œ์—๋Š” highlight์Šคํƒ€์ผ์„ ์ ์šฉ์‹œํ‚ค๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.
<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">

   $(document).ready(function() {
      $("em").addClass("selected");
      $("#myid").addClass("highlight");
   });

   </script>
   <style>
      .selected { color:red; }
      .highlight { background:yellow; }
  </style>
</head>
<body>
   <em title="Bold and Brave">This is first paragraph.</em>
   <p id="myid">This is second paragraph.</p>
</body>
</html>

 

 

์œ ์šฉํ•œ ์†์„ฑ ๊ด€๋ จ ๋ฉ”์†Œ๋“œ ๋ชฉ๋ก

 

MethodsDescription
attr( properties )Set a key/value object as properties to all matched elements.
attr( key, fn )Set a single property to a computed value, on all matched elements.
removeAttr( name )Remove an attribute from each of the matched elements.
hasClass( class )Returns true if the specified class is present on at least one of the set of matched elements.
removeClass( class )Removes all or the specified class(es) from the set of matched elements.
toggleClass( class )Adds the specified class if it is not present, removes the specified class if it is present.
html( )Get the html contents (innerHTML) of the first matched element.
html( val )Set the html contents of every matched element.
text( )Get the combined text contents of all matched elements.
text( val )Set the text contents of all matched elements.
val( )Get the input value of the first matched element.
val( val )Set the value attribute of every matched element if it is called on <input> but if it is called on <select> with the passed <option> value then passed option would be selected, if it is called on check box or radio box then all the matching check box and radiobox would be checked.

Similar to above syntax and examples, following examples would give you understanding on using various attribute methods in different situation:

  • $("#myID").attr("custom") : This would return value of attribute custom for the first element matching with ID myID.

  • $("img").attr("alt", "Sample Image"): This sets the alt attribute of all the images to a new value "Sample Image".

  • $("input").attr({ value: "", title: "Please enter a value" }); : Sets the value of all <input> elements to the empty string, as well as sets the title to the string Please enter a value.

  • $("a[href^=http://]").attr("target","_blank"): Selects all links with an href attribute starting with http:// and set its target attribute to _blank

  • $("a").removeAttr("target") : This would remove target attribute of all the links.

  • $("form").submit(function() {$(":submit",this).attr("disabled", "disabled");}); : This would modify the disabled attribute to the value "disabled" while clicking Submit button.

  • $("p:last").hasClass("selected"): This return true if last <p> tag has associated classselected.

  • $("p").text(): Returns string that contains the combined text contents of all matched <p> elements.

  • $("p").text("<i>Hello World</i>"): This would set "<I>Hello World</I>" as text content of the matching <p> elements

  • $("p").html() : This returns the HTML content of the all matching paragraphs.

  • $("div").html("Hello World") : This would set the HTML content of all matching <div> to Hello World.

  • $("input:checkbox:checked").val() : Get the first value from a checked checkbox

  • $("input:radio[name=bar]:checked").val(): Get the first value from a set of radio buttons

  • $("button").val("Hello") : Sets the value attribute of every matched element <button>.

  • $("input").val("on") : This would check all the radio or check box button whose value is "on".

  • $("select").val("Orange") : This would select Orange option in a dropdown box with options Orange, Mango and Banana.

  • $("select").val("Orange", "Mango") : This would select Orange and Mango options in a dropdown box with options Orange, Mango and Banana.

 

 

 

 

Reference : http://www.tutorialspoint.com/jquery/jquery-attributes.htm 

 

 

 

 

 

 

 

 

The jQuery library harnesses the power of Cascading Style Sheets (CSS) selectors to let us quickly and easily access elements or groups of elements in the Document Object Model (DOM).

A jQuery Selector is a function which makes use of expressions to find out matching elements from a DOM based on the given criteria.

$() factory function (ํŒฉํ† ๋ฆฌ ํ•จ์ˆ˜):

All type of selectors available in jQuery, always start with the dollar sign and parentheses: $().

The factory function $() makes use of following three building blocks while selecting elements in a given document:

jQueryDescription
Tag Name:Represents a tag name available in the DOM. For example $('p') selects all paragraphs in the document.
Tag ID:Represents a tag available with the given ID in the DOM. For example $('#some-id') selects the single element in the document that has an ID of some-id.
Tag Class:Represents a tag available with the given class in the DOM. For example $('.some-class') selects all elements in the document that have a class of some-class.

All the above items can be used either on their own or in combination with other selectors. All the jQuery selectors are based on the same principle except some tweaking.

NOTE: The factory function $() is a synonym of jQuery() function. So in case you are using any other JavaScript library where $ sign is conflicting with some thing else then you can replace $ sign by jQuery name and you can use function jQuery() instead of $().

Example(์˜ˆ์ œ):

Following is a simple example which makes use of Tag Selector. This would select all the elements with a tag name p.

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   
   <script type="text/javascript" language="javascript">
   $(document).ready(function() {
      var pars = $("p");
      for( i=0; i<pars.length; i++ ){
         alert("Found paragraph: " + pars[i].innerHTML);
      }
   });
   </script>
</head>
<body>
   <div>
      <p class="myclass">This is a paragraph.</p>
      <p id="myid">This is second paragraph.</p>
      <p>This is third paragraph.</p>
   </div>
</body>
</html>

 

 

Selectors ์‚ฌ์šฉ๋ฒ•

๊ธฐ๋ณธ์ ์œผ๋กœ ์…€๋ ‰ํ„ฐ๋Š” ์ด๋ฆ„, ์•„์ด๋””, ํด๋ž˜์Šค๋ช…์œผ๋กœ ์š”์†Œ๋ฅผ ๊ตฌ๋ถ„์„ ์ง€์–ด์„œ ํ•˜๋‚˜ ๋˜๋Š” ์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ์–ป์–ด์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

SelectorDescription
NameSelects all elements which match with the given element Name.
#IDSelects a single element which matches with the given ID
.ClassSelects all elements which match with the given Class.
Universal (*)Selects all elements available in a DOM.
Multiple Elements E, F, GSelects the combined results of all the specified selectors E, F or G.

์‹ค์ œ๋กœ ์œ„ ์…€๋ ‰ํ„ฐ๋“ค์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์— ๋งŽ์ด ๋‚˜์™€์žˆ์Šต๋‹ˆ๋‹ค.

  • $('*'): This selector selects all elements in the document.

  • $("p > *"): This selector selects all elements that are children of a paragraph element.

  • $("#specialID"): This selector function gets the element with id="specialID".

  • $(".specialClass"): This selector gets all the elements that have the class of specialClass.

  • $("li:not(.myclass)"): Selects all elements matched by <li> that do not have class="myclass".

  • $("a#specialID.specialClass"): This selector matches links with an id of specialID and a class of specialClass.

  • $("p a.specialClass"): This selector matches links with a class of specialClass declared within <p> elements.

  • $("ul li:first"): This selector gets only the first <li> element of the <ul>.

  • $("#container p"): Selects all elements matched by <p> that are descendants of an element that has an id of container.

  • $("li > ul"): Selects all elements matched by <ul> that are children of an element matched by <li>

  • $("strong + em"): Selects all elements matched by <em> that immediately follow a sibling element matched by <strong>.

  • $("p ~ ul"): Selects all elements matched by <ul> that follow a sibling element matched by <p>.

  • $("code, em, strong"): Selects all elements matched by <code> or <em> or <strong>.

  • $("p strong, .myclass"): Selects all elements matched by <strong> that are descendants of an element matched by <p> as well as all elements that have a class of myclass.

  • $(":empty"): Selects all elements that have no children.

  • $("p:empty"): Selects all elements matched by <p> that have no children.

  • $("div[p]"): Selects all elements matched by <div> that contain an element matched by <p>.

  • $("p[.myclass]"): Selects all elements matched by <p> that contain an element with a class of myclass.

  • $("a[@rel]"): Selects all elements matched by <a> that have a rel attribute.

  • $("input[@name=myname]"): Selects all elements matched by <input> that have a name value exactly equal to myname.

  • $("input[@name^=myname]"): Selects all elements matched by <input> that have a name value beginning with myname.

  • $("a[@rel$=self]"): Selects all elements matched by <a> that have rel attribute value ending with self

  • $("a[@href*=domain.com]"): Selects all elements matched by <a> that have an href value containing domain.com.

  • $("li:even"): Selects all elements matched by <li> that have an even index value.

  • $("tr:odd"): Selects all elements matched by <tr> that have an odd index value.

  • $("li:first"): Selects the first <li> element.

  • $("li:last"): Selects the last <li> element.

  • $("li:visible"): Selects all elements matched by <li> that are visible.

  • $("li:hidden"): Selects all elements matched by <li> that are hidden.

  • $(":radio"): Selects all radio buttons in the form.

  • $(":checked"): Selects all checked boxex in the form.

  • $(":input"): Selects only form elements (input, select, textarea, button).

  • $(":text"): Selects only text elements (input[type=text]).

  • $("li:eq(2)"): Selects the third <li> element

  • $("li:eq(4)"): Selects the fifth <li> element

  • $("li:lt(2)"): Selects all elements matched by <li> element before the third one; in other words, the first two <li> elements.

  • $("p:lt(3)"): selects all elements matched by <p> elements before the fourth one; in other words the first three <p> elements.

  • $("li:gt(1)"): Selects all elements matched by <li> after the second one.

  • $("p:gt(2)"): Selects all elements matched by <p> after the third one.

  • $("div/p"): Selects all elements matched by <p> that are children of an element matched by <div>.

  • $("div//code"): Selects all elements matched by <code>that are descendants of an element matched by <div>.

  • $("//p//a"): Selects all elements matched by <a> that are descendants of an element matched by <p>

  • $("li:first-child"): Selects all elements matched by <li> that are the first child of their parent.

  • $("li:last-child"): Selects all elements matched by <li> that are the last child of their parent.

  • $(":parent"): Selects all elements that are the parent of another element, including text.

  • $("li:contains(second)"): Selects all elements matched by <li> that contain the text second.

์ง€๊ธˆ๊นŒ์ง€ ๋ณธ ์…€๋ ‰ํ„ฐ๋“ค์€ ์–ด๋– ํ•œ HTML/XML ์š”์†Œ์—๋„ ์ผ๋ฐ˜์ ์œผ๋กœ ์ ์šฉ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด selector $("li:first") ๊ฐ€ <li> ํƒœ๊ทธ์— ์ ์šฉ์ด ๋œ๋‹ค๋ฉด $("p:first") ์—ญ์‹œ <p> ํƒœ๊ทธ์— ์ ์šฉ์ด ๋œ๋‹ค๋Š” ๋ง์ด์ฃ .

 

 

 

 

 

Reference : http://www.tutorialspoint.com/jquery/jquery-selectors.htm

 

 

 

 

AJAX ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์˜ˆ์ œ

์•„๋ž˜ ์˜ˆ์ œ๋Š” AJAX๋ฅผ ์ด์šฉํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์ฝ์–ด์˜จ ์ž๋ฃŒ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

์˜ˆ์ œ

form ํƒœ๊ทธ๊ฐ€ ๋จนํžˆ์ง€ ์•Š๋Š” ๊ด€๊ณ„๋กœ ์˜ˆ์ œ๋Š” ์‹ค์Šตํ•˜๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์„œ W3Schools๋กœ ๊ฐ€์…”์„œ ํ•ด๋ณด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

์‹ค์Šตํ•˜๊ธฐ ยป

์˜ˆ์ œ ์„ค๋ช… - showCustomer() ํ•จ์ˆ˜

์‚ฌ์šฉ์ž๊ฐ€ ๋“œ๋ž๋‹ค์šด ๋ฆฌ์ŠคํŠธ์—์„œ ๊ณ ๊ฐ์„ ์„ ํƒํ•˜๋ฉด, "showCustomer()" ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜์–ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ์ด ํ•จ์ˆ˜๋Š” "onchange" ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ํ˜ธ์ถœ๋˜๋„๋ก ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.

showCustomer ํ•จ์ˆ˜ ์†Œ์Šค ์ฝ”๋“œ

function showCustomer(str) {
  var xhttp; 
  if (str == "") {
    document.getElementById("txtHint").innerHTML = "";
    return;
  }
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
    document.getElementById("txtHint").innerHTML = xhttp.responseText;
    }
  };
  xhttp.open("GET""getcustomer.asp?q="+str, true);
  xhttp.send();
}

showCustomer() ํ•จ์ˆ˜๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ์ž‘์—…์„ ํ•ฉ๋‹ˆ๋‹ค.

  • customer๊ฐ€ ์„ ํƒ์ด ๋˜์—ˆ๋Š”์ง€ ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค.
  • XMLHttpRequest ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
  • ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์‘๋‹ต์„ ๋ฐ›๊ณ ๋‚˜์„œ ์‹คํ–‰๋  ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
  • ์„œ๋ฒ„์— ์žˆ๋Š” ํŒŒ์ผ๋กœ ์š”์ฒญ์„ ๋ณด๋ƒ…๋‹ˆ๋‹ค.
  • ์š”์ฒญ์„ ๋ณด๋‚ผ ๋•Œ ํŒŒ๋ผ๋ฏธํ„ฐ "q" ์™€ ๋“œ๋ž๋‹ค์šด ๋ฆฌ์ŠคํŠธ์—์„œ ์ฝ์–ด์˜จ str์„ URL์— ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

 AJAX Server Page

์œ„ ์˜ˆ์ œ์—์„œ ์‚ฌ์šฉ๋œ ์„œ๋ฒ„ํŽ˜์ด์ง€๋Š” "getcustomer.asp"์ž…๋‹ˆ๋‹ค.


์„œ๋ฒ„ ํŽ˜์ด์ง€ ํŒŒ์ผ์€ PHP, JSP์™€ ๊ฐ™์€ ๋‹ค๋ฅธ ์„œ๋ฒ„ ์–ธ์–ด๋กœ๋„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


PHP๋กœ ๊ตฌํ˜„ํ•œ ๋™์ผํ•œ ๊ธฐ๋Šฅ์˜ ์†Œ์Šค ๋ณด๊ธฐ


 "getcustomer.asp" ๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ •๋ณด๋ฅผ ์กฐํšŒํ•˜๊ณ  ์ฝ์–ด์˜จ ์ •๋ณด๋ฅผ HTML ํ…Œ์ด๋ธ”์— ๋„ฃ๋Š” ๊ธฐ๋Šฅ์„ ํ•ฉ๋‹ˆ๋‹ค.

<%
response.expires=-1
sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
sql=sql & "'" & request.querystring("q") & "'"

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/datafolder/northwind.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
rs.Open sql,conn

response.write("<table>")
do until rs.EOF
  for each x in rs.Fields
    response.write("<tr><td><b>" & x.name & "</b></td>")
    response.write("<td>" & x.value & "</td></tr>")
  next
  rs.MoveNext
loop
response.write("</table>")
%>


์ž, ํฐ ๊ทธ๋ฆผ์ด ๊ทธ๋ ค์ง€๋‚˜์š”?

์ •๋ฆฌ๋ฅผ ํ•œ๋ฒˆ ํ•ด๋“œ๋ฆฌ์ž๋ฉด,

1. ๋“œ๋ž๋‹ค์šด ๋ฆฌ์ŠคํŠธ์—์„œ ํ•ญ๋ชฉ์„ ์„ ํƒํ•œ๋‹ค.
2. ํ•ญ๋ชฉ์ด ์„ ํƒ๋˜๋ฉด onchange ์ด๋ฒคํŠธ์—์˜ํ•ด showCustomer() ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ajax ์š”์ฒญ์ด ์„œ๋ฒ„๋กœ ์ „์†ก๋˜๊ณ 
3. ์„œ๋ฒ„์—์„œ getcustomer.aspํŒŒ์ผ์ด ์‹คํ–‰์ด ๋˜๋Š”๋ฐ ์ด ํŒŒ์ผ์€ DB๋ฅผ ์กฐํšŒํ•ด์„œ ์ฝ์–ด์˜จ ์ •๋ณด๋ฅผ htmlํ˜•ํƒœ์˜ ํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค์–ด์„œ ์‘๋‹ต์œผ๋กœ ๋ณด๋ƒ…๋‹ˆ๋‹ค.
4. ๊ทธ๋Ÿฌ๋ฉด ์ด ์‘๋‹ต์œผ๋กœ ๋ฐ›์€ htmlํ˜•์‹์˜ ์ •๋ณด๋ฅผ ๋“œ๋ž๋‹ค์šด ๋ฆฌ์ŠคํŠธ ์•„๋ž˜์ชฝ์— ๋ฟŒ๋ ค์ค๋‹ˆ๋‹ค.

์ด๋Ÿฐ์‹์œผ๋กœ ajax๋ฅผ ์ด์šฉํ•œ ์š”์ฒญ์ด ์ฒ˜๋ฆฌ๊ฐ€ ๋˜๋Š” ๊ฒ๋‹ˆ๋‹ค.

๋ณ„๋กœ ์–ด๋ ต์ง€ ์•Š์ฃ ? ^-^ 

์—ฌ๊ธฐ์„œ AJAX ํฌ์ŠคํŒ…์€ ๋งˆ์น˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์ฐธ๊ณ ๋กœ AJAXํฌ์ŠคํŒ…์— ์‚ฌ์šฉ๋œ ์ž๋ฃŒ๋Š” W3Schools์— ์žˆ๋Š” ์ž๋ฃŒ๋ฅผ ๋ฒˆ์—ญํ•ด๋†“์€ ์ˆ˜์ค€์ž…๋‹ˆ๋‹ค.

๊ถ๊ธˆํ•œ๊ฒŒ ์žˆ์œผ์‹œ๋ฉด ๋Œ“๊ธ€ ๋‹ฌ์•„์ฃผ์‹œ๋ฉด ๋‹ต๊ธ€ ๋‹ฌ์•„๋“œ๋ฆฌ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.





onreadystatechange ์ด๋ฒคํŠธ

XMLHttpRequest๊ฐ์ฒด๋Š” ์ƒํƒœ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๋ฐ readyState ์†์„ฑ์ด ๊ทธ ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.


๊ทธ๋ฆฌ๊ณ  ์šฐ๋ฆฌ๋Š” ์ด ์ƒํƒœ ์ •๋ณด๋ฅผ ๋ณด๊ณ  ์‘๋‹ต์ด ์™”๋Š”์ง€, ๊ทธ ์‘๋‹ต์ด ์ •์ƒ์ ์œผ๋กœ ์™”๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.


์ด readyState ๊ฐ€ ๋ณ€ํ•  ๋•Œ๋งˆ๋‹ค ํ•ญ์ƒ ๋ฐœ์ƒํ•˜๋Š” ์ด๋ฒคํŠธ๊ฐ€ ์žˆ๋Š”๋ฐ ๊ทธ๊ฒƒ์ด ๋ฐ”๋กœ  onreadystatechange ์ด๋ฒคํŠธ์ž…๋‹ˆ๋‹ค.


XMLHttpRequest ๊ฐ์ฒด์˜ ์ค‘์š”ํ•œ ์„ธ ๊ฐ€์ง€ ์†์„ฑ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์†์„ฑ์„ค๋ช…
onreadystatechange readyState ์†์„ฑ๊ฐ’์ด ๋ณ€ํ•  ๋•Œ๋งˆ๋‹ค ์ž๋™์œผ๋กœ ํ˜ธ์ถœ๋  ํ•จ์ˆ˜ ๋˜๋Š” ํ•จ์ˆ˜๋ช…์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
readyStateXMLHttpRequest ๊ฐ์ฒด์˜ ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , 0 ์—์„œ 4 ์˜ ๊ฐ’์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค. 
0: ์š”์ฒญ์ด ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. 
1: ์„œ๋ฒ„์™€ ์—ฐ๊ฒฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
2: ์š”์ฒญ์ด ๋ฐ›์•„๋“ค์—ฌ์กŒ์Šต๋‹ˆ๋‹ค.
3: ์š”์ฒญ์ด ์ง„ํ–‰์ค‘์ž…๋‹ˆ๋‹ค.
4: ์š”์ฒญ์ด ์™„๋ฃŒ๋˜๊ณ  ์‘๋‹ต์„ ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค.
status200: ์ •์ƒ
404: ํŽ˜์ด์ง€๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.


 onreadystatechange ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๊ณ  readyState๊ฐ€ 4์ด๋ฉฐ status๊ฐ€ 200์ด๋ฉด ์ •์ƒ์ ์œผ๋กœ ์š”์ฒญ์ด ์ฒ˜๋ฆฌ๋˜์–ด ์‘๋‹ต์ด ์˜จ ๊ฒฝ์šฐ์ด๋ฏ€๋กœ ์ด๋•Œ ์›ํ•˜๋Š” ์ž‘์—…์„ ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ

function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
  if (xhttp.readyState == 4 && xhttp.status == 200) {
    document.getElementById("demo").innerHTML = xhttp.responseText;
  }
};
์‹ค์Šตํ•˜๊ธฐ ยป

Note: onreadystatechange ์ด๋ฒคํŠธ๋Š” ํ•œ๋ฒˆ์˜ ์š”์ฒญ์„ ํ•  ๋•Œ ์ด 5๋ฒˆ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค (readyState๊ฐ€ 0์—์„œ 4๊นŒ์ง€ ๋ฐ”๋€Œ๋ฏ€๋กœ).


Callback ํ•จ์ˆ˜ ์‚ฌ์šฉํ•˜๊ธฐ

callback ํ•จ์ˆ˜๋Š” ๋‹ค๋ฅธ ํ•จ์ˆ˜์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜๊ฒจ์ง€๋Š” ํ•จ์ˆ˜๋ฅผ ๋งํ•ฉ๋‹ˆ๋‹ค.

๋งŒ์•ฝ ์›น์‚ฌ์ดํŠธ์— ํ•˜๋‚˜ ์ด์ƒ์˜ AJAX ์ž‘์—…์ด ์žˆ๋‹ค๋ฉด, ๋‹จ ํ•˜๋‚˜์˜ ํ‘œ์ค€ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์„œ XMLHttpRequest ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ฐ๊ฐ์˜ AJAX ์ž‘์—…์ด ์žˆ์„ ๋•Œ๋งˆ๋‹ค ์ด ํ‘œ์ค€ํ•จ์ˆ˜์—์„œ ํ˜ธ์ถœํ•จ์œผ๋กœ์จ ์ฝ”๋“œ๋ฅผ ๋‹จ์ˆœํ™” ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ‘œ์ค€ํ•จ์ˆ˜๋Š” ๊ฐ๊ฐ์˜ AJAX์ž‘์—…์„ ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜๊ฒจ๋ฐ›์•„์„œ ์ด๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ

function loadDoc(cFunc) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
  if (xhttp.readyState == 4 && xhttp.status == 200) {
    cFunc(xhttp);
  }
์‹ค์Šตํ•˜๊ธฐ ยป

 

 

์„œ๋ฒ„ ์‘๋‹ต

์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์‘๋‹ต์„ ๋ฐ›๊ธฐ ์œ„ํ•ด์„œ๋Š” XMLHttpRequest๊ฐ์ฒด์˜ responseText ๋˜๋Š” responseXML ์†์„ฑ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์†์„ฑ์„ค๋ช…
responseText์‘๋‹ต ๋ฐ์ดํ„ฐ๋ฅผ string์œผ๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค.
responseXML์‘๋‹ต ๋ฐ์ดํ„ฐ๋ฅผ XML ๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค.


responseText ์†์„ฑ

์˜ˆ์ œ

document.getElementById("demo").innerHTML = xhttp.responseText;
์‹ค์Šตํ•˜๊ธฐ ยป

responseXML ์†์„ฑ

์˜ˆ์ œ

 cd_catalog.xml ํŒŒ์ผ์„ ์š”์ฒญํ•˜๊ณ  ์‘๋‹ต์œผ๋กœ ์˜จ ๋ฐ์ดํ„ฐ ํŒŒ์‹ฑํ•˜๊ธฐ

xmlDoc = xhttp.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName("ARTIST");
for (i = 0; i < x.length; i++) {
  txt += x[i].childNodes[0].nodeValue + "<br>";
  }
document.getElementById("demo").innerHTML = txt;
์‹ค์Šตํ•˜๊ธฐ ยป


์‘๋‹ต์„ ๋ฐ›๋Š”๊ฑฐ๋Š” ํ–ˆ๋Š”๋ฐ ๊ทธ๋ ‡๋‹ค๋ฉด ์‘๋‹ต์ด ์™”๋Š”์ง€๋Š” ์–ด๋–ป๊ฒŒ ์•Œ ์ˆ˜ ์žˆ๋‚˜์š”? 

์ž, ๊ทธ ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋Š” ๋‹ค์Œ ํฌ์ŠคํŒ…์— ์žˆ์„ ์ด๋ฒคํŠธ์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€๋ฅผ ํ•˜๊ณ ๋‚˜๋ฉด ์•„์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž, ๋‹ค์Œ ์‹œ๊ฐ„์—๋Š” AJAX์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์ด๋ฒคํŠธ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.





์„œ๋ฒ„๋กœ ์š”์ฒญํ•˜๊ธฐ


- ์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ํ•  ๋•Œ์—๋Š” XMLHttpRequest๊ฐ์ฒด์—์„œ ์ œ๊ณตํ•˜๋Š” open(), send() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.


์˜ˆ๋ฅผ๋“ค์–ด, ์•„๋ž˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.


var xhttp = new XMLHttpRequest();

xhttp.open("GET", "URL", true);

xhttp.send();


์ด๋Ÿฐ ์‹์œผ๋กœ ๋ง์ด์ฃ .


์ด๋•Œ open()๊ณผ send()์˜ ๋ฉ”์†Œ๋“œ ์„ค๋ช…์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋ฉ”์†Œ๋“œ์„ค๋ช…
open(method, url, async)์š”์ฒญ ํƒ€์ž…์„ ์ •ํ•ฉ๋‹ˆ๋‹ค.

method: ์š”์ฒญ ํƒ€์ž…: GET ๋˜๋Š” POST
url: ์„œ๋ฒ„ (ํŒŒ์ผ) ์œ„์น˜
async: true (๋น„๋™๊ธฐ์‹) ๋˜๋Š” false (๋™๊ธฐ์‹)
send()์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ๋ณด๋‚ธ๋‹ค (GET๋ฐฉ์‹์—์„œ ์‚ฌ์šฉ)
send(string)์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ๋ณด๋‚ธ๋‹ค (POST๋ฐฉ์‹์—์„œ ์‚ฌ์šฉ)


GET ๋ฐฉ์‹๊ณผ POST๋ฐฉ์‹


GET ์€ POST๋ณด๋‹ค ๋‹จ์ˆœํ•˜๊ณ  ๋น ๋ฅด๋ฉฐ ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์•„๋ž˜ ๊ฒฝ์šฐ์—๋Š” ๊ผญ POST๋ฐฉ์‹์œผ๋กœ ์จ์•ผํ•ฉ๋‹ˆ๋‹ค:

  • A cached file is not an option (์„œ๋ฒ„์— ์žˆ๋Š” ํŒŒ์ผ์ด๋‚˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ฒฝ์šฐ).
  • ์„œ๋ฒ„๋กœ ๋งŽ์€ ์–‘์˜ ๋ฐ์ดํ„ฐ ์ „์†ก์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ (GET๋ฐฉ์‹์€ ์ „์†กํ•  ๋ฐ์ดํ„ฐ ์‚ฌ์ด์ฆˆ ์ œํ•œ์ด ์žˆ์œผ๋‚˜ POST ๋ฐฉ์‹์€ ์‚ฌ์ด์ฆˆ ์ œํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค).
  • (unknown characters๋ฅผ ํฌํ•จํ•  ์ˆ˜ ์žˆ๋Š”) ์‚ฌ์šฉ์ž input์„ ์„œ๋ฒ„๋กœ ์ „์†กํ•  ๋•Œ , POST ๋ฐฉ์‹์ด ๋ณด์•ˆ์ƒ GET๋ฐฉ์‹๋ณด๋‹ค ์ข‹์Šต๋‹ˆ๋‹ค.

GET Requests

๊ฐ„๋‹จํ•œ GET ์š”์ฒญ:

์˜ˆ์ œ1

xhttp.open("GET""demo_get.asp"true);
xhttp.send();
์‹ค์Šตํ•˜๊ธฐ ยป

์œ„ ์˜ˆ์ œ์—์„œ๋Š” ์ด๋ฏธ ์บ์‰ฌ๋œ ๊ฒฐ๊ณผ๋ฅผ ๋ณผ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๊ฒฝ์šฐ๋ฅผ ํ”ผํ•˜๋ ค๋ฉด, ์œ ๋‹ˆํฌ ID๋ฅผ URL์— ๋„ฃ์–ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ2

xhttp.open("GET""demo_get.asp?t=" + Math.random(), true);
xhttp.send();
์‹ค์Šตํ•˜๊ธฐ ยป

GET ๋ฐฉ์‹์œผ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๊ณ  ์‹ถ์œผ์‹œ๋ฉด, ์ •๋ณด๋ฅผ URL์— ์ž…๋ ฅํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ3

xhttp.open("GET""demo_get2.asp?fname=Henry&lname=Ford"true);
xhttp.send();
์‹ค์Šตํ•˜๊ธฐ ยป

POST Requests

๊ฐ„๋‹จํ•œ POST ์š”์ฒญ:

์˜ˆ์ œ1

xhttp.open("POST""demo_post.asp"true);
xhttp.send();
์‹ค์Šตํ•˜๊ธฐ ยป

HTML ํ˜•์‹์œผ๋กœ POST ์š”์ฒญ์„ ํ•˜๋ ค๋ฉด, setRequestHeader()๋ฅผ ์ด์šฉํ•˜์—ฌ HTTP ํ—ค๋” ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  send() ๋ฉ”์†Œ๋“œ์— ๋ณด๋‚ด๋ ค๋Š” ๋ฐ์ดํ„ฐ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ2

xhttp.open("POST""ajax_test.asp"true);
xhttp.setRequestHeader("Content-type""application/x-www-form-urlencoded");
xhttp.send("fname=Henry&lname=Ford");
์‹ค์Šตํ•˜๊ธฐ ยป

The url - ์„œ๋ฒ„ ์ƒ์˜ ํŒŒ์ผ ์ฃผ์†Œ

open() ๋ฉ”์†Œ๋“œ์˜ url ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” ์„œ๋ฒ„์— ์œ„์น˜ํ•œ ํŒŒ์ผ์˜ ์ฃผ์†Œ์ž…๋‹ˆ๋‹ค.

xhttp.open("GET""ajax_test.asp"true);

์—ฌ๊ธฐ์„œ ๋งํ•˜๋Š” ํŒŒ์ผ์€ .txt, .xml ํŒŒ์ผ์ฒ˜๋Ÿผ ํ‰๋ฒ”ํ•œ ํŒŒ์ผ๋“ค, ๋˜๋Š” .asp, .php ์™€ ๊ฐ™์€ ์„œ๋ฒ„์Šคํฌ๋ฆฝํŒ… ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.  (์„œ๋ฒ„์Šคํฌ๋ฆฝํŒ… ํŒŒ์ผ๋“ค์€ ์„œ๋ฒ„์—์„œ ์‘๋‹ต์„ ๋ณด๋‚ด๊ธฐ ์ „์— ํŠน์ • ์ผ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.).


๋น„๋™๊ธฐ์‹ - True or False?

ajax๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด 3๋ฒˆ์งธ ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” ๋ฌด์กฐ๊ฑด true์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

xhttp.open("GET""ajax_test.asp"true);

Async=true

์˜ˆ์ œ

xhttp.onreadystatechange = function() {
  if (xhttp.readyState == 4 && xhttp.status == 200) {
    document.getElementById("demo").innerHTML = xhttp.responseText;
  }
};
xhttp.open("GET""ajax_info.txt"true);
xhttp.send();
์‹ค์Šตํ•˜๊ธฐ ยป



Async=false

xhttp.open("GET""ajax_info.txt"false);

async=false ๋กœ ์‚ฌ์šฉํ•˜๊ฒŒ๋˜๋ฉด ๋”์ด์ƒ AJAX๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ์•„๋‹Œ๊ฒŒ ๋˜์–ด๋ฒ„๋ฆฝ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ํ•˜๊ฒŒ๋˜๋ฉด ์„œ๋ฒ„์—์„œ ์‘๋‹ต์ด ์˜ค๊ธฐ ์ „๊นŒ์ง€ ํ™”๋ฉด์—์„œ ์•„๋ฌด๊ฒƒ๋„ ํ•  ์ˆ˜ ์—†๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ

xhttp.open("GET""ajax_info.txt"false);
xhttp.send();
document.getElementById("demo").innerHTML = xhttp.responseText;
์‹ค์Šตํ•˜๊ธฐ ยป



์ž, ์ง€๊ธˆ๊นŒ์ง€ AJAX๋ฅผ ์ด์šฉํ•œ ์„œ๋ฒ„๋กœ ์š”์ฒญ ๋ณด๋‚ด๊ธฐ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ํฌ์ŠคํŒ…์—์„œ๋Š” ์‘๋‹ต์„ ๋ฐ›๋Š” ๊ฒƒ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.