CSS交集选择器

转载自:http://blog.csdn.net/lianghe_work/article/details/52816267

问题引入

[html] view plain copy
  1. <!DOCTYPE html>  
  2. <html lang="en">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>Document</title>  
  6.     <style type="text/css">  
  7.         .red{  
  8.             color: red;  
  9.         }  
  10.     </style>  
  11. </head>  
  12. <body>  
  13.     <h2>二级标题</h2>  
  14.     <h2 class="red">二级标题</h2>  
  15.     <h2 class="red">二级标题</h2>  
  16.     <p  class="red">段落</p>  
  17.     <p>段落</p>  
  18.     <p>段落</p>  
  19. </body>  
  20. </html>  

运行的结果:

我们发现只要是含有red类的标签都变红了
如果我的需求是:只能让h2且含有red类的标签变红,这是就要需要交集选择器

交集选择器

[html] view plain copy
  1. h2.red{  
  2.             color: red;  
  3.         }  
上面就是一个交集选择器的示例:就是说必须是h2标签同时拥有.red类才会被选择器选中,如下图所示:

这时你发现第一个“段落”并没有变红,原因是他只拥有.red类,但不具备h2标签

注意:

前面讲过:后代选择器h2 .red之间有空格
而交集选择器没有空格,紧挨着一起

来源:网络


智能推荐

CSS选择器

CSS选择器 css选择器分类 简单选择器:针对某一特征判断是否选中元素 复合选择器:连续写在一起的简单选择器,针对元素自身特征选择单个元素 复杂选择器:由(空格), >, ~, +, ||等符号连接的复合选择器,根据父元素或前序元素检查单个元素 选择器列表:由逗号分隔的复杂选择器,表示“或”的关系 参考资料 W3SchoolCSS选择器参考手册 30个你必须熟记的C...

CSS选择器

作为网页制作基础,CSS 选择器很强大,用得恰当则事半功倍!本文介绍常用CSS选择器,并在下一篇中根据以往工作经验简单写一些Best practice,供前端er们参考。 基本选择器 通配符:* //匹配任何元素。 标签选择器:div/p/span等 //匹配所有的div/p/span。 class选择器:.xxx //匹配所有class属性包含xxx的元素。 id选择器:#xxx //匹配所有i...

CSS选择器~

问题描述:鼠标经过.face的时候给.ear-wrap加样式,它们是兄弟关系,如果用.face:hover .ear-wrap{ transform:rotate(-45deg);},则不生效。 原因分析: 如果是兄弟关系应该用~选择器,才能生效。 补充:兄弟选择器(~和+) ‘+’选择器则表示某元素后相邻的兄弟元素,也就是紧挨着的,只有一个的。而‘~...

css选择器

CSS选择器 一、什么是选择器 Css控制html样式,要css控制哪个元素的样式,这个元素就要被作为选择器。例如要改变标题一的大小h1{font-size:12px;},改变段落文本颜色 p{color:Red},此时h1、p为选择器。 二、选择器种类 标签选择器。 实例 选择并设置所有 <p> 元素的样式: p{ background-color:yellow;} 复制代码 *注意...

css选择器

1.属性选择器     属性选择器可以根据元素的属性及属性值来选择元素。css3中新增了三种属性选择器:E[att^=value]、E[att$=value]、E[att*=value]。     1.1 E[att^=value]属性选择器         E[att^=val...

猜你喜欢

Mysql系列六:(Mycat分片路由原理、Mycat常用分片规则及对应源码介绍)

一、Mycat分片路由原理 我们先来看下面的一个SQL在Mycat里面是如何执行的: 有3个分片dn1,dn2,dn3, id=5000001这条数据在dn2上,id=10000001这条数据在dn3上。 查询时可能有出现的问题: 1)全部扫描一遍dn1  dn2  dn3,结果导致性能浪费。 2)只扫描某个片。漏掉数据的情况。 总结: 不能多扫——&g...

虚拟机连通外网(NET模式)

(linu系统,windows同理)自定义静态ip 可以访问外网的问题,一直ping不通问题,做个笔记小计; 需要注意的问题: 选用的为net模式时, 设置虚拟机对应NET网卡的虚拟ip和本机设置的为同一个网段上    2. 设置linux网卡配置信息,首先这里需要注意的是网关配置信息和NET虚拟ip一样,然后需要开启网卡 TYPE=Ethernet BOOTPROTO=sta...

第二课 加载、修改和保存图像

第二课 加载、修改和保存图像 课程视频链接 加载图像 (cv::imread,cv::namedWindos,cv::imshow) 修改图像 (cv::cvtColor) 保存图像 (cv::imwrite) 代码历程...

Squid代理服务器

本文聊下squid限制(IP限制,域名限制,上网时间限制) 一,环境搭建实验环境需要centos7+widnwos10 先配置服务器需要双网卡,eth0设为局域网IP地址192.168.0.1,eth1设为外网ip172.16.0.100 同时设为权主机模式,NAT模式配置eth0和eth1网卡,和static 设置eth0指定一个内网ip就可以,eth1中的网关与DNS1和网络适配器中的一样,删...

setup命令防火墙配置

setup是redhat开发的命令行下命令行模式界面的GUI工具,只适用6.x或5.x版本,其他的版本比如说Suse是没有这个工具的。通过它可配置网络,防火墙,主机名,开机启动服务等,用这个命令比较方便对系统的配置。 setup 命令的基本信息如下。 命令名称:setup。 英文原意:A text mode system configuration tool。 所在路径:/usr/bin/setu...

问答精选

Groovy script to compare response xml with another xml file in the local directory

we have a hub upgrade in our project, for this before upgrade, we need to run all the services(83) and store the response in our local directory after upgrade, we need to run all the services with sam...

Microstrategy - filtering a dashboard depending on the user

I need to filter a dashboard basing on the user. for example: if user1 my-attribute = 1 if user2 my-attribute = 2 What method could I use for doing it also in reports and documents? What you need here...

How to apply context-dependent changes to numerical data in text files?

I'm aware of a lot of batch processors that can do find-and-replace operations, but they generally can't handle numerical formulas, nor can they be made to edit only a certain part of a text file. Spe...

Menu list with choices

I'm trying to make a choice list in a program and now I'm stuck with what happens when user writes incorrect input. I've tried doing it with do loop (I've looped switch statement). Also, tried to set ...

How to find out if a certain item from the dataset (ArrayList<obj>) is currently on the screen (RecyclerView)?

Here is the problem: I have a dataset: ArrayList<Alarm> alarms, which is used by a RecyclerView to display rows. How to figure out if a certain item from the dataset is currently on the screen? ...

相关问题

相关文章

热门文章

推荐文章

相关标签

推荐问答