若不设置,则伪元素不会显示。如果不想设置 content 的内容,可以将内容设置为空。如:
.a:before { content: ‘‘; display: block; width: 100px; height: 100px; background-color: red; }
要遵循如下规则:
content:‘abc‘; , content:"abc";。content: ‘(‘attr(title)‘)‘;。感觉这种写法好违法直觉。若 content 的属性值不遵循如上要求,则伪元素不会显示。
如下表所示:
| 特殊字符 | content 中这么写 |
|---|---|
| 空格 | content:"\00a0"; |
| < | content:"\003c"; |
| > | content:"\003e"; |
| & | content:"\0026"; |
| " | content:"\0022"; |
| © | content:"\00a9"; |
| ® | content:"\00ae"; |
| × | content:"\00d7"; |
更多见 这里。
display 为 block 和 inline-block 之类的块级元素有效。
.