Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么不能在css样式之后插入/使用::BEFORE::呢?_Css_Pseudo Element_Pseudo Class - Fatal编程技术网

为什么不能在css样式之后插入/使用::BEFORE::呢?

为什么不能在css样式之后插入/使用::BEFORE::呢?,css,pseudo-element,pseudo-class,Css,Pseudo Element,Pseudo Class,我正在尝试使用: .widget::before{ background:red; height:20px; width:100%; content: ""; <---- if this is removed, then block is not visible at all } .widget::before{ 背景:红色; 高度:20px; 宽度:100%; 内容:;没有内容:;在小部件之前没有要添加的内容。您可以声明伪类的大小、颜色、形状等…但是没有声明“内容”

我正在尝试使用:

.widget::before{
  background:red;
  height:20px;
  width:100%;
  content: "";   <---- if this is removed, then block is not visible at all
}
.widget::before{
背景:红色;
高度:20px;
宽度:100%;
内容:;没有
内容:;
在小部件之前没有要添加的内容。您可以声明伪类的大小、颜色、形状等…但是没有声明“内容”是什么,就没有要插入的内容。

是的,应该这样。
CSS伪元素用于向页面添加内容,因此必须显示内容。
:

此属性与:before和:after伪元素一起使用,以生成文档中的内容。值具有以下含义:
: 不生成伪元素


这意味着伪元素必须具有要生成的内容。

使用::before和::after伪类的目的是使用CSS插入内容。如果没有为伪类声明内容属性,则不会看到任何更改