Skip to content

[css] 第4天 CSS选择器有哪些?哪些属性可以继承? #11

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

第4天 CSS选择器有哪些?哪些属性可以继承?

Activity

yxkhaha

yxkhaha commented on Apr 20, 2019

@yxkhaha

选择器

  • 通配符
  • id
  • class
  • 标签
  • 后代选择器
  • 子选择器
  • 兄弟选择器
  • 属性选择器
  • 伪类选择器
  • 伪元素选择器

可以继承的属性

  • font-size
  • font-weight
  • font-style
  • font-family
  • color
hbl045

hbl045 commented on May 5, 2019

@hbl045

属性继承好像只要有inherit属性都可以继承,详情自查

tiyunchen

tiyunchen commented on May 28, 2019

@tiyunchen

text-indent:文本缩进
text-align:文本水平对齐
text-shadow:设置文本阴影
line-height:行高
word-spacing:增加或减少单词间的空白(即字间隔)
letter-spacing:增加或减少字符间的空白(字符间距)
text-transform:控制文本大小写direction:规定文本的书写方向

AricZhu

AricZhu commented on Jun 18, 2019

@AricZhu

能继承的属性:

字体系列

font-size
font-weight
font-family
font-style
...

文本系列

text-align
text-indent
text-shadow
line-height
color
...

其他

visibility
cursor
...

poporeki

poporeki commented on Jul 4, 2019

@poporeki

选择器
id选择器 #header
class选择器 .container
伪类选择器 ::after
属性选择器 [type='input']
兄弟选择器 +
后代选择器 >
通配符 *
继承
这个还真没记过
font-size
font-family
text-align
color

Lianfeiru

Lianfeiru commented on Jul 30, 2019

@Lianfeiru
wsb260

wsb260 commented on Jul 31, 2019

@wsb260

选择器:

通配符,id,class,标签,后代选择器,子选择器,兄弟选择器,属性选择器,伪类选择器,伪元素选择器

可继承的属性:

字体属性:font-size,font-weight,font-style,font-family
文本属性:text-indent,text-align,line-height,word-spacing,letter-spacing,color,direction,text-transform
元素可见性:visibility,opacity
光标属性:cursor

weizhanzhan

weizhanzhan commented on Sep 9, 2019

@weizhanzhan

选择器

  • id
  • class
  • 通配符 *
  • 后代 >
  • 兄弟 +
  • 相同的父元素中位于某元素之后的某些元素 ~
  • 伪类 ::hover ....
  • 伪元素 ::before ...
  • 属性 [type='input']

继承

  • font-size
  • font-family
  • color
  • text-align
  • cursor
censek

censek commented on Sep 27, 2019

@censek
选择器 例子 例子描述 CSS
.class .intro 选择 class="intro" 的所有元素。 1
#id #firstname 选择 id="firstname" 的所有元素。 1
* * 选择所有元素。 2
element p 选择所有

元素。

1
element,element div,p 选择所有
元素和所有

元素。

1
element element div p 选择
元素内部的所有

元素。

1
element>element div>p 选择父元素为
元素的所有

元素。

2
element+element div+p 选择紧接在
元素之后的所有

元素。

2
[attribute] [target] 选择带有 target 属性所有元素。 2
[attribute=value] [target=_blank] 选择 target="_blank" 的所有元素。 2
[attribute~=value] [title~=flower] 选择 title 属性包含单词 "flower" 的所有元素。 2
[attribute|=value] [lang|=en] 选择 lang 属性值以 "en" 开头的所有元素。 2
:link a:link 选择所有未被访问的链接。 1
:visited a:visited 选择所有已被访问的链接。 1
:active a:active 选择活动链接。 1
:hover a:hover 选择鼠标指针位于其上的链接。 1
:focus input:focus 选择获得焦点的 input 元素。 2
:first-letter p:first-letter 选择每个

元素的首字母。

1
:first-line p:first-line 选择每个

元素的首行。

1
:first-child p:first-child 选择属于父元素的第一个子元素的每个

元素。

2
:before p:before 在每个

元素的内容之前插入内容。

2
:after p:after 在每个

元素的内容之后插入内容。

2
:lang(language) p:lang(it) 选择带有以 "it" 开头的 lang 属性值的每个

元素。

2
element1~element2 p~ul 选择前面有

元素的每个

    元素。
3
[attribute^=value] a[src^="https"] 选择其 src 属性值以 "https" 开头的每个 元素。 3
[attribute$=value] a[src$=".pdf"] 选择其 src 属性以 ".pdf" 结尾的所有 元素。 3
[attribute*=value] a[src*="abc"] 选择其 src 属性中包含 "abc" 子串的每个 元素。 3
:first-of-type p:first-of-type 选择属于其父元素的首个

元素的每个

元素。

3
:last-of-type p:last-of-type 选择属于其父元素的最后

元素的每个

元素。

3
:only-of-type p:only-of-type 选择属于其父元素唯一的

元素的每个

元素。

3
:only-child p:only-child 选择属于其父元素的唯一子元素的每个

元素。

3
:nth-child(n) p:nth-child(2) 选择属于其父元素的第二个子元素的每个

元素。

3
:nth-last-child(n) p:nth-last-child(2) 同上,从最后一个子元素开始计数。 3
:nth-of-type(n) p:nth-of-type(2) 选择属于其父元素第二个

元素的每个

元素。

3
:nth-last-of-type(n) p:nth-last-of-type(2) 同上,但是从最后一个子元素开始计数。 3
:last-child p:last-child 选择属于其父元素最后一个子元素每个

元素。

3
:root :root 选择文档的根元素。 3
:empty p:empty 选择没有子元素的每个

元素(包括文本节点)。

3
:target #news:target 选择当前活动的 #news 元素。 3
:enabled input:enabled 选择每个启用的 元素。 3
:disabled input:disabled 选择每个禁用的 元素 3
:checked input:checked 选择每个被选中的 元素。 3
:not(selector) :not(p) 选择非

元素的每个元素。

3
::selection ::selection 选择被用户选取的元素部分。 3

css有哪些属性可以继承?

rennzhang

rennzhang commented on Mar 11, 2020

@rennzhang

CSS 的选择器

这里不做统计了,可以参考速查文档


那些属性可以继承

1. 所有元素都可以继承

  • visibilitycursor

2. 内联元素可以继承

  • letter-spacing:字符之间的间隙
  • word-spacing:单词之间的间隙
  • white-space:换行方式
  • line-height:行高
  • color:颜色
  • font:字体设置
  • font-family:字体名称
  • font-size:字体大小
  • font-style:字体样式
  • font-variant:是否为小型的大写字母
  • font-weight:文本字体的粗细
  • text- decoration:复合属性。文本的装饰。
  • text-transform:文本的大小写
  • direction:文本流的方向

3. 块级元素可以继承

  • text-indent:文本缩进
  • text-align:文本对齐方式

4. 列表元素可以继承

  • list-style:复合属性。设置列表项目相关内容
  • list-style-type:列表项所使用的预设标记
  • list-style-position:列表项标记如何根据文本排列
  • list-style-image:列表项标记的图像

5. 表格元素嗯昆虫继承

  • border-collapse:表格的行和单元格的边是合并还是独立

6. 不可继承的元素

displaymarginborderpaddingbackgroundheightmin-heightmax- heightwidthmin-widthmax-widthoverflowpositionleftrighttopbottomz-indexfloatcleartable-layoutvertical-alignpage-break-afterpage-bread-before和unicode-bid

blueRoach

blueRoach commented on May 18, 2020

@blueRoach

CSS选择器:
通配符
元素选择器
class选择器
id选择器
属性选择器
伪类

可继承属性:
font-
text-
visibility

giggleCYT

giggleCYT commented on May 29, 2020

@giggleCYT

选择器
通配符、id、class、元素选择器、子代选择器、兄弟选择器、属性选择器、伪类、伪元素
可继承属性
color、font-(size、style、family...)、text-(transform、align...)、list-style-(type、position...)

huoyuhao

huoyuhao commented on Jan 28, 2021

@huoyuhao
选择器 示例
通配符 *
标签选择器 span
class选择器 .container
id选择器 #app
属性选择器 [type='input']
后代选择器 空格
子选择器 >
一般兄弟组合器 ~ (同一个父节点,后一个节点在前一个节点后面的任意位置)
紧邻兄弟选择器 +(同一个父节点,一个元素紧跟在前一个之后)
伪元素选择器 :hover
伪类选择器 ::after

16 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@huoyuhao@WangXi01@blueRoach@poporeki

        Issue actions

          [css] 第4天 CSS选择器有哪些?哪些属性可以继承? · Issue #11 · haizlin/fe-interview