>  기사  >  웹 프론트엔드  >  CSS에서 콘텐츠 속성을 사용하는 방법

CSS에서 콘텐츠 속성을 사용하는 방법

WBOY
WBOY원래의
2022-06-30 11:20:573441검색

CSS에서 콘텐츠 속성은 ":before" 및 ":after" 의사 요소와 함께 사용되어 콘텐츠를 삽입합니다. 구문은 "content: Normal|none|counter|attr|string|open-quote| close-quote |no-open-quote|no-close-quote|url|initial|inherit;".

CSS에서 콘텐츠 속성을 사용하는 방법

이 튜토리얼의 운영 환경: Windows 10 시스템, CSS3&&HTML5 버전, Dell G3 컴퓨터.

CSS에서 콘텐츠 속성을 사용하는 방법

콘텐츠 속성은 콘텐츠를 삽입하기 위해 :before 및 :after 의사 요소와 함께 사용됩니다.

구문은 다음과 같습니다.

content: normal|none|counter|attr|string|open-quote|close-quote|no-open-quote|no-close-quote|url|initial|inherit;

지정된 속성 값은 다음과 같습니다.
CSS에서 콘텐츠 속성을 사용하는 방법

예는 다음과 같습니다.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>123</title>
<style>
a:after {
  content: " (" attr(href) ")";
}
</style>
</head>
<body>
<p><a href="http://www.php.cn">PHP中文网</a> - 程序员梦开始的地方。</p>
<p><a href="http://www.bilibili.com">哔哩哔哩弹幕网</a> - 好用的学习网站。</p>
</body>
</html>

출력 결과는 다음과 같습니다.

CSS에서 콘텐츠 속성을 사용하는 방법

예는 다음과 같습니다.

삽입 현재 요소 번호(지정된 유형)

CSS에서 콘텐츠 속성을 사용하는 방법

css:

<style>
    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
        position: relative;padding: 10px;
        border: 1px solid #666;margin: 10px;
    }
    .fill-dom-index2 li{
        position: relative;
        counter-increment: my2;
    }
    .fill-dom-index2 li div::before{
        /* 第二个参数为list-style-type,可用值见: http://www.w3school.com.cn/cssref/pr_list-style-type.asp*/
        content: counter(my2,lower-latin)&#39;- &#39;;
        color: #f00;
        font-weight: 600;
    }
</style>

html:

<body>
    <h1>5、插入当前元素编号(指定种类)</h1>
    <div class="content fill-dom-index2">
        <ul>
            <li><div>我是第1个li标签</div></li>
            <div>我是li标签中的第1个div标签</div>
            <li><div>我是第2个li标签</div></li>
            <li><div>我是第3个li标签</div></li>
            <div>我是li标签中的第2个div标签</div>
            <li><div>我是第4个li标签</div></li>
            <li><div>我是第5个li标签</div></li>
        </ul>
    </div>
</body>

(학습 영상 공유: css 영상 튜토리얼, html 영상 튜토리얼)

위 내용은 CSS에서 콘텐츠 속성을 사용하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.