Table of Contents

HTML5/CSS3

HTML5

기본 용어 정리

구조

<!DOCTYPE html>
<html lang="ko">
<head>
    <title></title>
</head>  
<body>
    <h1>hello, world!</h1>
</body>
</html>

<head> Tag 내부에 입력할 수 있는 Tag

meta 웹 페이지에 추가 정보 전달
title 웹 페이지의 제목
script 웹 페이지의 스크립트 추가
link 웹 페이지에 다른 파일 추가
style 웹 페이지에 스타일시트 추가
base 웹 페이지의 기본 경로 지정

<body> Tag 내부에 입력할 수 있는 Tag

글자 Tag

제목 h1 ~ h6 header. 숫자가 클 수록 작은 글씨.(하위 분류)
본문 p paragraph. 단락.
br break. 개행.
hr horizon. 수평선 삽입.
Anchor a anchor. 이동. 링크 참조
글자 형태 b bold.
i itallic
s small
sub subscript. 아래첨자
sup superscript. 위첨자
ins insert. 밑줄
del delete. 취소선. (가운데줄)
루비 문자 ruby, rp 루비 문자 선언. 브라우저 지원/미지원. 링크 참조
rt 위에 위치하는 작은 문자. 링크 참조

<a>

웹표준으로 반드시 “href” 속성을 입력해야 한다!

<a href="#">example</a>

<h1 id="from">From</h1>
<a href="#from">To</a>

<ruby>

    <!-- 루비 태그를 지원하는 경우 -->
    <ruby>
        <span>大韓民國</span>
        <rt>대한민국</rt>
    </ruby>

    <br />

    <!-- 루비 태그를 지원하지 않는 경우 -->
    <ruby>
        <span>大韓民國</span>
        <rp>(</rp>
        <rt>대한민국</rt>
        <rp>)</rp>
    </ruby>
<!-- 루비 태그를 지원하는 경우 --> <ruby> <span>大韓民國</span> <rt>대한민국</rt> </ruby>   <br />   <!-- 루비 태그를 지원하지 않는 경우 --> <ruby> <span>大韓民國</span> <rp>(</rp> <rt>대한민국</rt> <rp>)</rp> </ruby>

목록 Tag

기본 목록 ol, ul ordered list, unordered list
li list item
정의 목록 dl definition list
dt definition term
dd definition description
    <ol>
        <li>A</li>
        <li>B</li>
        <li>C</li>
    </ol>

    <ul>
        <li>A</li>
        <li>B</li>
        <li>C</li>
    </ul>

    <dl>
        <dt>definition</dt>
        <dd>(특히 사전에 나오는 단어나 구의) 정의</dd>
        <dd>(어떤 개념의) 의미</dd>
        <dd>선명도</dd>
    </dl>
<ol> <li>A</li> <li>B</li> <li>C</li> </ol>   <ul> <li>A</li> <li>B</li> <li>C</li> </ul>   <dl> <dt>definition</dt> <dd>(특히 사전에 나오는 단어나 구의) 정의</dd> <dd>(어떤 개념의) 의미</dd> <dd>선명도</dd> </dl>

Table Tag

현재는 <div> Tag 사용으로 사용 빈도가 줄음.

Tag tr table row
th table header
td table data
Element border 테두리 두께
rowspan
columnspan
행병합,열병합
    <table border="1">
        <tr>
            <th style="background: cyan">Header 1</th>
            <th>Header 2</th>
            <th>Header 3</th>
        </tr>
        <tr>
            <td>Data 1-1</td>
            <td>Data 1-2</td>
            <td rowspan="2">Data 1-2</td>
        </tr>
        <tr>
            <td>Data 2-1</td>
            <td>Data 2-2</td>
        </tr>
        <tr>
            <td colspan="3">Data 3</td>
        </tr>
    </table>
<table border="1"> <tr> <th style="background: cyan">Header 1</th> <th>Header 2</th> <th>Header 3</th> </tr> <tr> <td>Data 1-1</td> <td>Data 1-2</td> <td rowspan="2">Data 1-2</td> </tr> <tr> <td>Data 2-1</td> <td>Data 2-2</td> </tr> <tr> <td colspan="3">Data 3</td> </tr> </table>

Image Tag

<!-- width, height 잘 사용하지 않음. Stylesheet를 이용하는 것이 일반적. -->
<img src="none" alt="이미지 없음" />
<img src="none" alt="이미지 없음" />

Audio Tag

    <!-- 음원 출처 : https://en.wikipedia.org/wiki/File:My_Last_Serenade.ogg -->

    <!-- 일반적인 사용 -->
    <audio src="https://upload.wikimedia.org/wikipedia/en/7/7c/My_Last_Serenade.ogg" controls="controls"></audio>

    <!-- 특정 음악 포맷을 미지원할 경우 -->
    <!-- IE는 OGG, WAV / Oprea는 WAV 미지원 -->
    <audio controls="controls">
        <source src="sample.mp3" />
        <source src="https://upload.wikimedia.org/wikipedia/en/7/7c/My_Last_Serenade.ogg" />
    </audio>
<!-- 음원 출처 : https://en.wikipedia.org/wiki/File:My_Last_Serenade.ogg -->   <!-- 일반적인 사용 --> <audio src="https://upload.wikimedia.org/wikipedia/en/7/7c/My_Last_Serenade.ogg" controls="controls"></audio>   <!-- 특정 음악 포맷을 미지원할 경우 --> <audio controls="controls"> <source src="sample.mp3" /> <source src="https://upload.wikimedia.org/wikipedia/en/7/7c/My_Last_Serenade.ogg" /> </audio>

Video, Track Tag

    <!-- 영상 출처 : https://commons.wikimedia.org/wiki/File:Time_Lapse_of_New_York_City.ogv -->

    <!-- 일반적인 사용 -->
    <video src="https://upload.wikimedia.org/wikipedia/commons/9/9a/Time_Lapse_of_New_York_City.ogv" controls="controls" width="240"></video>
    
    <!-- 특정 영상 포맷을 미지원할 경우 -->
    <video poster="http://placehold.it/200x100" controls="controls" width="240">
        <source src="sample.mp4" type="video/mp4" />
        <source src="https://upload.wikimedia.org/wikipedia/commons/9/9a/Time_Lapse_of_New_York_City.ogv" type="video/ogg" />

        <track kind="subtitles" src="track.srt" srclang="ko" label="Korean" />
    </video>
<!-- 영상 출처 : https://commons.wikimedia.org/wiki/File:Time_Lapse_of_New_York_City.ogv -->   <!-- 일반적인 사용 --> <video src="https://upload.wikimedia.org/wikipedia/commons/9/9a/Time_Lapse_of_New_York_City.ogv" controls="controls" width="240"></video>   <!-- 특정 영상 포맷을 미지원할 경우 --> <video poster="http://placehold.it/200x100" controls="controls" width="240"> <source src="sample.mp4" type="video/mp4" /> <source src="https://upload.wikimedia.org/wikipedia/commons/9/9a/Time_Lapse_of_New_York_City.ogv" type="video/ogg" />   <track kind="subtitles" src="track.srt" srclang="ko" label="Korean" /> </video>

입력 양식 Tag

<input>

Chrome/Opera에서 더 정상적으로 보인다.

<form method="get">
    <!-- HTML4 -->
    <input type="text" /><br />
    <input type="password" /><br />
    <input type="hidden" /><br />

    <input type="image" /><br />
    <input type="file" /><br />

    <input type="checkbox" /><br />
    <input type="radio" /><br />

    <input type="button" /><br />
    <input type="reset" /><br />
    <input type="submit" /><br />

    <br />

    <!-- HTML5 -->
    <input type="date" /><br />
    <input type="datetime" /><br />
    <input type="datetime-local" /><br />
    <input type="time" /><br />
    <input type="month" /><br />
    <input type="week" /><br />

    <input type="search" /><br />
    <input type="url" /><br />
    <input type="tel" /><br />
    <input type="email" /><br />

    <input type="color" /><br />
    <input type="number" /><br />
    <input type="range" /><br />

    <br />

    <!-- label : input Tag 설명-->
    <label for="age">나이</label>
    <input id="age" type="text" />
</form>
<form method="get"> <!-- HTML4 --> <input type="text" /><br /> <input type="password" /><br /> <input type="hidden" /><br />   <input type="image" /><br /> <input type="file" /><br />   <input type="checkbox" /><br /> <input type="radio" /><br />   <input type="button" /><br /> <input type="reset" /><br /> <input type="submit" /><br />   <br />   <!-- HTML5 --> <input type="date" /><br /> <input type="datetime" /><br /> <input type="datetime-local" /><br /> <input type="time" /><br /> <input type="month" /><br /> <input type="week" /><br />   <input type="search" /><br /> <input type="url" /><br /> <input type="tel" /><br /> <input type="email" /><br />   <input type="color" /><br /> <input type="number" /><br /> <input type="range" /><br />   <br />   <!-- label : input Tag 설명--> <label for="age">나이</label> <input id="age" type="text" /> </form>

<textarea>

    <textarea cols="10" rows="3">
hello,
world!
    </textarea>
<textarea cols="10" rows="3"> hello, world! </textarea>

<select>

    <select>
        <option>A</option>
        <option>B</option>
        <option>C</option>
    </select>

    <br />

    <select multiple="multiple">
        <option>A</option>
        <option>B</option>
        <option>C</option>
    </select>

    <br />

    <select>
        <optgroup label="Alphabet">
            <option>A</option>
            <option>B</option>
            <option>C</option>
        </optgroup>
        <optgroup label="Numeric">
            <option>1</option>
            <option>2</option>
            <option>3</option>
        </optgroup>
    </select>
<select> <option>A</option> <option>B</option> <option>C</option> </select>   <br />   <select multiple="multiple"> <option>A</option> <option>B</option> <option>C</option> </select>   <br />   <select> <optgroup label="Alphabet"> <option>A</option> <option>B</option> <option>C</option> </optgroup> <optgroup label="Numeric"> <option>1</option> <option>2</option> <option>3</option> </optgroup> </select>

<fieldset> & <legend>

공간 분할 Tag

<div>, <span>

    <!-- block 형식 공간 분할 -->
    <div>동해물과</div>
    <div>백두산이</div>
    <div>마르고</div>
    <div>닳도록</div>

    <!-- inline 형식 공간 분할 -->
    <span>하느님이</span>
    <span>보우하사</span>
    <span>우리나라</span>
    <span>만세</span>
<!-- block 형식 공간 분할 --> <div>동해물과</div> <div>백두산이</div> <div>마르고</div> <div>닳도록</div>   <!-- inline 형식 공간 분할 --> <span>하느님이</span> <span>보우하사</span> <span>우리나라</span> <span>만세</span>

Semantic Tag

의미를 갖는 Tag. 모두 div Tag와 같은 기능.

header
nav
aside
section 여러 중심 내용을 감싸는 공간
article 글자가 많이 들어가는 부분
fotter
<header>
        <h1>HEADER</h1>
    </header>

    <nav>
        <ul>
            <li><a href="#">NAV Item1</a></li>
            <li><a href="#">NAV Item2</a></li>
            <li><a href="#">NAV Item2</a></li>
        </ul>
    </nav>

    <section>
        <h1>SECTION</h1>

        <article>
            <h1>ARTICLE1</h1>
            <p>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 specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
        </article>

        <article>
            <h1>ARTICLE2</h1>
            <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
        </article>
    </section>

    <aside>
        <h1>ASIDE</h1>
        <p>"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."</p>
    </aside>

    <footer>
        <address>가가도 나나시 다다동 123</address>
        <p>E-Mail : <a href="mailto:someone@example.com">someone@example.com</a>.</p>
    </footer>
<header> <h1>HEADER</h1> </header>   <nav> <ul> <li><a href="#">NAV Item1</a></li> <li><a href="#">NAV Item2</a></li> <li><a href="#">NAV Item2</a></li> </ul> </nav>   <section> <h1>SECTION</h1>   <article> <h1>ARTICLE1</h1> <p>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 specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> </article>   <article> <h1>ARTICLE2</h1> <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p> </article> </section>   <aside> <h1>ASIDE</h1> <p>"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."</p> </aside>   <footer> <address>가가도 나나시 다다동 123</address> <p>E-Mail : <a href="mailto:someone@example.com">someone@example.com</a>.</p> </footer>

CSS

Cascading Style Sheet 3 기준.

선택자(Selector)

특정 태그에 스타일이나 기능을 적용할 때 사용.

선택자 { 스타일속성: 스타일값; }
h1 { color: red; }

전체(Universal) 선택자

* 페이지 내 모든 Tag

Tag 선택자

TAG 특정 Tag

h1, p, body { color: red; }

ID 선택자, Class 선택자

ID 선택자

#ID 특정한 하나 Tag

Class 선택자

.CLASS 특정 Tag
<!DOCTYPE html>
<html>
<head>
    <style>
        .item {color: red;}
        .header {background-color: cyan;}
    </style>
</head>
<body>
    <h1 class="item header">HEADER</h1>
</body>
</html>
<head> <style> .item {color: red;} .header {background-color: cyan;} </style> </head> <body> <h1 class="item header">HEADER</h1> </body>
<html>
<head>
    <style>
        h1.header {color: red;}
    </style>
</head>
<body>
    <h1 class="header">HEADER</h1>
    <h1>HEADER</h1>
</body>
</html>
<head> <style> h1.header {color: red;} </style> </head> <body> <h1 class="header">HEADER</h1> <h1>HEADER</h1> </body>

속성(Element) 선택자

기본 속성 선택자

선택자[속성] 특정 Tag의 속성 선택
선택자[속성=값]{[속성=값]} 특정 Tag의 속성값이 같은 속성 선택

<html>
<head>
    <style>
        a[title] {background-color: cyan;}
        input[type=text] {background-color: violet;}
        input[type=text][border='1'] {background-color: yellow;}
    </style>
</head>
<body>
    <a href="#" title="test">link</a>

    <br />

    <form>
        <input type="text" />
        <input type="text" border="1" />
    </form>
</body>
</html>

http://jsbin.com/locasajofo/edit?html,output

문자열 속성 선택자

특정 Tag의 특정 속성의 속성값 ↔ 문자열 비교

<html>
<head>
    <style>
        /* 단어 선택 */

        /* 값이 단어로 포함하는 태그 선택 (- 제외) */
        h1[title~=abc] {color: cyan;}

        /* 값이 단어로 포함하는 태그 선택 (- 포함) */
        h2[title|=abc] {color: red;}

        /* 값이 전체 문자열에서 시작하는 태그 선택 */
        h3[title^=abc] {color: blue;}

        /* 값이 전체 문자열에서 끝나는 태그 선택 */
        h4[title$=abc] {color: yellow;}

        /* 값이 전체 문자열에서 포함하는 태그 선택 */
        h5[title*=abc] {color: lightgreen;}
    </style>
</head>
<body>
    <h1 title="abc">Lorem</h1>
    <h1 title="abc-xyz">Lorem</h1>
    <h1 title="abc xyz">Lorem</h1>

    <br />

    <h2 title="abc">Lorem</h2>
    <h2 title="abc-xyz">Lorem</h2>
    <h2 title="abc xyz">Lorem</h2>

    <hr />

    <h3 title="abc">Lorem</h3>
    <h3 title="abc-xyz">Lorem</h3>
    <h3 title="abc xyz">Lorem</h3>

    <br />

    <h4 title="abc">Lorem</h4>
    <h4 title="abc-xyz">Lorem</h4>
    <h4 title="abc xyz">Lorem</h4>

    <br />

    <h5 title="abc">Lorem</h5>
    <h5 title="abc-xyz">Lorem</h5>
    <h5 title="abc xyz">Lorem</h5>
</body>
</html>
<head> <style> /* 단어 선택 */   /* 값이 단어로 포함하는 태그 선택 (- 제외) */ h1[title~=abc] {color: cyan;}   /* 값이 단어로 포함하는 태그 선택 (- 포함) */ h2[title|=abc] {color: red;}   /* 값이 전체 문자열에서 시작하는 태그 선택 */ h3[title^=abc] {color: blue;}   /* 값이 전체 문자열에서 끝나는 태그 선택 */ h4[title$=abc] {color: yellow;}   /* 값이 전체 문자열에서 포함하는 태그 선택 */ h5[title*=abc] {color: lightgreen;} </style> </head> <body> <h1 title="abc">Lorem</h1> <h1 title="abc-xyz">Lorem</h1> <h1 title="abc xyz">Lorem</h1>   <br />   <h2 title="abc">Lorem</h2> <h2 title="abc-xyz">Lorem</h2> <h2 title="abc xyz">Lorem</h2>   <hr />   <h3 title="abc">Lorem</h3> <h3 title="abc-xyz">Lorem</h3> <h3 title="abc xyz">Lorem</h3>   <br />   <h4 title="abc">Lorem</h4> <h4 title="abc-xyz">Lorem</h4> <h4 title="abc xyz">Lorem</h4>   <br />   <h5 title="abc">Lorem</h5> <h5 title="abc-xyz">Lorem</h5> <h5 title="abc xyz">Lorem</h5> </body>

후손(Descendant) 선택자, 자손(Child) 선택자

Descendant 선택자 선택자 (부모 선택자 기준) 하위 전체 Tag
Child 선택자 > 선택자 {> 선택자} (부모 선택자 기준) 하위 한개 Tag
<html>
<head>
    <style>
        #header h1 {color:red;}

        #section > h1 {color:blue;}
        #section > .article1 > h1 {color:green;}
    </style>
</head>
<body>
    <div id="header">
        <h1>Lorem ipsum1</h1>
        <nav id="nav">
            <h1>Lorem ipsum2</h1>
        </nav>
    </div>

    <br />

    <div id="section">
        <h1>Lorem ipsum3</h1>
        <nav id="nav">
            <h1>Lorem ipsum4</h1>
        </nav>

        <br />

        <article class="article1">
            <h1>Lorem ipsum5</h1>
        </article>
    </div>
</body>
</html>
<head> <style> #header h1 {color:red;}   #section > h1 {color:blue;} #section > .article1 > h1 {color:green;} </style> </head> <body> <div id="header"> <h1>Lorem ipsum1</h1> <nav id="nav"> <h1>Lorem ipsum2</h1> </nav> </div>   <br />   <div id="section"> <h1>Lorem ipsum3</h1> <nav id="nav"> <h1>Lorem ipsum4</h1> </nav>   <br />   <article class="article1"> <h1>Lorem ipsum5</h1> </article> </div> </body>

동위(Adjacent sibling) 선택자

같은 Level의 Tag에서 선후 관계의 특정 Tag 선택.

선택자 2개를 A, B라고 할 때,

A + B A 바로 뒤 B 하나 선택. (One)
A ~ B A 바로 뒤 B 모두 선택. (All)

<html>
<head>
    <style>
        /* h1 뒤 바로 h2만 색상 변경 */
        h1 + h2 {color:red;}
        
        /* h1 뒤 모든 h2 배경 변경 */
        h1 ~ h2 {background-color:cyan;}
    </style>
</head>
<body>    
    <h2>Lorem ipsum</h2>
    <h2>Lorem ipsum</h2>
    <h1>Lorem ipsum</h1>
    <h2>Lorem ipsum</h2>
    <h2>Lorem ipsum</h2>
</body>
</html>

http://jsbin.com/denafuxama

반응 선택자

<html>
<head>
    <style>
        /* 마우스 커서를 */
        /* 올리면 hover, 클릭하면 active */

        h1:hover {color:red;}
        h1:active {color:cyan;}
    </style>
</head>
<body>
    <h1>Lorem ipsum</h1>
</body>
</html>

http://jsbin.com/negegitaje

상태 선택자

입력 양식 Tag의 상태 선택.

<html>
<head>
    <style>
        input:enabled {background-color:cyan;}
        input:disabled {background-color:gray;}
        input:focus {background-color:red;}

        input[type=checkbox]:checked + div {height:0;}
        div {
            overflow: hidden;
            width: 650px;
            height: 300px;

            -ms-transition-duration: 1s;
            -webkit-transition-duration: 1s;
            -moz-transition-duration: 1s;
            -o-transition-duration: 1s;
            transition-duration: 1s;
        }
    </style>
</head>
<body>
    <input />
    <input disabled="disabled" />

    <section>
        <input type="checkbox" />
        <div>
            <h1>What is Lorem Ipsum?</h1>
            <p>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 specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
        </div>
    </section>
</body>
</html>

http://jsbin.com/lefiduqoga

구조 선택자

일반 구조 선택자

특정한 위치에 있는 Tag 선택.

같은 Level의 Child 관계에서

선택자:first-child 첫 번째 위치하는 Tag 선택
선택자:last-child 마지막에 위치하는 Tag 선택
선택자:nth-child 앞에서 수열 번째 Tag 선택
선택자:nth-last-child 뒤에서 수열 번째 Tag 선택

<html>
<head>
    <style>
        ul { overflow:hidden; }
        li { 
            list-style: none; 
            float: left;
            padding: 15px;
        }

        li:first-child { border-radius: 10px 0 0 10px; }
        li:last-child { border-radius: 0 10px 10px 0; }

        li:nth-child(2n) { background: red; }
        li:nth-child(2n+1) { background: cyan; }
    </style>
</head>
<body>
    <ul>
        <li>first</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>last</li>
    </ul>
</body>
</html>

http://jsbin.com/cevowopuxu

형태 구조 선택자

일반 구조 선택자와 비슷하지만 Tag의 type으로 구분.

같은 Level의 Child 관계에서

TAG:first-of-type 첫 번째로 등장하는 특정 Tag 선택
TAG:last-of-type 마지막으로 등장하는 특정 Tag 선택
TAG:nth-of-type(수열) 앞에서 수열 번째로 등장하는 특정 Tag 선택
TAG:nth-last-of-type(수열) 뒤에서 수열 번째로 등장하는 특정 Tag 선택

<html>
<head>
    <style>
       h1:first-of-type { color: red; }
       h2:nth-of-type(2n) { color: green; }
       h3:nth-of-type(2n+1) { color: blue; }
    </style>
</head>
<body>
    <h1>h1</h1>
    <h2>h2</h2>
    <h3>h3</h3>

    <h1>h1</h1>
    <h2>h2</h2>
    <h3>h3</h3>

    <h1>h1</h1>
    <h2>h2</h2>
    <h3>h3</h3>
</body>
</html>

http://jsbin.com/xoxugocoze

문자 선택자

Tag 내부 특정 조건의 문자를 선택하는 선택자. “::“를 이용한다.

시작 문자 선택자

<html>
<head>
    <style>
       /* 첫 번째 글자 선택 */
       p::first-letter { font-size: 3em; }
       
       /* 첫 번째 줄 선택 */
       p::first-line { color: red; }
    </style>
</head>
<body>
    <p>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 specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
</body>
</html>

http://jsbin.com/lakufepono

전후 문자 선택자

TAG::after 선택자 뒤에 위치하는 공간 선택
TAG::before 선택자 앞에 위치하는 공간 선택

http://jsbin.com/jesevemifo/edit?html,output

반응 문자 선택자

<html>
<head>
    <style>
       /* Drag 문자 선택 */
       /* Firefox 47.0 작동 불가. Chrome 51.0.2704.103 m, IE11 작동. */
       p::selection { background: red; color:cyan; }
    </style>
</head>
<body>
    <p>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 specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>    
</body>
</html>

http://jsbin.com/pebokelovo

<html>
<head>
    <style>
       /* 방문 전 href 속성을 가지고 있는 "a" Tag 선택 */
       a:link { color: cyan; }

       /* 방문 후 href 속성을 가지고 있는 "a" Tag 선택 */
       a:visited { color: pink; }
    </style>
</head>
<body>
    <a href="#test">test</a>
</body>
</html>

http://jsbin.com/becoxidici

부정 선택자

<html>
<head>
    <style>
        /* "input" Tag 중 "password" 속성이 아닌 것 선택 */
       input:not([type=password]) { background : red; }
    </style>
</head>
<body>
    <input type="text" />
    <input type="password" />
    <input type="button" />
</body>
</html>

http://jsbin.com/wobifayavu

Tips

<a href='#id'>를 구현하면 Header의 시작 위치가 아닌 끝 위치로 이동하여 그 아래 내용만 보이는 문제.

:target::before {
    content: "";
    display: block;
    height: 3rem; /* fixed header height*/
    margin: -3rem 0 0; /* negative fixed header height */
}