Design comparison
Solution retrospective
Hello,
I have completed another project. I had fun working on this and learned a lot about CSS opacity property.
I have a question about the background image not displaying when you hover over the image tag. What is preventing the background image from showing?
Any suggestion on how to improve this or my code will be appreciated. Thank you.
Community feedback
- @polzakPosted over 1 year ago
Hi Paul,
You've done a great job. I see you did a beautiful design.
Just one thing, please let me tell you how you can make theicon-view.jpg
image that you set as background image visible.First, the image file path:
You can access image files with
./images/....jpg
inindex.html
, but yourstyle.css
file is not in the root directory now. The stylesheet's path is./app/scss/style.css
; so you will be able to access image files from there, with./../../images/icon-view.jpg
: you need to come up twice, then come down into the images folder again.Second, the tag you applied 'opacity: 0.3' to.
You set the background image on the
img
tag, and applied theopacity
(transparent) to the sameimg
tag: it will not work because theimg
tag has both its own image and background image at once. Solution: move the class.image-equilibrium
up to its parentdiv
inindex.html
. Then create a style.image-equilibrium:hover img
, and moveopacity: 0.3
into that. Now when you hover thediv
tag(its dimension will be the same asimg
tag), theopacity: 0.3
will work just on the image, and the background image on thediv
tag will show up.You can see my code:
(index.html)
<main class="card"> <div class="image_equilibrium"> <img src="./images/image-equilibrium.jpg" alt="picture of equilibrium card"> </div> <h1>Equilibrium #3429</h1>
(style.css)
.image_equilibrium:hover { background-image: url("./../../images/icon-view.svg"); background-repeat: no-repeat; background-position: center center; cursor: pointer; /* move the opacity out into the below one */ } .image_equilibrium:hover img { opacity: 0.3; }
Marked as helpful0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord