What types of css3 attribute selectors include

青灯夜游
Release: 2021-12-22 11:35:08
Original
6599 people have browsed it

css3 attribute selector includes 3 types: 1. "E[att^=value]" selector, selects the tag named E, and the tag defines the att attribute, and the attribute value includes the prefix of value Substring; 2. "E[att$=value]" selector; 3. "E[att*=value]" selector.

What types of css3 attribute selectors include

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

Attribute selector can select elements based on their attributes and attribute values. Three new attribute selectors have been added to CSS3: E[att^=value], E[att$=value] and E[att*=value], we will introduce it in detail below.

<span style="font-size: 18px;"><strong>E[att^=value]</strong></span>Attribute selector

E[att^=value]The attribute selector refers to selecting the tag named E, and the tag defines the att attribute, and the att attribute value contains the substring prefixed with value. It should be noted that E can be omitted. If omitted, it means that any element that meets the condition can be matched. For example, div[id^=section] indicates that the match contains the id attribute, and the id attribute value is a div element starting with the "section" string.

The following uses a case to demonstrate the usage of the E[att^=value] attribute selector, as shown below.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>E[att^=value]属性选择器的应用</title>
        <style type="text/css">
            p[id^="one"]{
                color:pink;
                font-family: "微软雅黑";
                font-size: 20px;
            }
        </style>
    </head>
    <body>
        <p id="one">为了看日出,我常常早起。那时天还没有大亮,周围非常清静,船上只有机器的响声。</p>
        <p id="two">天空还是一片浅蓝,颜色很浅。转眼间天边出现了一道红霞,慢慢地在扩大它的范围,加强它的亮光。我知道太阳要从天边升起来了,便目不转睛地望着那里。</p>
        <p id="one1">果然过了一会儿,在那个地方出现了太阳的小半边脸,红是真红,却没有亮光。这个太阳好像负着重荷似地一步一步、慢慢地努力上升,到了最后,终于冲破了云霞,完全跳出了海面,颜色红得非常可爱。一刹那间,这个深红的圆东西,忽然发出了夺目的亮光,射得人眼睛发痛,它旁边的云朵也突然有了光彩。</p>
        <p id="two1">有时太阳走进了云堆中,它的光线却从云里射下来,直射到水面上。这时候要分辨出哪里是水,哪里是天,倒也不容易,因为我就只看见一片灿烂的亮光。</p>
    </body>
</html>
Copy after login

In the above code, the [att^=value]selector "p[id^="one"]" is used. As long as the id attribute value in the p element starts with the "one" string, it will be selected, thus presenting a special text effect.

What types of css3 attribute selectors include

<span style="max-width:90%"><strong>E[att$=value]</strong></span>Attribute Selector

E[att$=value]The attribute selector refers to selecting the tag named E, and the tag defines the att attribute, and the att attribute value contains the suffix substring of value. Like the E[att^=value] selector, the E element can be omitted. If omitted, it means that any element that meets the condition can be matched. For example, div[id$=section] indicates that the match contains the id attribute, and the id attribute value is the div element ending with the "section" string.

The following uses a case to demonstrate the usage of the E[att$=value] attribute selector, as shown below.

<!Doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>E[att$=value] 属性选择器的应用</title>
    <style type="text/css">
        p[id$="main"]{
            color: #0cf;
            font-family: "宋体";
            font-size: 20px;
        }
    </style>
</head>
    <body>
        <p id="old1">盼望着,盼望着,东风来了,春天的脚步近了。</p>
        <p id="old2">小草偷偷地从土里钻出来,嫩嫩的,绿绿的。园子里,田野里,瞧去,一大片一大片满是的。坐着,躺着,打两个滚,踢几脚球,赛几趟跑,捉几回迷藏。风轻悄悄的,草绵软软的。</p>
        <p id="oldmain">桃树、杏树、梨树,你不让我,我不让你,都开满了花赶趟儿。红的像火,粉的像霞,白的像雪。花里带着甜味,闭了眼,树上仿佛已经满是桃儿、杏儿、梨儿!花下成千成百的蜜蜂嗡嗡地闹着……</p>
        <p id="newmain">“吹面不寒杨柳风”,不错的,像母亲的手抚摸着你。风里带来些新翻的泥土的气息,混着青草味,还有各种花的香,都在微微润湿的空气里酝酿。鸟儿将窠巢安在繁花嫩叶当中,高兴起来了……</p>
    </body>
</html>
Copy after login

In the above code, the [att$=value]selector "p[id$="main"]" is used. As long as the id attribute value in the p element ends with the "main" string, it will be selected, thus presenting a special text effect.

What types of css3 attribute selectors include

<span style="max-width:90%"><strong>E[att*=value]</strong></span>Attribute Selector

E[att*=value]The selector is used to select the tag named E, and the tag defines the att attribute, and the att attribute value contains the value substring . This selector is the same as the previous two selectors. The E element can also be omitted. If omitted, it means that any element that meets the condition can be matched. For example, div[id*=section] means matching div elements that contain the id attribute and the id attribute value contains the "section" string.

The following uses a case to demonstrate the usage of the E[att*=value] attribute selector, as shown below.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>E[att*=value]属性选择器的使用</title>
<style type="text/css">
    p[id*="demo"]{
        color:#0ca;
        font-family: "宋体";
        font-size: 20px;
    }
</style>
</head>
    <body>
        <p id="demo1">我们消受得秦淮河上的灯影,当四月犹皎的仲夏之夜。 </p>
        <p id="main1">在茶店里吃了一盘豆腐干丝,两个烧饼之后,以至歪的脚步踅上夫子庙前停泊着的画访,就懒洋洋地躺到藤椅上去了。好郁蒸的江南,傍也还是热的。"快开船罢!"桨声响了。</p>
        <p id="newdemo">小的灯舫初次在河中荡漾;于我,情景是颇朦胧,滋味是怪羞涩的。我要错认它作七里的山塘;可是,河房里明窗洞启,映着玲珑入画的栏干,顿然省得身在何处了……</p>
        <p id="olddemo">又早是夕阳西下,河上妆成一抹胭脂的薄媚。是被青溪的姊妹们所薰染的吗?还是匀得她们脸上的残脂呢?寂寂的河水,随双桨打它,终没言语。密匝匝的绣恨逐老去的年华,已都如蜜饧似的融在流波的心窝里、连呜咽也将嫌它多事,更哪里论到哀嘶……</p>
    </body>
</html>
Copy after login

In the above code, the [att*=value]selector "p[id*="demo"]" is used. As long as the id attribute value in the p element contains the "demo" string, it will be selected, thus presenting a special text effect.

What types of css3 attribute selectors include

(Learning video sharing: css video tutorial)

The above is the detailed content of What types of css3 attribute selectors include. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!