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 preview card component using HTML and CSS

@Lalithanjali-16

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 have downloaded the starter for 3 times and all the 3 times the cart icon is not displayed while opening so that's the reason cart icon is not displayed in my project

Community feedback

@Dhruv-mak

Posted

Hey there!

It seems like the webpage you mentioned was designed specifically for large screens like PCs and laptops, but it's not responsive and breaks down when viewed on mobile screens. To address this issue, two essential concepts come into play: the <picture> tag and media queries.

The <picture> tag is an HTML element used to provide multiple versions of an image based on different conditions, such as screen size, resolution, or device capabilities. It allows you to specify different image sources and let the browser choose the most suitable one. This tag is particularly useful for responsive design, as it enables you to deliver different images for different screen sizes.

On the other hand, media queries are a fundamental part of CSS that allows you to apply specific styles to different devices or screen sizes. By using media queries, you can define different CSS rules for various breakpoints, ensuring that your webpage adapts and displays properly across different devices and screen sizes.

To make the webpage responsive, you'll need to consider a few steps:

  1. Start by incorporating media queries into your CSS. Media queries enable you to define different styles for different screen sizes. You can specify breakpoints at which the styles will change. For example:
/* Styles for large screens */
@media screen and (min-width: 1024px) {
/* CSS rules for large screens go here */
}

/* Styles for medium screens */
@media screen and (max-width: 1023px) and (min-width: 768px) {
/* CSS rules for medium screens go here */
}

/* Styles for small screens */
@media screen and (max-width: 767px) {
/* CSS rules for small screens go here */
}
  1. Within your media queries, you can adjust the layout, font sizes, image sizes, or any other element to ensure they fit and look good on different screen sizes.

  2. To handle images, you can use the <picture> tag along with media queries. Within the <picture> element, you can specify different image sources using the <source> tag, each targeting specific screen sizes. The browser will select the appropriate image based on the conditions you set. For example:

<picture>
<source media="(min-width: 768px)" srcset="large-image.jpg">
<source media="(min-width: 480px)" srcset="medium-image.jpg">
<img src="small-image.jpg" alt="Fallback Image">
</picture>

In this example, "large-image.jpg" will be displayed on screens wider than 768 pixels, "medium-image.jpg" on screens wider than 480 pixels but narrower than 768 pixels, and "small-image.jpg" will be used as a fallback for screens smaller than 480 pixels.

By combining media queries with the <picture> tag and adjusting the layout and styles accordingly, you can create a responsive webpage that works well across various devices and screen sizes.

0

@Khawarmehfooz

Posted

Hi there👋,

I noticed that you're experiencing an issue with the cart icon not being displayed in your project. Upon inspecting your HTML code, I noticed that the icon is placed outside the button element.

To resolve this, I suggest placing the icon inside the button element. You can achieve this by using either an <a> tag or a button to wrap both the icon and the "Add to Cart" text. Here's an example of how you can modify your code:

<button type="submit" class="main-btn"> <img src="icon-cart.svg" class="img" alt=""> Add to Cart </button>

By doing this, the cart icon will be included within the button, and it should be displayed correctly when you open the project.

Please give this a try and let me know if you need any further assistance.

0

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