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选择器之后?_Css_Css Selectors - Fatal编程技术网

工作示例:带多个背景图像的css选择器之后?

工作示例:带多个背景图像的css选择器之后?,css,css-selectors,Css,Css Selectors,我发誓我见过有人使用:after选择器将多个背景图像添加到元素中。不管什么原因,我都不能让它工作。我做错了什么?有人能给我举一个有效的例子吗 #el li { background:url(image1.jpg) top center;} #el li:after { background:url(image2.jpg) bottom center;} 谢谢 你能做到,但我从未尝试过:after似乎在元素之后创建了一个类似内联的元素。您可以尝试添加此CSS(不知道是否有效): 你能做到,但我从

我发誓我见过有人使用:after选择器将多个背景图像添加到元素中。不管什么原因,我都不能让它工作。我做错了什么?有人能给我举一个有效的例子吗

#el li { background:url(image1.jpg) top center;}
#el li:after { background:url(image2.jpg) bottom center;}

谢谢

你能做到,但我从未尝试过<代码>:after似乎在元素之后创建了一个类似内联的元素。您可以尝试添加此CSS(不知道是否有效):


你能做到,但我从未尝试过<代码>:after似乎在元素之后创建了一个类似内联的元素。您可以尝试添加此CSS(不知道是否有效):


正如Blender所指出的,有一些类型的dom节点作为内容添加到元素内容的末尾。但是,您还需要提供某种AFAICT内容才能使其正常工作

<ul id="el">
    <li>Hello world</li>
</ul>

#el li {
    background:url(http://www.gravatar.com/avatar/e1122386990776c6c39a08e9f5fe5648?s=128&d=identicon&r=PG) top center no-repeat;
    width: 200px;
    height: 200px;
    overflow: hidden;
}
#el li:after {
    background:url(http://www.gravatar.com/avatar/05a3a91994b86e4e45246b57b0ec3c7d?s=128&d=identicon&r=PG) bottom center;
    content: " ";
    display: block;
    position: relative;
    height: 500px;
    z-index: -100;
}
  • 你好,世界
#伊利{ 背景:url(http://www.gravatar.com/avatar/e1122386990776c6c39a08e9f5fe5648?s=128&d=identicon&r=PG)上中不重复; 宽度:200px; 高度:200px; 溢出:隐藏; } #el li:之后{ 背景:url(http://www.gravatar.com/avatar/05a3a91994b86e4e45246b57b0ec3c7d?s=128&d=identicon&r=PG)底部中心; 内容:“; 显示:块; 位置:相对位置; 高度:500px; z指数:-100; }

正如Blender所指出的,在元素内容的末尾添加了某种类型的dom节点作为内容。但是,您还需要提供某种AFAICT内容才能使其正常工作

<ul id="el">
    <li>Hello world</li>
</ul>

#el li {
    background:url(http://www.gravatar.com/avatar/e1122386990776c6c39a08e9f5fe5648?s=128&d=identicon&r=PG) top center no-repeat;
    width: 200px;
    height: 200px;
    overflow: hidden;
}
#el li:after {
    background:url(http://www.gravatar.com/avatar/05a3a91994b86e4e45246b57b0ec3c7d?s=128&d=identicon&r=PG) bottom center;
    content: " ";
    display: block;
    position: relative;
    height: 500px;
    z-index: -100;
}
  • 你好,世界
#伊利{ 背景:url(http://www.gravatar.com/avatar/e1122386990776c6c39a08e9f5fe5648?s=128&d=identicon&r=PG)上中不重复; 宽度:200px; 高度:200px; 溢出:隐藏; } #el li:之后{ 背景:url(http://www.gravatar.com/avatar/05a3a91994b86e4e45246b57b0ec3c7d?s=128&d=identicon&r=PG)底部中心; 内容:“; 显示:块; 位置:相对位置; 高度:500px; z指数:-100; }

使用CSS3,可以通过

#el li {
   background: url(image1.jpg), url(image2.jpg);
   background-position: top center, bottom center;
   background-repeat: no-repeat;
}

有了CSS3,可以通过

#el li {
   background: url(image1.jpg), url(image2.jpg);
   background-position: top center, bottom center;
   background-repeat: no-repeat;
}

:在
之前和
:在
之后始终需要以下内容:

{
    content: '';
}

:在
之前和
:在
之后始终需要以下内容:

{
    content: '';
}

“:before”和“:after”伪元素可用于在元素内容之前或之后插入生成的内容。“:before”和“:after”伪元素可用于在元素内容之前或之后插入生成的内容。”他在问如何使用伪元素他在问如何使用伪元素谢谢Jared。我没有想到留下内容:“空白”。谢谢,杰瑞德。我没有想到留下内容:“空白”。谢谢=)