Hello readers we are back with an other interesting article based on the topic HTML and Javascript. Hope all are doing well and safe. Explore all the contents in our blog and please support us.

HTML,CSS and Javascript are main languages to design a web page as we all know. They are like siblings. HTML and CSS take care about the structure, design and styles while Javascript is like heart for writing the web page. It takes care of the operations to be performed on various events like button clicks, on hover,on double tap and many other events.

In this article we are gonna discuss about creating a basic and very simple shopping card.

What information will the shopping card contain?
  • contains name of the product.
  • Colors if any are present.
  • The available sizes. 
  • Add to cart button.
  • Buy now button.

HTML:

Inside the "card" class the name of the product using h2 tag with styling yellow color. First in the HTML insert only one image of any one color. The height and width are adjusted according to the convenience.

The form is created using the <form> tag and in the 'action' attribute a link to the page must be given where the details must be submitted.

 In the next part for selecting the size option radio buttons are created. Note : For the radio buttons "name" attribute must be same so that only one option can be selected if different names are given multiple options are selected.

Next part is creating the buttons for different colors using <input> tag with type as "button" .For each button the color is set to the name of the color in the button.

Next comes the "add to cart" and "buy now" button . 'Add to cart' is created through anchor tag and the 'Buy now' button is created through <input> tag with type "submit" so that the details will be submitted the page specified in 'action' attribute in the form tag.

CSS:

The body-background is set to black and the position of the card is set to the center using 'place-items'.

For the image the width and height are set according the convenience.For the class 'card' the width is set to 350px and the height to 555px. This may be edited according to the convenience. Many attributes like 'box-shadow' ,border', 'border-radius' are specified. 

The shopping cart is used in the 'Add to cart' button using 'fa' class with background set to brown and padding set to 10px.

For the 'input type=submit' button also the style is added similar to the add to cart button.

Javascript:

In the HTML while creating the buttons which have the name of the colors, each button is specified with a seperate functions to the 'onclick' attribute. Each function is to change the colors to the color given inside the function. In the HTML part the <img> tag is given an id 'colors'. This tag is retreived in the Javascript using 'document.getElementById('colors')'. Using this each function will change the 'src' of the <img> tag to the image containing T-shirt of the respective color  given inside the function.

Source codes:


HTML:

 

CSS:

 

Javascript:



Post a Comment

Previous Post Next Post