Css p标记前后的背景图像

Css p标记前后的背景图像,css,background-image,Css,Background Image,我找到了解决堆栈溢出问题的潜在方法,但它似乎对我不起作用。我想要一个图像出现在p.choke之前和之后,所以在顶部和底部。我正在使用以下CSS: p.choke:before{ content:" "; background-image:url(...); background-position:center top; } p.choke:after{ content:" "; background-image:url(...); backgro

我找到了解决堆栈溢出问题的潜在方法,但它似乎对我不起作用。我想要一个图像出现在p.choke之前和之后,所以在顶部和底部。我正在使用以下CSS:

p.choke:before{
    content:" ";
    background-image:url(...);
    background-position:center top;
}

p.choke:after{
    content:" ";
    background-image:url(...);
    background-position:center bottom;
}

p.choke{
    background-image:url(...);
    background-repeat:no-repeat;
    background-position:center top;
    width:75%;
    line-height:2em;
    text-align:center;
    margin:0 auto;
    color:#009245;
    padding:1em 0;
}
图片应该出现在我的段落标签的顶部和底部,对吗?我读到其他人也有同样的问题,这就是他们使用的语法。为什么我的图像只出现在顶部

而不是:

p.choke:after{
    content:" ";
    background-image:url(...);
    background-position:center bottom;
}
我曾经

p.choke:after{
    content:url(...);
    background-position:center bottom;
}

现在好像在工作。仍然不确定为什么另一种方法不起作用。

您试图将这种影响应用于该页面中的哪些元素?我认为您需要为伪元素设置宽度和高度,以便让html知道图像的大小