问题
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