Getting :before pseudo element to use background image of parent

我是研究僧i 提交于 2019-12-02 04:06:40

问题


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;
}

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!


回答1:


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

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?



来源:https://stackoverflow.com/questions/7305487/getting-before-pseudo-element-to-use-background-image-of-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!