Skip to main content
  1. All Posts/

Ecommerce-product-page-solution

eCommerce CSS

Frontend Mentor – E-commerce product page solution

This is a solution to the E-commerce product page challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

The challenge

Users should be able to:

  • View the optimal layout for the site depending on their device’s screen size
  • See hover states for all interactive elements on the page
  • Open a lightbox gallery by clicking on the large product image
  • Switch the large product image by clicking on the small thumbnail images
  • Add items to the cart
  • View the cart and remove items from it

Screenshot

Note: More screenshots in the design folder

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox
  • Mobile-first workflow
  • JavaScript

What I learned

  • Changing the color of an SVG image on hover was quite a challenge for me. After a peruse of some articles (links below) that challenge became somewhat of an inspiration. I discovered that the combination of CSS filter properties does the trick. Some examples:
.delete:hover {
    filter: brightness(0);
}/*Makes the image completely dark (bold) on hover */

.close {
  filter: brightness(90); 
}/* Turn Black (original) to White color */

.close:hover {
  filter: invert(55%) sepia(100%) saturate(3.5) brightness(110%);
} /* To Orange on hover */

.arr:hover img {
  filter: invert(55%) sepia(100%) saturate(3.5);
} /* Orange on hover */

.thumb:hover {
  filter: opacity(1) drop-shadow(0 0 0 #fff) saturate(0.2) brightness(150%);
} /* Make thumbnail opaque/white */
/* The dropshadow is used to change the image's color to white */
/* Combinations & Value types, degree or percentage: */

.user-acc .cart:hover {
  filter: invert(27%) saturate(2878%) hue-rotate(346deg) brightness(104%) contrast(97%);

  filter: invert(200%) saturate(5000%) hue-rotate(360deg) brightness(6%) contrast(50%); 

  filter: brightness(60%);
}
  • I also learned that the :hover pseudo-class needs a pointing (graphical input) device, capable of distinguishing the actions pointing and selecting/activating. Usually on mobile devices with a touch interface you don’t have the former, only the latter. That said, :hover has a weird behaviour on mobile devices and is problematic on touchscreens. A workaround for this is:
@media (hover: hover) and (pointer: fine) {
 button:hover {
   ...
   /* True for pointing devices, not touchscreens */
 }
}

Continued development

I am currently learning React, a JavaScript library. Building this project made me realize how quickly JavaScript can become messy and all over the place. And how React is great for complex projects like this one – for building reuseable components.

Useful resources

These are amazing articles which helped me finally understand CSS filter and changing the color of svg images. And also :hover behaviour on touchscreens. I’d recommend it to anyone still learning this concept.

Author