获取:before伪元素使用父级的背景图像 [英] Getting :before pseudo element to use background image of parent

查看:792
本文介绍了获取:before伪元素使用父级的背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用CSS来设置a:before伪元素的背景图像与其父元素相同。我想说继承,但是一个伪元素可以继承什么吗?示例:

Can CSS be used to set the background image of a :before pseudo element to the same as it's parent. I want to say inherit, but can a pseudo element inherit anything? Example:

li a {
    background: #f56a46 url(images/gallery-thumb.jpg) center center no-repeat;
}

li a:before {
    background: inherit;
}



我知道我可以很容易地使用JavaScript,但我想知道可能只使用CSS。任何帮助将非常感谢,谢谢!

I know I could easily do it with JavaScript but I want to know if it's possible using only CSS. Any help would be much appreciated, Thanks!

推荐答案

for pseudo-elements: http://jsfiddle.net/kizu/GaUsp/

确定您已添加所有需要的属性,例如 content display 和尺寸,所以伪元素有一个框,必须显示背景?

Are sure, you've added all the needed properties like content, display and dimensions so the pseudo-element have a box where background must be shown?

这篇关于获取:before伪元素使用父级的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆