Design comparison
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
- @kkhwjnrkPosted over 1 year ago
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 helpful1
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