While positioning the images inside the <div> tag, the image is not behaving according to the sizing of <div> tag. How can I solve that?
Larra
@larrasuAll comments
- @surabhilsskSubmitted over 1 year ago@larrasuPosted over 1 year ago
You can improve the look of the card by adding more padding to the contents of the card. It's a little bit compact compared to the original design. Overall, the card component looks great!
To answer your question, you can do so by doing this:
img { width: 100%; height: 250px; //specify image height object-fit: cover; // this keeps the image's aspect ratio and fills the given sizes }
I hope this helps. Happy coding! ✨
Marked as helpful1 - @aaronli722Submitted almost 2 years ago
After the project, I have two questions:
-
How to vertically center a span element?
-
Is it possible to set the height of a div same as the background image? (which mean can fully show the background image with correct scale)
@larrasuPosted almost 2 years agoHello! Your solution looks excellent overall!
A few things you might want to add are the rounded corners of the card component and add
overflow: hidden
so the image molds into the rounded corners.To answer your questions:
- You can vertically center a
span
element by adding Flexbox to the parent element like this:
display: flex; items-align: center;
- Yes, it is possible to set the height of the
div
the same as the background image by addingbackground-size: cover
to yourdiv
. If you are using animg
element, you can also do it by addingobject-fit: cover
to yourimg
element.
I hope this helps! Happy coding ✨
0 -