繁体   English   中英

CSS中多个:before或:after伪元素

[英]Multiple :before or :after pseudo-elements in css

让我们说我有一个div,它保存通知消息,例如

<div class="notification"></div>

该消息是通过PHP动态生成的,例如

<div class="notification><?php echo $notif;?></div>

但是我想让那个div说它持有如下通知

Notification: [notification message]

所以我把CSS:

.notification:before{
    content:'Notification: ';
}

问题是我可以只为该div放置另一个内容吗? 例如,我希望在“ 通知”之前显示警告图片

因此可以在前面加上另一个

.notification:before{
     content:url(warning.png);
}

如果我喜欢那最后一个。 那我该怎么展示两个呢?

您可以将图像设置为:before的背景,如下所示:

.notification:before {
    content: 'Notification: ';
    padding-left: 20px;
    background: url('warning.png') left center no-repeat;
}

JSFIDDLE演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM