Table of Contents
1 Use a selector to insert content " >1 Use a selector to insert content
2 Specify individual elements not to be inserted" >2 Specify individual elements not to be inserted
3 Insert image files " >3 Insert image files
4 Display the value of the alt attribute as the title of the image" >4 Display the value of the alt attribute as the title of the image
5 Use the content attribute to insert the item number " >5 Use the content attribute to insert the item number
(1) Add consecutive numbers before multiple titles
(2) Append text to the item number
(3) Specify the type of number
(4) Number nesting
(5) Embed large numbers in middle numbers
(6) Add nested text symbols on both sides of the string
Home Web Front-end CSS Tutorial How to use selectors to insert required content into the page in css3 (code attached)

How to use selectors to insert required content into the page in css3 (code attached)

Aug 24, 2018 am 10:27 AM
css3 web front end

The content of this article is about how to use CSS3 selectors to insert the required content into the page. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1 Use a selector to insert content

Use the after or before selector to define the content to be inserted in the content attribute of the selector. When the inserted content is text When inserting text, you must add single or double quotes on both sides of the inserted text.

<style type="text/css">
h2:before{  content:‘COLUMN’;}
</style>
Copy after login

2 Specify individual elements not to be inserted

Use the none attribute value of the content attribute

<style type="text/css">
h2.sample:before{  content:none;}
</style>
Copy after login

3 Insert image files

<style type="text/css">
h2:before{  content:url(mark.png);}
</style>
Copy after login

4 Display the value of the alt attribute as the title of the image

By specifying the form of "attr (attribute name)" in the content attribute, you can The attribute values ​​of each attribute are displayed.

img:after{
content:attr(alt);
display:block;
text-align:center;
}
Copy after login

5 Use the content attribute to insert the item number

(1) Add consecutive numbers before multiple titles

1. In the content attribute Use the counter attribute value to append consecutive numbers to multiple items

: before{ content: counter (counter name);} (Use a counter to calculate the number, and the counter can be named arbitrarily)

2. You also need to add the specification of the counter-increment attribute of the element in the element's style. In order to use continuous numbering, you need to set the attribute value of the counter-increment attribute to the before selector or after selector. The counter name specified in the counter attribute value.

{ counter-increment: the counter name specified in the before selector or after selector}

h1:before{content:counter(mycounter);}
h1{counter-increment:mycounter;}//1、2、3.......
Copy after login

(2) Append text to the item number

h1:before{content:‘第’counter(mycounter)‘章’;}//第1章大标题、第2章大标题.........
Copy after login

(3) Specify the type of number

1. Using the content attribute of the before selector or after selector, you can add not only numeric numbers, but also alphabetical numbers or Roman numeral numbers.

content: counter (counter name, numbering type)

2. You can use the value of the list-style-type attribute to specify the numbering type. For example, when numbering in uppercase letters, use "upper- alpha" attribute, use the "upper-roman" attribute when specifying uppercase Roman letters.

h1:before{content:counter(mycounter,upper-alpha)‘.’;}// A.、B.、C.、
Copy after login

(4) Number nesting

h1:before{content:counter(mycounter);}//1(1、2、3...)、2(1、2、3...)、........
h1{counter-increment:mycounter;counter-reset:subcounter;}(将中编号进行重置)
h2:before{content:counter(subcounter);}
h2{counter-increment:subcounter;margin-left:40px}
Copy after login

(5) Embed large numbers in middle numbers

h2:before{content:counter(mycounter)‘-’ counter(subcounter)‘.’;}//1-1、1-2
Copy after login

(6) Add nested text symbols on both sides of the string

1. You can use the open-quote attribute value and close-quote attribute value of the content attribute to add nested text symbols such as brackets, single quotes, and double quotes on both sides of the string.

2. The open-quote attribute value is used to add the beginning of the nested text symbol, and the close-quote attribute value is used to add the end of the nested text symbol.

3. Use the quotes attribute in the style of the element to specify what nested text symbols to use

h1:before{  content:open-quote; }
h1:after { content:close-quote; }
h1{   quotes:"(" ")"   }//形如:   (标题)
Copy after login

Related recommendations:

CSS3 Series 1 (Overview, Selection , use selectors to insert content)_html/css_WEB-ITnose

How to insert content into the page in css3

The above is the detailed content of How to use selectors to insert required content into the page in css3 (code attached). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to achieve wave effect with pure CSS3? (code example) How to achieve wave effect with pure CSS3? (code example) Jun 28, 2022 pm 01:39 PM

How to achieve wave effect with pure CSS3? This article will introduce to you how to use SVG and CSS animation to create wave effects. I hope it will be helpful to you!

What frameworks are there for web front-end? What frameworks are there for web front-end? Aug 23, 2022 pm 03:31 PM

Web front-end frameworks include: 1. Angular, a front-end framework for creating a single application interface; 2. React, a JavaScript development framework for building user interfaces; 3. Vue, a progressive framework for building user interfaces JavaScript framework; 4. Bootstartp, a front-end framework based on HTML, CSS, and JavaScript; 5. QUICK UI, a set of enterprise-level web front-end development solutions; 6. SUI, a front-end component library.

Use CSS skillfully to realize various strange-shaped buttons (with code) Use CSS skillfully to realize various strange-shaped buttons (with code) Jul 19, 2022 am 11:28 AM

This article will show you how to use CSS to easily realize various weird-shaped buttons that appear frequently. I hope it will be helpful to you!

How to hide elements in css without taking up space How to hide elements in css without taking up space Jun 01, 2022 pm 07:15 PM

Two methods: 1. Using the display attribute, just add the "display:none;" style to the element. 2. Use the position and top attributes to set the absolute positioning of the element to hide the element. Just add the "position:absolute;top:-9999px;" style to the element.

[Hematemesis Compilation] The latest front-end interview questions and answers in 2023 (Collection) [Hematemesis Compilation] The latest front-end interview questions and answers in 2023 (Collection) Jun 29, 2022 am 11:20 AM

This article summarizes some selected Web front-end interview questions worth collecting (with answers). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

What is a web front-end engineer What is a web front-end engineer Aug 23, 2022 pm 05:10 PM

A web front-end engineer is an engineer who is engaged in Web front-end development. His main job is to develop, optimize, and improve the website. His main responsibility is to use various professional technologies to develop client products, and then combine the back-end development technology to simulate the overall effect and provide the website with The products and services provided on realize first-class web interfaces, optimize code and maintain good compatibility, and are committed to improving user experience through technology.

How to implement lace borders in css3 How to implement lace borders in css3 Sep 16, 2022 pm 07:11 PM

In CSS, you can use the border-image attribute to achieve a lace border. The border-image attribute can use images to create borders, that is, add a background image to the border. You only need to specify the background image as a lace style; the syntax "border-image: url (image path) offsets the image border width inward. Whether outset is repeated;".

It turns out that text carousel and image carousel can also be realized using pure CSS! It turns out that text carousel and image carousel can also be realized using pure CSS! Jun 10, 2022 pm 01:00 PM

How to create text carousel and image carousel? The first thing everyone thinks of is whether to use js. In fact, text carousel and image carousel can also be realized using pure CSS. Let’s take a look at the implementation method. I hope it will be helpful to everyone!

See all articles