css -::和 ~ 在 css 中做什么?

标签 css pseudo-element css-selectors

我在推特上看到一个人写的代码,它是这样的:

div::after {
-webkit-transform: rotate(2deg);
}

div ~ div {
-webkit-transform: rotate(0deg);
}

这是什么?

最佳答案

The double colon replaced the single-colon selectors for pseudo-elements in CSS3 to make an explicit distinction between pseudo-classes and pseudo-elements. For backward compatibility, the single-colon syntax is acceptable for pre-CSS3 selectors. So, :after is a pseudo-class and ::after is a pseudo-element.


The general sibling selector is available in CSS3, and the combinator used in this selector is a tilde character (~).

The selector matches elements that are siblings of a given element. This example will match a p element if it’s a sibling of an h2 element:

http://reference.sitepoint.com/css/generalsiblingselector

http://www.evotech.net/blog/2007/05/after-v-after-what-is-double-colon-notation/

关于css -::和 ~ 在 css 中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10267643/

相关文章:

css - 如何更改 jquery 数据表导出按钮的字体系列

javascript - 元素的宽度在 javascript 中占怪癖模式?

使用伪 :before and :after elements 的 IE8 中面包屑导航的 CSS 样式

python - 使用 Python (Selenium) 选择提交按钮

中间元素的 CSS 选择器模式

html - CSS 不适用于组织结构图(使用 ul 和 li 构建)

html - 将 Bootstrap 3 div 放在居中的 div 中以居中

html - 如何使用 CSS 在另一个元素下方添加一个元素?

css - 垂直居中 :before/:after pseudo-elements 的内容

css - CLASSLESS **和** IDLESS 元素的 Jsoup 选择器符号?