Pet Food Shop Website Using Html CSS and JavaScript
Introduction
Hello coders, welcome to another new blog. Today in this article we’ll build a kitter pet shop which is Frontend project made up of HTML, CSS and JavaScript. This project is about a pet food store where you can get all the essential pet food for your loved one pet animals.
To create this pet food store we’ve used HTML, CSS and JavaScript. Using these three core frontend technologies we’ve build our Pet food store. HTML sets up the basic structure of our website while the CSS adds interactive styling to our webpage and makes our UI better and visually appealing. JavaScript adds functionality to our webpage for smaller screens.
If you guys also want to create this type of project then all you need is the knowledge of HTML, CSS and JavaScript. If you’ve good command in these techs then you’re good to go. Usually this type of interactive project enhances our coding and UI skills which are important to industry point of view. Let’s dive into our code.
HTML (index.html)
Get Discount on Top Educational Courses
Brand Name
Discount Information
Coupon Codes Link
Educative.io
20% discount on Educative courses and plans
W3Schools
20% discount on W3Schools courses
KodeKloud
10% discount on KodeKloud courses and plans
GeeksforGeeks
30% discount on GeeksforGeeks courses
Target Test Prep
20% discount on Target Test Prep
Coding Ninjas
₹5000 discount on Coding Ninjas courses
Skillshare
40% discount on Skillshare
DataCamp
50% discount on DataCamp
365 Data Science
57% discount on 365 Data Science Plans
Get Smarter
Flat 20% discount on Get Smarter courses
SmartKeeda
Flat 40% discount on SmartKeeda courses
StackSocial
20% discount on StackSocial courses
This is our HTML code which sets up the basic structure of our website. In other words we can say that it builds a skeleton of our website. Let’s breakdown the code.
<! DOCTYPE html> : This defines the type of our document and ensures that our file a HTML code file.
<title> : It sets the title of our portfolio page.
<link> : This tag links external CSS file and all the other links required for our project like favicon etc.
<body> : This contains all the content of the page.
<header> : Header contains all the content on the head part of the project. It contains logo, navbar and other essential buttons. Header contains some div tags in which all the content of logo, navbar and cta buttons are wrapped. It contains different tags and attributes according to the section.
<section class=”hero”> : This section contains a background image, heading, text and a button. This is what the hero section contains.
<section class=”category”> : Category section contains a container div in which all the content is wrapped. This section contains some heading and then for each product it contains a image and descriptive name.
<section class=”offer”> : This section contains all the latest deals and offers on the store. A main container div contains all the content on the section including a image, text and read more button.
<section class=”product”> : It starts with a heading on the top of the section. For each product there is div with the class product card. Each div with this class contains two images, add to cart button and some outline icon. One image will show the front part of product and other will show other part on hover.
<section class=”services”> : Services section contains all the pet services provided by the store. It contains a image on top of it then some heading and then four card with the services and description.
<section class=”cta”> : CTA section contains a bg image as well as some heading, text and button to setup the entire section.
<section class=”brand”> : Brand section contains one heading at top of the section and then some cards wrapped in div to display all the brand affiliated to the store.
<footer> : footer contains all the quick links along with address and contact info of the store so that user can easily contact and locate the store.
There is a button called scroll to top which will work after adding functionality.
<script> : This tag links all the script files to the HTML page.
This is our CSS code which styles our HTML elements. This code adds interactive styling to our webpage. It enhances user experience and keep engaging the user to our website. Let’s breakdown the code.
Code starts by defining root elements for each general styling of the page like colors, font, shadow, transition etc.
Pseudo selectors are used to reset and margin padding.
All the general basic styling are applied to the root tags of HTML which will applied to all the elements of the page.
The header sits at the top of the page and remains fixed even when you scroll down. It contains a menu that’s fantastic on the phone as well, with a tiny button to open and close it to your convenience.
The hero section displays a headline, some text, and a button in the center. On large screens, it divides into two halves — text on one half, image on the other. The button also slightly alters when you hover over it.
Category cards show different categories of products along with nice pictures. When hovering over a card, the image is zoomed in and the color of the title changes to provide it with a fresh look. The structure fits itself evenly to all sizes of screens.
The offers section displays some special offers in a grid format. Each offer card contains a small title, a big bold headline, and a button. If you hover over a card with your mouse, the background color changes to highlight it. The layout also adjusts depending on the size of your screen.
The product section displays all the products in a neat manner. Each product contains an image that changes on hover, star ratings, prices, and an “Add to Cart” button that responds when clicked. The products are stacked differently on mobile and large screens so everything appears neat.
The services page shows what the business or store provides. Every service includes an icon, a heading, and a brief description. On large screens, the services are shown in 3 or 4 columns so that it will be neat and readable.
Call to action (CTA) portion has a foreground image with bold headline. The portion has an element that ever so slightly elevates when you hover your cursor over it. On bigger displays, the area divides into two sides — word on one and image on another.
The brand section displays logos of various brands horizontally in a row. On smaller devices, you scroll. On larger ones, they’re just placed side by side neatly without scrolling.
Dark bottom footer is divided into sections — quick links, contact details, social media icons, and a sign-up form. All are created in white and gray, and the icons turn colorful on hover.
The back-to-top button is a tiny button which appears when scrolled down. It will smoothly move you to the top of the page when you press it. It’s disguised if you already are at the top.
Media queries are applied throughout to ensure the site is pretty on every screen size – mobile, tablet, laptop, or desktop. It scales font sizes, layouts, margins, and even hides or displays some things based on the device.
This is our JavaScript code which adds functionality to our webpage. The JavaScript is usually used to adds interactive functionality to our webpages. Let’s understand the code.
Code starts with the use strict mode which helps to catch mistakes.
Next, we’ve added some event on the elements. It’s stored in variable and function contains some parameters and using those parameter type or callback event are handled in this function.
Navbar toggle section code is used to toggle or appear navbar on smaller screen on click event. First of all we access all the essential elements from the HTML, then created a function for the active and close navbar.
When the click event runs the navbar appears and add classlist and when navtoggler clicked the classlist will be removed and the navbar will disappear.
Same happens when we click on the navlinks, the navbar will be closed.
Then we accessed the header and back to top button from the HTML document.
Then we creates a function, where if user scrolls down to the 100px then the header will appear and some CSS classes will be added to it. Otherwise the default class will be applicable to header.
And lastly this function is called with the scroll event.
This was all about our code.
'use strict';
/**
* add event on element
*/
const addEventOnElem = function (elem, type, callback) {
if (elem.length > 1) {
for (let i = 0; i 100) {
header.classList.add("active");
backTopBtn.classList.add("active");
} else {
header.classList.remove("active");
backTopBtn.classList.remove("active");
}
}
addEventOnElem(window, "scroll", activeElemOnScroll);
Output:
Disclaimer: The code provided in this post is sourced from GitHub and is distributed under the MIT License. All credits for the original code go to the respective owner. We have shared this code for educational purposes only. Please refer to the original repository for detailed information and any additional usage rights or restrictions.