Design comparison
Solution retrospective
I struggled with the hero-image overlay. I would love some tips on best practice for this. I initially used an ::after element and transform:translate to position it correctly. This however wouldn't allow me to have lower opacity on the background colour and full opacity on the image.
I tried a few over ways..created a div and image with 0 opacity and had a hover state of 0.5 for the overlay colour and opacity of 1 for the image but this still didn't work. I left it after doing a-lot of research and will ask for some tips
Community feedback
- @vanzasetiaPosted over 2 years ago
Hi there! 👋
Regarding the overlay, here are some changes that I made on my devtool.
.overlay:hover { /* opacity: 0.4; */ opacity: 1; } .overlay { position: relative; height: 100%; width: 100%; opacity: 0; transition: .5s ease; /* background-color: var(--cyan); */ background-color: hsla(178, 100%, 50%, 0.5); transform: translate(0, -100%); border-radius: 0.5em; }
So, I used
hsla()
to control the opacity of the color itself. This way, the eye icon can have full opacity. 😉Anyway, there are some areas that you can improve and fix.
- Currently, the card is so narrow at
376px
width until1400px
. It is because the cardwidth
is set withvw
unit. Also, on mobile landscape view the card almost has noheight
. So, I recommend only setting amax-width
on the card element withrem
unit. The card only needs amax-width
to prevent it from becoming too large on wide screen sizes. For the height of it, remove theheight
property and let the element inside the card controls it. - All the elements that have interactivity need to be wrapped by interactive elements like anchor tag.
- All the icons are decorative images. So, I recommend leaving the
alt=""
empty. - For the avatar, it is a pretty important image. So, I suggest using the author's name as the alternative text of the image.
- I don't think
defer
can be used onlink
tag (?).
That's it! Hope this helps. 😊
1@MarioLisbonaPosted over 2 years ago@vanzasetia Hey Vanza. Thanks so much for this! That is such an elegant solution, i had thought to use hsla(). It was the first time id encountered need to put an overlay over an image.
I also changed the card width to
rem
units andmax-width
. This seemed to work however as soon as i removed the height, it also removed the overlay colour and changed the position of the eye image. So i had to leave the height in./* I tried to remove the height and let the elements inside the card dictate its height This worked but it remove the hover overlay and moved the position of the image */ max-width: 18rem; height: 30rem;```
0@vanzasetiaPosted over 2 years ago@MarioLisbona You're welcome! 👍
I took a look at the updated solution. I notice the card is having some problems.
- First, I still recommend removing the
height
and the flex properties. Usemargin
orpadding
to create white space between the elements instead of usingjustify-content
. - So, add
margin
orpadding
to each element inside the card (e.g.h1
, etc). - The
overlay
should be set toposition: absolute
. Then set thehero-image-container
toposition: relative
instead. This way, theoverlay
would always be inside the parent element.
For the card image, I recommend:
- Wrap the image with
a
tag. It has interactivity so it needs to be wrapped by an interactive element. - The
:hover
effect should be on thea
tag instead of the.overlay
element. - Make the card overlay with 100% pure CSS. Use pseudo-elements and
background
properties instead. Make the cyan color asbackground-color
and the eye icon asbackground-image
. Then, you can put the eye icon in the center by usingbackground-position
property.
Also, I notice two complex media queries where they have multiple conditions. I am not sure why you need those media queries. But, I would recommend keeping the media queries as simple as possible.
0 - Currently, the card is so narrow at
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