프로젝트4 - div 섹션 구역 분리 와 CSS 스타일 적용하기

이미지
웹 브라우저에 표시되는 글자와 이미지 들에 디자인 적인 효과( 배경색, 글자색, 크기 조절...) 및 브라우저 내에서의 배치등을 조절하기 위해서는 구역을 나누면 편리해진다. 바로 구역(섹션) 을 나누어 주는 역할을 하는 태그가 div 이다. <div>태그는 브라우저에서 보여지는 시각적 기능은 없다. 단지, 구역을 나누는 역할을 한다.  코드를 만들어 본다. <!DOCTYPE html> <html> <head>   <title>div</title> </head> <body>   <div>     <p>Ice cream is a frozen dessert typically made from milk or cream that has been flavoured with a sweetener,        either sugar or an alternative, and a spice,        such as cocoa or vanilla, or with fruit, such as strawberries or peaches.</p>   </div>   <div>     <p> Food colouring is sometimes added in addition to stabilizers.        mixture is cooled below the freezing point of water and stirred to incorporate air spaces and prevent detectable ice crystals from forming.        It can also be made by whisking a flavoured cream base and liquid nitrogen together.        The result is a smooth, semi-solid foam that is solid at v

CSS속성 선택자 사용법

CSS속성 선택자 는 HTML 속성을 선택할 수 있는 선택자 타입이다.

 syntax

[ 속성 = "속성값"] {

스타일

}

[] 사이에 속성 혹은 속성="속성값" 을 주면, 해당 속성을 가진 HTML요소들에
스타일을 정교하게 설정할 수 있다.
<!DOCTYPE html>
<html>
<head>
<style>
[target] {
  background-color: yellow;
}
</style>
</head>
<body>

<h2>CSS [attribute] Selector</h2>
<p>The links with a target attribute gets a yellow background:</p>

<a href="https://www.w3schools.com">w3schools.com</a>
<a href="http://www.disney.com" target="_blank">disney.com</a>
<a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>

</body>
</html>

위 소스에서는 
target 이라는 속성을 가진 요소만 선택하기 위해서 속성 선택자를 선언했다.
결과는 예상했던것 처럼, target 속성이 설정된 두개의 하이퍼링크 텍스트에만 스타일이 적용된다.

target 속성에만 설정된 스타일



[] 앞에 태그 혹은 클래스, 아이디 를 같이 사용할 수도 있다.
위 코드는 하기와 같이 응용이 가능하다.
<head>
<style>
/* a태그에 target 속성을 가진 요소를 선택 */
a[target] {
  background-color: yellow;
}
/* id 속성값이 text이고 title속성을 가진 요소를 선택 */
#text[title] {
  background-color: red;
}
/* class 속성값이 text2이고 name속성을 가진 요소를 선택 */
.text2[name] {
  background-color: blue;
}
</style>
</head>
<body>

<h2>CSS [attribute] Selector</h2>
<p>The links with a target attribute gets a yellow background:</p>

<a href="https://www.w3schools.com">w3schools.com</a>
<a href="http://www.disney.com" target="_blank">disney.com</a>
<a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>

<h1 id="text" title="h1">h1 text</h1>
<h2 class="text2" name="h2">h2 text</h2>
</body>


댓글

이 블로그의 인기 게시물

구글 블로그 이미지 복사 붙여넣기 가능한가요?

HTML 페이지 기본 구성.(HTML Page Structure)

구글 블로그 대표이미지 설정하기