#1. 가상 클래스 선택자(pseudo class selector)

: class 선택자처럼 여러 대상에 속성을 지정할 수 있지만, class 선택자는 아닌 것을 의미

=> id나 class 또는 태그 지정:pseudo class selector {디자인 속성 지정}

ex) #fancy:hover{background-color:blue}

: id가 fancy인 요소에 마우스가 올려져 있을 때(=hover)->가상클래스선택자 해당 서식을 적용한다는 의미

 

가상 클래스 선택자에도 여러 종류가 있는데, 그 중 간단하게 몇 가지만 알아보았다.

1) active

: 해당 요소를 클릭하고 있을 때를 의미.

2) visited

: 주로 <a> 태그와 함께 사용. 이미 클릭한 링크에 적용됨

3) link

: visited 와 반대 경우에 사용. 클릭하지 않은 <a> 링크에 적용됨

4) hover

: 해당 부분에 마우스 커서를 올리고 있을 때 디자인 서식이 적용됨

 

+) 그 외, 지난 시간에 배운 부분도 pseudo class selector로 사용될 수 있음

ex) p i:first-child   => <p> 태그 안의 <i> 태그 중 first-child 인 요소에만 디자인 적용

 

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>beta file</title>
    <style>
      #one:hover {background-color:IndianRed}
      #two:hover{background-color:lightSalmon}
      #three:hover{background-color:gold}
      #four:hover{background-color:greenyellow}
      #five:hover{background-color:lightskyblue }
      
      a.stylish:visited{color:green}
      strong.stylish:hover{background-color:lavender}
      a.ping:active{background-color:lightsteelblue ; color:black}
    </style>
  </head>
  <body>
      <p>his article is about the mathematical study of optimizing agents. For the mathematical study of sequential games, see <strong class="stylish">Combinatorial game theory</strong>. For the study of playing games for entertainment, see Game studies. For the YouTube series, see <strong>MatPat</strong>. For other uses, see <strong class="stylish">Game theory</strong> (disambiguation).</p>
      <a href="naver.com"Complex systems organizational map.jpg></a>
      <a href="daum.com"Complex systems></a>
    <ol>
    <li id="one">  Topics </li>
    <li id="two">  Self-organization </li>
    <li id="three">  Collective behaviour </li>
    <li id="four">  Networks </li>
    <li id="five">  Evolution and adaptation </li>
    <li class="stylish">  Pattern formation </li>
    <li class="stylish">  Systems theory </li>
    <li class="stylish">  Nonlinear dynamics </li>
    <li class="stylish">  Game theory </li>
  </ol>

    <h3>Reference Sites</h3><ul>
    <li><a href="https://opentutorials.org/course/1" class="stylish">  Part of a series on </li></a>
    <li><a href="https://youtube.com" class="stylish">  Economics </li></a>
    <li><a href="https://naver.com" class="ping">  IndexOutlineCategory </li></a>
    <li><a href="https://daum.net" class="ping">  HistoryBranchesClassification </li></a>
    <li><a href="https://portal.korea.ac.kr" class="ping">  ConceptsTheoryTechniques </li></a>
    <li><a href="https://blog.naver.com" class="ping">  By application </li></a>
    <li><a href="https://webtoon.naver.com" class="ping">  Notable economists </li></a>
    <li><a href="https://mail.naver.com" class="ping">  Lists </li></a>
    <li><a href="https://google.co.kr" class="ping">  Glossary </li></a>
    <li><a href="https://en.wikipedia.org/wiki/Game_theory" class="stylish">  Emblem-money.svg Business portal </li></a>
    <li><a href="https://tistory.com" class="stylish">  Bills and coins.svg Money portal </li></a></ul>

<br><br>
    <article> <p>Game theory is the study of mathematical models of strategic interaction among rational decision-makers.[1] It has applications in all fields of social science, as well as in logic, systems science and computer science. Originally, it addressed zero-sum games, in which each participant's gains or losses are exactly balanced by those of the other participants. In the 21st century, game theory applies to a wide range of behavioral relations, and is now an umbrella term for the science of logical decision making in humans, animals, and computers.</p>
      <p>Modern game theory began with the idea of mixed-strategy equilibria in two-person zero-sum games and its proof by John von Neumann. Von Neumann's original proof used the Brouwer fixed-point theorem on continuous mappings into compact convex sets, which became a standard method in game theory and mathematical economics. His paper was followed by the 1944 book Theory of Games and Economic Behavior, co-written with Oskar Morgenstern, which considered cooperative games of several players. The second edition of this book provided an axiomatic theory of expected utility, which allowed mathematical statisticians and economists to treat decision-making under uncertainty.</p>
      <p>Game theory was developed extensively in the 1950s by many scholars. It was explicitly applied to evolution in the 1970s, although similar developments go back at least as far as the 1930s. Game theory has been widely recognized as an important tool in many fields. As of 2014, with the Nobel Memorial Prize in Economic Sciences going to game theorist Jean Tirole, eleven game theorists have won the economics Nobel Prize. John Maynard Smith was awarded the Crafoord Prize for his application of evolutionary game theory.</p></article>
  </body>
</html>

 

Q. #one, #two, ... 이렇게 id를 지정하는데 번거로운 부분이 있었다. id 선택자도 <ol> 태그처럼 순서대로 지정할 수 있는 방법이 있을까?

 

#1-2. 속성을 공부하는 방법

: 속성(property)을 많이 사용하는 순서대로 통계를 보면, 많이 사용되는 속성은 크게 타이포그래피, 색상, 박스 타입 으로 정리된다. 많이 사용되는 것 위주로 공부해 보자.

 

#2. 타이포그래피

: 웹페이지에 쓰이는 글씨에 대한 디자인 서식을 의미

 

1. font-size

여러 단위가 있다(px, em, rem). 지금은 rem 을 권장한다. 이유는?

1) px : 글자 크기 고정. 브라우저의 설정을 변경해도 글씨 크기가 고정됨

2) rem : 글자 크기 가변적. 브라우저의 설정을 변경하면 그에 따라 크기가 변함

ex) rem 은 웹페이지의 [검사(inspect)]를 눌렀을 때 <html>의 폰트 크기와 비례해서 크기가 변한다. 그러나 px는 이에 상관없이 고정된다.

<html>
  <head>
    <meta charset="utf-8">
    <title>beta file</title>
    <style>
      .px{
        font-size:32px ; color:limegreen
      }
      .rem{
        font-size:2rem ; color:orchid
      }
    </style>
  </head>
  <body>
    <article> <p><div class="px">Game theory is the study of mathematical models of strategic interaction among rational decision-makers.[1]</div> <br><div class="px">It has applications in all fields of social science, as well as in logic, systems science and computer science.</div><br> <div class="rem">Originally, it addressed zero-sum games, in which each participant's gains or losses are exactly balanced by those of the other participants.</div><br><div class="rem"> In the 21st century, game theory applies to a wide range of behavioral relations, and is now an umbrella term for the science of logical decision making in humans, animals, and computers.</div></p>
      <p>Modern game theory began with the idea of mixed-strategy equilibria in two-person zero-sum games and its proof by John von Neumann. Von Neumann's original proof used the Brouwer fixed-point theorem on continuous mappings into compact convex sets, which became a standard method in game theory and mathematical economics. His paper was followed by the 1944 book Theory of Games and Economic Behavior, co-written with Oskar Morgenstern, which considered cooperative games of several players. The second edition of this book provided an axiomatic theory of expected utility, which allowed mathematical statisticians and economists to treat decision-making under uncertainty.</p>
      <p>Game theory was developed extensively in the 1950s by many scholars. It was explicitly applied to evolution in the 1970s, although similar developments go back at least as far as the 1930s. Game theory has been widely recognized as an important tool in many fields. As of 2014, with the Nobel Memorial Prize in Economic Sciences going to game theorist Jean Tirole, eleven game theorists have won the economics Nobel Prize. John Maynard Smith was awarded the Crafoord Prize for his application of evolutionary game theory.</p></article>
  </body>
</html>

2. font-color

색깔을 지정하는 방법은 세 가지가 있다.

1) 색깔 이름으로 지정

ex) #ping { color : lightgray }

2) HEX 값으로 지정

ex) h1 { color : #ffffff }

3) RGB 값으로 지정

ex) .dobby { color : rgb(60,60,60) }

 

+) 색깔을 투명하게 지정할 수 있다.

(opacity 라고 표현하기도 함. 0~1의 값. 0 : 투명 <-> 1 : 불투명)

1) 색깔 이름으로 지정  -> 없음(이미 같은 색깔의 다양한 투명도 버전인 색깔들이 많아서 그런 듯)

2) HEX 값으로 지정  -> #RRAAGGBB 형태의 값. (A: alpha(투명도), R : red, G : green, B : blue) 투명도 없는 색상은 AA를 제외한 6자리를 입력하지만, 투명도를 추가하려면 앞에 두 글자를 추가해주면 된다.

ex) #highlight { color : #ff4D6347 }   => 4D 가 투명도를 의미, ff6347 은 색깔을 의미. 

(-> gist.github.com/lopspower/03fb1cc0ac9f32ef38f4 각 투명도에 따라 어떤 글자를 추가하면 되는지 알려줌)

3) RGB 값일 때 지정

ex) .dobby { color : rgb(50,60,30,0.5) }  => 50% 투명한 색깔이 나타남

 

3. text-align

텍스트를 어떻게 정렬할지를 지정. 총 4가지 방법이 있다.

1) 왼쪽 정렬  : text-align:left

2) 가운데 정렬  : text-align:center

3) 오른쪽 정렬  : text-align:right

4) 좌우 간격 동일하게 정렬  : text-align:justify (border 보이게 하면 좌측 우측의 공백이 동일하게 나옴)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Lorem Ipsum</title>
    <style>
      h2 { color:limegreen ; font-size : 2rem ; text-align:center }
      #left{text-align:left ; border:1px solid lightgreen}
      #center{text-align:center ; background-color:lavenderblush}
      #right{text-align:right ; color:blue}
    </style>
  </head>
  <body>
      <h2>Consierei</h2>
      <p id="left">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur malesuada id nulla vitae consectetur. Quisque pharetra massa vitae enim lobortis, in finibus nibh finibus. Nam laoreet id est quis scelerisque. Etiam fringilla ullamcorper lectus eu scelerisque. In rhoncus convallis posuere. Curabitur sagittis accumsan tellus et interdum. Praesent molestie eros elit, nec rutrum dolor pharetra non. Nulla purus lacus, ultrices sit amet venenatis non, tempor vel enim. Ut fringilla elementum orci, quis auctor tellus ultrices ut. Praesent ut dui sodales, feugiat leo hendrerit, lobortis elit. Donec erat neque, maximus non hendrerit sit amet, scelerisque sagittis arcu. Maecenas sodales in arcu sed lacinia. Maecenas molestie dui ut elit sodales, nec lobortis justo tristique. Nullam pulvinar sapien vitae magna pretium, nec consectetur odio hendrerit.</p>

      <p id="center">Suspendisse vitae nibh pretium, dictum odio vel, laoreet neque. In hac habitasse platea dictumst. Aliquam rhoncus turpis arcu, sed rhoncus eros posuere vel. Integer fermentum vel augue quis auctor. Nunc tellus ante, posuere sodales dignissim vel, bibendum vel libero. Pellentesque imperdiet pellentesque congue. Vivamus ac euismod velit, sodales fringilla risus. Curabitur nunc odio, finibus non dapibus aliquam, molestie et ligula.</p>

      <p id="right">Phasellus eget nulla tellus. Integer eget justo vitae nibh tempor porttitor. Morbi viverra lorem in tellus aliquet, vitae scelerisque tellus luctus. Praesent orci tortor, vestibulum id molestie at, blandit eu nisi. Fusce aliquam orci tellus, in congue sem tempor vitae. Vivamus eget tortor venenatis, venenatis eros nec, dignissim sem. Vestibulum porta tellus orci, sed pharetra ipsum placerat a. Curabitur in justo ex. Nunc commodo, ante quis mattis fermentum, nibh ante dictum orci, at pulvinar eros orci ac massa.</p>

      <p>In ullamcorper lectus in nunc eleifend, vitae laoreet neque dapibus. Sed non leo ut est dapibus tincidunt. Nam vel metus aliquam metus posuere vestibulum et eget ex. Ut tincidunt vulputate risus, id posuere massa faucibus non. Aenean mollis urna non urna volutpat, ut lobortis risus posuere. Sed elementum porta sapien, non pharetra arcu porta sit amet. Sed ultricies nisl accumsan sapien ornare auctor. Nulla commodo tincidunt urna.</p>

      <p>Praesent nec accumsan urna, a cursus urna. Fusce orci felis, maximus ac urna a, vulputate volutpat nulla. Nulla aliquam sem id nisi molestie, vel maximus leo viverra. Mauris id convallis odio, ultrices molestie sem. Aenean sit amet ultricies felis. Vivamus et pharetra turpis, in efficitur metus. Mauris elit diam, mollis ut iaculis sed, lobortis non orci. Vestibulum tempus cursus egestas. Nunc pretium molestie ex. Praesent justo mauris, pharetra sit amet ipsum rhoncus, molestie tempus arcu.</p>
  </body>
</html>

 

+) 웹 프로그래밍 경우, 연습용 텍스트가 많이 필요한 경우가 종종 있다.

이럴 때 사용하면 좋은 사이트: www.lipsum.com/

 

Lorem Ipsum - All the facts - Lipsum generator

What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type spec

www.lipsum.com

의미 없는 텍스트를 대량으로 만들어주는 사이트라 유용하다.

'front-side > CSS' 카테고리의 다른 글

6. 레이아웃 추가(심화)내용  (0) 2021.04.05
5. brackets ~ 레이아웃 기초 내용  (0) 2021.04.02
4. 타이포그래피-font ~ 조화  (0) 2021.04.01
2. 선택자  (0) 2021.03.29
CSS Tutorial:  (1) 2021.03.24

#1. 선택자 공부 팁

선택자의 종류도 많고, 포함관계 등을 따지면 더 복잡하다. 

#1-1. 선택자 공부/연습할 수 있는 사이트 : https://flukeout.github.io

 

CSS Diner

A fun game to help you learn and practice CSS selectors.

flukeout.github.io

: 테이블 안의 음식 중 특정한 것을 고르는 게임? 퀘스트?인데, 그 과정에서 CSS 선택자의 종류와 여러 관계를 학습할 수 있다.

 

 

1. Sibling Selector

1) Adjacent Sibling Selector

A + B

: A와 B가 동일한 level이고(<ul>과 <ol>처럼) A 태그 바로 다음에 B 태그가 언급될 때, B는 A의 adjacent sibling selector이다.

-A 바로 다음에 B가 올 때만 해당

-A 바로 다음에 오는 선택자 하나만 해당

 

2) General Sibling Selector

A ~ B

: A와 B가 동일한 level이고 A 태그 다음에 B 태그가 언급될 때, B는 A의 general sibling selector이다.

-A 바로 다음이 아니어도 A 뒤에 있는 선택자면 모두 해당

-선택자 여러 개 해당

 

 

2. Parent-Child

1-1) Descendant Selector

A  B

: A 선택자 안에 포함된 모든 B 선택자를 선택

-A 선택자 바로 안에 포함된 선택자(direct child)가 아니어도 적용됨

 

1-2) Child Selector

A>B

: A 선택자 바로 안에 포함된 B선택자만 선택

-B 선택자가 A 선택자의 direct child 일 때만 적용됨

 

2) First Child Pseudo Selector

(first-child : 부모 선택자에서 첫 번째로 작성된 자식 선택자를 의미)

:first-child  : 모든 부모 선택자에서 first-child element 선택

A:first-child  : A라는 선택자 안에 포함된 first-child element 선택

A  B:first-child  : A 선택자 안에 포함된 B 선택자 안에 포함된 first-child element 선택

+) A>B:first-child  : A 선택자의 direct child인 B 선택자 안에 포함된 first-child element 선택

 

3) Only Child Pseudo Selector

(only-child : 부모 선택자가 단 하나의 자식 선택자를 가질 때 그 자식을 only child라고 함)

:only-child : 모든 부모 선택자에서 only-child element 선택

A:only-child : A라는 선택자 안에 포함된 only-child element 선택

A  B:only-child : A 선택자 안에 포함된 B 선택자 안에 포함된 only-child element 선택

+) A>B:only-child : A 선택자의 direct child인 B 선택자 안에 포함된 only-child element 선택

 

4) Last Child Pseudo Selector

(last-child : 부모 선택자에서 마지막으로 작성된 자식 선택자를 의미)
:last-child : 모든 부모 선택자에서 last-child element 선택

A:last-child : A라는 선택자 안에 포함된 last-child element 선택

A  B:last-child : A 선택자 안에 포함된 B 선택자 안에 포함된 last-child element 선택

+) A>B:last-child  : A 선택자의 direct child인 B 선택자 안에 포함된 last-child element 선택

 

* first-child , only-child , last-child 는 서로 배타적인 관계가 아니다!

= first-child 이면서 only-child 이면서 last-child 일 수도 있다.

ex) 부모 선택자가 하나의 자식 선택자만 가질 때.

 

+ 선택자가 너무 복잡해서 first-child , only-child , last-child 만으로 표현할 수 없을 때 사용하는 선택자:

5) Nth Child Pseudo-Selector

(nth-child : 부모 선택자에서 n번째로 작성된 자식 선택자를 의미)

:nth-child(a)  : 모든 부모 선택자를 대상으로 a번째 자식 선택자를 선택

A:nth-child(a)  : A라는 부모 선택자를 대상으로 a번째 자식 선택자를 선택

+) A  B 나 A>B 등의 부모-자식 관계를 앞에 적용하는 것도 물론 가능

- 앞에서부터 세는 방식

 

6) Nth Last Child Selector

(nth-last-child : 부모 선택자에서 뒤에서부터 셌을 때 n번째에 있는 자식선택자를 의미)
:nth-last-child(a)  : 모든 부모 선택자를 대상으로 끝에서 a번째 있는 자식 선택자를 의미

+) A  B 나 A>B 등의 부모-자식 관계를 앞에 적용하는 것도 물론 가능

- 뒤에서부터 세는 방식

 

 

3. Type

type : 어떤 태그나 선택자의 종류를 지정할 때 사용

* Type 역시 first, only, last, nth 등으로 종류를 지정한다.

 

1) First of Type Selector

:first-of-type  : 선택자의 종류 상관없이, 같은 선택자 중에서 첫 번째로 제시된 선택자를 의미

A:first-of-type  : A라는 선택자 중에서 첫 번째로 제시된 선택자를 의미

+ 부모-자식관계 적용 가능

 

2) Only of Type Selector

:only-of-type : 같은 선택자인 요소가 없는 경우. 자신만이 해당 선택자일 경우 그 element를 의미

A:only-of-type : A라는 선택자 종류인 유일한 element를 의미

+ 부모-자식관계 적용 가능

 

3) Last of Type Selector

:last-of-type : 선택자의 종류 상관없이, 같은 선택자 중에서 마지막으로 제시된 선택자를 의미

A:last-of-type : A라는 선택자 중에서 마지막으로 제시된 선택자를 의미

+ 부모-자식관계 적용 가능

 

4) Nth of Type Selector

:nth-of-type(a) : 선택자의 종류 상관없이, 같은 선택자 중에서 a번째로 제시된 선택자를 의미

A:nth-of-type(a) : A라는 선택자 중에서 a번째로 제시된 선택자를 의미

A:nth-of-type(odd) : A라는 선택자 중에서 홀수 번째로 제시된 선택자를 의미

+ 부모-자식관계 적용 가능

 

4-1) Nth of Type Selector with Formula

A:nth-of-type(an+b) : A라는 선택자 중에서 b번째부터 시작해서, 매 a번째 element를 의미

ex) li:nth-of-type(3n+2) : <li> 태그 선택자 중에서 2번째부터 시작해서, 매 3번째 element를 의미

(= 2,5,8,11, ... 번째의 li 태그 선택자를 의미)

* nth type selector로도 지칭할 수 없는 선택자가 있을 때 사용하는 것 같다.

 

#1-2. CSS cheat sheet : CSS 공부 중 모르는 점을 찾아볼 수 있는 정리표 개념

구글 이미지검색에 'CSS cheat sheet selector' 라고 검색하면 잘 정리된 표를 찾아볼 수 있다.

 

 

'front-side > CSS' 카테고리의 다른 글

6. 레이아웃 추가(심화)내용  (0) 2021.04.05
5. brackets ~ 레이아웃 기초 내용  (0) 2021.04.02
4. 타이포그래피-font ~ 조화  (0) 2021.04.01
3. 선택자 fin ~ 타이포그래피  (0) 2021.03.30
CSS Tutorial:  (1) 2021.03.24

0. CSS 소개

HTML과 CSS의 관계에 대해 배우던 중 이런 글을 보았다:

 

  • Inline - by using the style attribute inside HTML elements
  • Internal - by using a <style> element in the <head> section
  • External - by using a <link> element to link to an external CSS file

CSS가 HTML 문서에 적용될 수 있는 3가지 방법에 대한 글이다.

1) Inline 방법은 개별 HTML 요소에 style '속성'을 지정하는 방법,

2) Internal 방법은 <style> 태그를 사용하는 방법으로, {}을 사용해서 <p>, <h1> 등 '태그'별로 스타일을 할당할 수 있다.

3) External 방법은 <link> 태그로 외부 파일을 끌어오는 방법인데, CSS 언어를 알아야만 사용가능한 방법이다.

: 실제로 화려한 웹사이트를 보면 대부분 이 방법을 사용해서 적용할 수 없었던 게 아쉬웠다. 이번에 CSS를 배우면서 적용해 보려고 한다!

 

* ctrl + O 키를 누르면 사용중인 브라우저에서 내 컴퓨터의 파일을 불러올 수 있다.

 

1. HTML과 CSS를 연결하는 방법 : style

style : HTML의 태그/속성이고 이제부터 CSS 문법이 사용된다는 것을 알려준다.

1) style 속성

: HTML의 문법에서 style 이라는 '속성'이 있다.

이때 안쪽의 color:skyblue  부분은 CSS 문법이고, 나머지는 HTML 문법이다.

    <h2 style="color:skyblue">Dobby is free!</h2>
    <h2 style="color:skyblue">Dobby is free!</h2>
    <h2 style="color:skyblue">Dobby is free!</h2>

2) style 태그

: HTML의 태그 중 style 태그가 있다. 

이 태그에 둘러싸인 부분에서 CSS 문법이 사용된다는 것을 알려주는 역할을 한다.

장점1: 1) 과 똑같은 결과물이 나오지만, <style> 태그는 특정 태그가 반복될 때 태그별로 다른 서식을 적용시킬 수 있다. 태그가 많을 때 효율적이다.

장점2: <style> 태그는 <head> 태그 안에서 본문의 부연설명으로 쓰인다. 코드상 디자인과 정보 기능을 더 잘 분리시켜서 보여줄 수 있다.

<html>
  <head>
    <style>
      h2 {color:skyblue}
    </style>
  </head>
  <body>
    <h2>Dobby is free!</h2>
    <h2>Dobby is free!</h2>
    <h2>Dobby is free!</h2>
  </body>
</html>

 

2. CSS의 문법 (1) : Selector(선택자) 와 Declaration(선언)

ex) 

    <style>
      h2 {
          color:skyblue;
          text-decoration:underline
          }
    </style>

h2 는 Selector(선택자)이고 디자인 설정을 받을 개체이다.

{  } 안의 부분은 Declaration(선언)이고 Selector에 적용될 디자인 설정이다.

color , text-decoration 부분은 property(속성)이며 Declaration 안의 구체적인 요소들을 의미한다.

skyblue , underline  부분은 value(속성값)이며 property에 할당되는 값이다.

: 은 property와 value를 구분한다.

; 은 각각의 declaration을 구분한다. (declaration이 하나이면 안 써도 된다)

 

그런데 태그 단위로 선언을 하고 싶지 않을 수도 있다.

ex) 여러 <li> 태그 중 하나만 다른 색으로 표시하고 싶을 때

=> 다른 종류의 Selector를 사용하면 된다.

 

사실 Selector에는 세 종류가 있다.

  • Tag Selector : 태그 단위로 선언할 때
  • ID Selector
  • Class Selector

1) ID Selector

: <style> 태그 안에서 ID를 정의한 뒤 따로 다른 선언을 하고 싶은 개체에 해당 ID를 입력하면 된다.

    <style>
      #ping {
        color:#228B22 ; font-size: 30px
      }

    </style>

    <h2 id="ping">Dobby is free!</h2>

 

 # 뒤에는 ID 개체의 이름을 원하는 대로 정해서 입력하고, {  } 안에 디자인 요소를 지정해 준다.

-> 해당 ID Selector를 사용하고 싶으면 해당 개체 속성에 id="Selector 이름"  이런 식으로 지정한다. 

<html>
  <head>
    <style>
      #ping {
        color:#228B22 ; font-size: 30px
      }
      #dobby {
        background-color:LemonChiffon ; font-weight:bold
      }
    </style>
  </head>
  <body>
    <h1 id="ping">CSS</h1>
    <h1>CSS</h1>
      <h2>Dobby is free!</h2>
      <h2 id="dobby">Dobby is free!</h2>
  </body>
</html>

 

2) Class Selector

: <style> 태그 안에서 Class를 정의한 뒤 따로 다른 선언을 하고 싶은 개체에 해당 Class를 입력하면 된다.

 

ID Selector 와의 차이점이 무엇인가?

적용 방법은 거의 비슷하다. 다만 의미에 차이가 있다.

-Class : 여러 학생들을 구분할 때 '반'의 개념. 여러 개체를 '그룹화', '묶어서' 구분할 때 사용

-ID : 학생들 하나하나가 갖는 '고유한' 번호. 고유한 하나의 개체가 하나의 ID를 가짐.

=> Class Selector는 여러 번 사용 가능, ID Selector는 한 번만 사용 가능.

 

또한 class selector는 .dobby  이렇게 class 선언하기 전 . 을 찍는다.

<-> id selector는 #을 붙인다.

<html>
  <head>
    <style>
      #pping {
        color:#228B22 ; font-size: 30px
      }
      .dobby {
        background-color:LemonChiffon ; font-weight:bold
      }
    </style>
  </head>
  <body>
    <h1 id="pping">CSS</h1>
    <h1>CSS</h1>
      <h2>Dobby is free!</h2>
      <h2 class="dobby">Dobby is free!</h2>
      <h2>Dobby is free!</h2>
      <h2 class= "dobby">Dobby is free!</h2>
      <h2>Dobby is free!</h2>
      <h2 class= "dobby">Dobby is free!</h2>
        <h3>welcome</h3>
        <h3>welcome</h3>
  </body>
</html>

+) CSS에는 다양한 종류의 색깔이 있다.

Colors Tutorial (w3schools.com) 여기서 색깔 이름을 볼 수 있다.

 

3. CSS의 문법 (2) : 부모-자식 선택자

ex) <ol>, <ul>, <li> 태그의 경우, <ol>과 <ul> 태그는 <li> 태그를 포함한다.

즉 태그간의 포함관계가 있을 때, 특정 부분의 스타일을 지정하려면 부모-자식 관계를 고려해야 한다.

부모-자식 관계를 고려해서 Style 지정할 수 있는 여러 가지 경우:

 

경우1) 특정 태그 안에 포함되는 다른 태그의 디자인 지정할 때

<html>
  <head>
    <style>
      ol li {
        border-style : solid ; border-color : Salmon ;
        border-radius : 6px ; border-width: 1px
      }
    </style>
  </head>
  <body>
    <ol>
      <li>Window</li>
      <li>Mac OS</li>
      <li>Linux</li>
    </ol>
    <ul>
      <li>iPad</li>
        <ol>
          <li>iPad Air
            <ol>
              <li>iPad Air 3</li>
              <li>iPad Air 4</li>
            </ol>
          </li>
          <li>iPad Pro</li>
        </ol>
      <li>Galaxy Tabs</li>
      <li>Others</li>
    </ul>
  </body>
</html>

=> ol 태그 안에 포함된 li 태그의 경우라면 모두 해당 border 서식이 적용되었다.

 

경우2) 특정 태그의 바로 안에 포함되는 태그한테만 디자인 적용할 때

(아까는 A태그 안에 포함된 B태그라면 무조건 위의 디자인을 적용하는 경우였고, 

지금은 A태그 바로 안에 B태그가 포함된 경우에만 위의 디자인 서식을 적용하는 경우이다.)

cf) 아까 : A태그 안에 C태그, 그 안에 B태그 포함되면 => 적용됨

    지금 : A태그 안에 C태그, 그 안에 B태그 포함되면 => 적용 안 됨

** 만약 같은 종류의 태그인데 한쪽 태그에만 디자인을 적용하고 싶다면, id나 class Selector로 구분시켜 준다.

    <style>
      #tablet li {
        border-style : solid ; border-color : Salmon ;
        border-radius : 6px ; border-width: 1px
      }
    </style>

=> iPad Air 바로 아래의 <ol> 태그에만 id="tablet" 으로 ID Selector를 입력하였고, 이에 따라 해당 <ol> 태그 안에 속한 <li> 태그의 내용에만 디자인 서식이 적용되었다.

 

경우3) 여러 개의 태그에 같은 서식을 적용할 때

* 여러 태그가 포함관계에 있지 않아도 적용된다.

* A태그가 B태그를 포함하고 있는데 A태그에 서식이 적용되면 당연히 B태그에도 서식이 적용된다.

    <style>
       ul, ol {
        border-style : solid ; border-color : ForestGreen ;
        border-radius : 6px ; border-width: 3px
      }
    </style>

=> <ul> 태그와 <ol> 태그 모두 서식이 적용되었고, 둘 다 <li> 태그를 포함하고 있으므로 그 안의 <li>태그에도 개별적으로 서식이 적용되었다.

지금까지 상위 태그에만 적용한 속성이 하위 태그에도 적용된 것은 "상속" 이라는 개념 때문이다.

 

상속(Inheritance)

: 상위 태그(부모 태그) 에서 적용된 속성은 별다른 지시 없이도 하위 태그(자식 태그)에도 그대로 적용된다.

 

 

 

'front-side > CSS' 카테고리의 다른 글

6. 레이아웃 추가(심화)내용  (0) 2021.04.05
5. brackets ~ 레이아웃 기초 내용  (0) 2021.04.02
4. 타이포그래피-font ~ 조화  (0) 2021.04.01
3. 선택자 fin ~ 타이포그래피  (0) 2021.03.30
2. 선택자  (0) 2021.03.29

+ Recent posts