I want to add some shine to an element on webpage. I would prefer if I don’t have to add additional html to the page. I want the image to appear in front of the element rather than behind. What’s the best way to do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To achieve a "foreground image" (without extra HTML code), you can use a pseudo-element (
::before/:before) plus the CSSpointer-events. The last property is needed so that the user can actually click through the layer "as if it did not exist".Here’s an example (using a colour whose alpha channel is 50% so that you can see that the real elements can actually be focused). http://jsfiddle.net/JxNdT/
PS. I picked the
::beforepseudo-element, because that naturally leads to the correct positioning. If I pick::after, then I have to addposition:relative;to the real element (#cont), andtop:0;left:0;to the pseudo-element (::after).PPS. To get the foreground effect on elements without a fixed size, an additional element is needed. This wrapper element requires the
position:relative;display:inline-block;styles. Set thewidthandheightof the pseudo-element to100%, and the pseudo-element will stretch to the width and height of the wrapper element. Demo: http://jsfiddle.net/JxNdT/1/.