CSS / Reference / content

개요

content는 선택한 요소의 앞이나 뒤에 텍스트, 이미지 등을 추가하는 속성입니다.

  • 기본값 : normal
  • 상속 : No
  • 애니메이션 : No
  • 버전 : CSS Level 2

문법

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
content: normal | none | counter | attr | string | open-quote | close-quote | no-open-quote | no-close-quote | url | initial | inherit
content: normal | none | counter | attr | string | open-quote | close-quote | no-open-quote | no-close-quote | url | initial | inherit
content: normal | none | counter | attr | string | open-quote | close-quote | no-open-quote | no-close-quote | url | initial | inherit
  • normal
  • none
  • counter
  • attr : 특정 속성의 값을 출력합니다.
  • string : 텍스트를 추가합니다.
  • open-quote : 시작하는 따옴표를 출력합니다.
  • close-quote : 끝나는 따옴표를 출력합니다.
  • no-open-quote
  • no-close-quote
  • url : 이미지 등 미디어를 출력합니다.
  • initial : 기본값으로 설정합니다.
  • inherit : 부모 요소의 속성값을 상속 받습니다.

예제 - 텍스트 추가하기

  • p 요소 앞에 Hello World를 추가합니다.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>CSS</title>
<style>
* {
font-family: Consolas, monospace;
font-size: 24px;
}
p:before {
content: "Hello World";
}
</style>
</head>
<body>
<p>Lorem ipsum dolor</p>
</body>
</html>
<!doctype html> <html lang="ko"> <head> <meta charset="utf-8"> <title>CSS</title> <style> * { font-family: Consolas, monospace; font-size: 24px; } p:before { content: "Hello World"; } </style> </head> <body> <p>Lorem ipsum dolor</p> </body> </html>
<!doctype html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <title>CSS</title>
    <style>
      * {
        font-family: Consolas, monospace;
        font-size: 24px;
      }
      p:before {
        content: "Hello World";
      }
    </style>
  </head>
  <body>
    <p>Lorem ipsum dolor</p>
  </body>
</html>

  • 추가한 텍스트는 CSS로 더 꾸밀 수 있습니다.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
p:before {
content: "Hello World";
margin-right: 20px;
font-weight: bold;
color: cornflowerblue;
}
p:before { content: "Hello World"; margin-right: 20px; font-weight: bold; color: cornflowerblue; }
p:before {
  content: "Hello World";
  margin-right: 20px;
  font-weight: bold;
  color: cornflowerblue;
}

예제 - 이미지 추가하기

  • p 요소 앞에 images 폴더 안에 있는 circle.png를 추가합니다.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>CSS</title>
<style>
* {
font-family: Consolas, monospace;
font-size: 24px;
}
p:before {
content: url( "images/circle.png" );
}
</style>
</head>
<body>
<p>Lorem ipsum dolor</p>
</body>
</html>
<!doctype html> <html lang="ko"> <head> <meta charset="utf-8"> <title>CSS</title> <style> * { font-family: Consolas, monospace; font-size: 24px; } p:before { content: url( "images/circle.png" ); } </style> </head> <body> <p>Lorem ipsum dolor</p> </body> </html>
<!doctype html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <title>CSS</title>
    <style>
      * {
        font-family: Consolas, monospace;
        font-size: 24px;
      }
      p:before {
        content: url( "images/circle.png" );
      }
    </style>
  </head>
  <body>
    <p>Lorem ipsum dolor</p>
  </body>
</html>

  • 추가한 이미지는 CSS로 더 꾸밀 수 있습니다.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
p:before {
content: url( "images/circle.png" );
vertical-align: middle;
margin-right: 30px;
}
p:before { content: url( "images/circle.png" ); vertical-align: middle; margin-right: 30px; }
p:before {
  content: url( "images/circle.png" );
  vertical-align: middle;
  margin-right: 30px;
}

  • content 속성으로 추가한 이미지는 크기를 정할 수 없습니다. 크기를 조절하고 싶다면 background 속성을 이용합니다.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
p:before {
content: "";
display: inline-block;
background-image: url( "images/circle.png" );
background-size: 40px 40px;
width: 40px;
height: 40px;
vertical-align: middle;
margin-right: 20px;
}
p:before { content: ""; display: inline-block; background-image: url( "images/circle.png" ); background-size: 40px 40px; width: 40px; height: 40px; vertical-align: middle; margin-right: 20px; }
p:before {
  content: "";
  display: inline-block;
  background-image: url( "images/circle.png" );
  background-size: 40px 40px;
  width: 40px;
  height: 40px;
  vertical-align: middle;
  margin-right: 20px;
}

예제 - 속성값 출력하기

  • p 요소 앞에 p 요소의 class 값을 출력합니다.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>CSS</title>
<style>
* {
font-family: Consolas, monospace;
font-size: 24px;
}
p:before {
content: attr( class );
}
</style>
</head>
<body>
<p class="abc bcd">Lorem ipsum dolor</p>
</body>
</html>
<!doctype html> <html lang="ko"> <head> <meta charset="utf-8"> <title>CSS</title> <style> * { font-family: Consolas, monospace; font-size: 24px; } p:before { content: attr( class ); } </style> </head> <body> <p class="abc bcd">Lorem ipsum dolor</p> </body> </html>
<!doctype html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <title>CSS</title>
    <style>
      * {
        font-family: Consolas, monospace;
        font-size: 24px;
      }
      p:before {
        content: attr( class );
      }
    </style>
  </head>
  <body>
    <p class="abc bcd">Lorem ipsum dolor</p>
  </body>
</html>

예제 - 따옴표 출력하기

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>CSS</title>
<style>
* {
font-family: Consolas, monospace;
font-size: 24px;
}
p:before {
content: open-quote;
}
p:after {
content: close-quote;
}
</style>
</head>
<body>
<p>Lorem ipsum dolor</p>
</body>
</html>
<!doctype html> <html lang="ko"> <head> <meta charset="utf-8"> <title>CSS</title> <style> * { font-family: Consolas, monospace; font-size: 24px; } p:before { content: open-quote; } p:after { content: close-quote; } </style> </head> <body> <p>Lorem ipsum dolor</p> </body> </html>
<!doctype html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <title>CSS</title>
    <style>
      * {
        font-family: Consolas, monospace;
        font-size: 24px;
      }
      p:before {
        content: open-quote;
      }
      p:after {
        content: close-quote;
      }
    </style>
  </head>
  <body>
    <p>Lorem ipsum dolor</p>
  </body>
</html>

같은 카테고리의 다른 글
CSS / Reference / background-color

CSS / Reference / background-color

background-color로 배경의 색을 정합니다. 그 색으로 border와 padding을 포함한 영역을 칠합니다. margin 영역은 칠하지 않습니다. 기본값 : transparent 상속 : No 애니메이션 : Yes 버전 : CSS Level 1

CSS / Reference / text-align

CSS / Reference / text-align

text-align은 문단 정렬 방식을 정하는 속성입니다. 기본값 : 읽는 방향이 LTR(왼쪽에서 오른쪽)인 경우 left, RTL(오른쪽에서 왼쪽)인 경우 right 상속 : Yes 애니메이션 : No 버전 : CSS Level 1

CSS / Reference / list-style-position

CSS / Reference / list-style-position

list-style-position으로 ul, ol 등의 목록의 마커(marker)의 위치를 정합니다. 기본값 : outside 상속 : Yes 애니메이션 : No 버전 : CSS Level 1

CSS / Reference / box-shadow

CSS / Reference / box-shadow

box-shadow는 선택한 요소에 그림자 효과를 만들어주는 속성입니다. 기본값 : none 상속 : No 애니메이션 : Yes 버전 : CSS Level 3 글자에 그림자 효과를 주고 싶다면 text-shadow 속성을 사용합니다.

CSS / Reference / list-style-type

CSS / Reference / list-style-type

목록은 ul 태그 또는 ol 태그로 만듭니다. 목록 앞에 붙는 도형이나 문자을 마커(Marker)라고 하는데, 어떤 형식 또는 어떤 모양의 마커를 사용할지는 list-style-type으로 정할 수 있습니다.

CSS / Reference / background-image

CSS / Reference / background-image

background-image는 이미지를 배경으로 사용하게 하는 속성입니다. 기본값 : none 상속 : No 애니메이션 : No 버전 : CSS Level 1

CSS / Reference / background-repeat

CSS / Reference / background-repeat

background-repeat는 배경 이미지의 반복 여부와 반복 방향을 정하는 속성입니다. 기본값 : repeat 상속 : No 애니메이션 : No 버전 : CSS Level 1

CSS / Reference / accent-color

CSS / Reference / accent-color

accent-color는 HTML의 폼 요소에 사용되는 강조 색상을 정하는 속성입니다. 기본적으로 브라우저는 사용자 인터페이스 요소에 특정한 시스템 색상을 사용하지만, accent-color를 사용하면 이러한 요소들의 강조 색상을 커스터마이즈할 수 있습니다.

CSS / Reference / font-style

CSS / Reference / font-style

font-style은 글자 모양을 정하는 속성으로, 기울임 여부를 정합니다. 기본값 : normal 상속 : Yes 애니메이션 : No 버전 : CSS Level 1

CSS / Reference / color

CSS / Reference / color

color로 텍스트의 색을 정합니다. 상속 : Yes 애니메이션 : Yes 버전 : CSS Level 1