Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Product Prev Card Component Solution (Not Responsive)

h415232 110

@h415232

Desktop design screenshot for the Product preview card component coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


I learned a lot from CSS Flexbox from this exercise. I did have difficulty managing the icon/image placing in the button as the button text tends to wrap, making the button text 2 lines instead of 1 line (as what the exercise wants).

I wanted to ask the community if there is a more efficient way of managing images in buttons as it is very tricky. Any feedback will be helpful for me to learn!

Thanks! :)

Community feedback

@kkhwjnrk

Posted

Wrapping the image inside a container element is unnecessary when adding it to a button. Instead, we can directly add the image inside the button element. Like this:

<button class="btn">
  <img src="./assets/images/icon-cart.svg" alt="">
  Add to cart
</button>

We can use flexbox to align the image and the text inside the button. We can apply the flex properties to the button element like this:

.btn {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  border-radius: 0.5rem;
}

.btn img {
  width: 1rem;
  margin-right: 0.75rem;
}

I hope this helps🙏

Marked as helpful

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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