<header>
        <div class="container">
            <a href="#" class="logo">CompanyLogo</a>
            <a href="#" class="bag">
                <i class="fas fa-shopping-bag"></i>
<!--                 <span class="quantity">0</span> -->
            </a>
        </div>
    </header>
    <div class="cart">
        <a href="#" class="closecart"><i class="fas fa-times"></i></a>
        <div id="minicart">                      
            <table id="lista-carrito" class="u-full-width">
                <thead>
                    <tr>
                        <th>Imagen</th>
                        <th>Nombre</th>
                        <th>Precio</th>
                        <th>Cantidad</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <a href="#" id="vaciar-carrito" class="button u-full-width">
                Clean Cart <i class="far fa-trash-alt"></i>
            </a>
        </div>
    </div>
    <div class="cards container">
        <h1>EXPLORE THE COLLECTION</h1>
        <div class="card">
            <img src="https://picsum.photos/200" alt="">
            <p class="title">Nike Air Max Plus</p>
            <p class="description">Men's Shoes</p>
            <p class="price">$180</p>
            <a href="#" class="button" data-id="1">Add to Card</a>
        </div>

        <div class="card">
            <img src="https://picsum.photos/200" alt="">
            <p class="title">Nike Quest Premium</p>
            <p class="description">Women's Road Running Shoes</p>
            <p class="price">$150</p>
            <a href="#" class="button" data-id="2">Add to Card</a>
        </div>

        <div class="card">
            <img src="https://picsum.photos/200" alt="">
            <p class="title">Nike Air Max 270</p>
            <p class="description">Men's Shoes</p>
            <p class="price">$160</p>
            <a href="#" class="button" data-id="3">Add to Card</a>
        </div>

    </div>
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@200;300;400;700;900&display=swap');

body {
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 18px;
    color: #585858;
}
.container {
    max-width: 1200px;
    margin: auto;
    padding: 0 20px;
}
@media(max-width:1024px) { 
    .container {
        max-width: 100%;
    }
    header .container {
        max-width: 90%;
    }
}
header {
    border-bottom: 1px solid rgb(243, 243, 243);
}
header .container{
    display: flex;
    justify-content:space-between;
    padding: 15px 0;
}
a {
    text-decoration: none;
    color: inherit;
}
p {
     margin: 0.5rem;
}
.logo {
    text-transform: uppercase;
    color: #000;
    font-size: 22px;
    font-weight: bold;
    line-height: 2rem;
}
.bag {
    font-size: 28px;
    position: relative;
}
.bag span {
    display: block;
    background: #E20000;
    color: #fff;
    width: 1.3rem;
    height: 1.3rem;
    text-align: center;
    border-radius: 100%;
    line-height: 1.3rem;
    font-size: 0.8rem;
    font-weight: bold;
    position: absolute;
    right: -12px;
    top: 19px;
}
@media(min-width:800px) {
    .cards {
        display: flex;
        justify-content: space-around;
        padding: 3rem 0 0 0;
    }
    .card {
        width: 34%;
    }
}

.card {
    border: solid #ccc 1px;
    border-radius: 20px;
    overflow: hidden;
    line-height: 1.5rem;
    padding-bottom: 20px;
    margin: 0 10px;
}
.card img {
    width: 100%;
}
.card .title {
    font-weight: 900;
    font-size: 26px;
}
.card .price {
    font-size:4rem;
    font-weight: 100;
    text-align: right;
    line-height: 2rem;
    margin-top: 2rem;
    margin-bottom: 3rem;
}
.button {
    border-radius: 50px;
    display: block;
    background: #000;
    color: #fff;
    text-transform: uppercase;
    text-align: center;
    height: 3rem;
    width: 90%;
    line-height: 3rem;
    margin: auto;
    transition: all .3s ease;
}
.button:hover {
    background: #2c2c2c;
}
.cart {
    width: 30%;
    height: 100%;
    position: fixed;
    top: 0;
    right: -100%;
    background: #fff;
    box-shadow: 0px 0px 5px #d4d4d4;
    font-size: 16px;
    transition: all .5s ease;
}
.activo {
    right: 0;
}
.cart #minicart {
    padding: 1.3rem;
}
.cart #minicart .button {
    margin-top: 2rem;
}
.cart table {
    border-collapse: collapse;
}
.cart th, .cart td {
    padding: 10px;
    text-align: left;
}
.closecart {
    font-size: 2rem;
    position: absolute;
    right: 10px;
}
.deletebtn {
    display: block;
    background: #E20000;
    color: #fff;
    width: 1.5rem;
    height: 1.5rem;
    text-align: center;
    border-radius: 100%;
    line-height: 1.5rem;
    font-size: 0.8rem;
    font-weight: bold;
}
//Menu right
const bag =  document.querySelector('header .bag');
const cart =  document.querySelector('.cart');
const closecartBtn = document.querySelector('.closecart');
const contenedorCarrito =  document.querySelector('#lista-carrito tbody');
const carrito = document.querySelector('#minicart');
const vaciarCarritoBtn =  document.querySelector('#vaciar-carrito');

//Body
const courseList = document.querySelector('.cards');
let articulosCarrito = [];
let total = 0;

loadEventListeners()
function loadEventListeners(){
    //Menu right cart
    bag.addEventListener('click', openCart);

    //Close Cart button
    closecartBtn.addEventListener('click', closecart)

    //Agregar curso presionando addToCart
    courseList.addEventListener('click', addCourse);

    //Eliminar articulo
    carrito.addEventListener('click', eliminarCurso);

    //Vaciar carrito
    vaciarCarritoBtn.addEventListener('click', ()=>{
        articulosCarrito = []; // reseteamos carrito
        limpiarHTML()
    })
}

//Open cart
function openCart(e){
    e.preventDefault();
    cart.classList.add('activo')
}
//Close Cart
function closecart(e) {
    e.preventDefault();
    cart.classList.remove('activo')
}

//Btn add course
function addCourse(e) {
    e.preventDefault();
    if (e.target.classList.contains('button')) {
        const cursoSelected = e.target.parentElement;
        datosCurso(cursoSelected)
    }
}

//Delete product
function eliminarCurso(e){
    if(e.target.classList.contains('deletebtn')) {
        const cursoID = e.target.getAttribute('data-id');
        articulosCarrito = articulosCarrito.filter( curso => curso.id !== cursoID);

        carritoHTML();
    }
}

//Read course data
function datosCurso(curso){

    //Create Object
    const infoCurso = {
        image: curso.querySelector('img').src,
        title: curso.querySelector('.title').textContent,
        price: curso.querySelector('.price').textContent,
        id: curso.querySelector('a').getAttribute('data-id'),
        cantidad: 1
    }

    //Revisa si un elemento existe
    const existe = articulosCarrito.some( curso => curso.id === infoCurso.id);
    if(existe){
        //Actualizar el carrito
        let cursos = articulosCarrito.map(curso =>{
            if(curso.id === infoCurso.id){
                curso.cantidad++;
                return curso;
            }else {
                return curso;
            }
        });
        articulosCarrito = [...cursos];
    }else{
        //Agrega elementos al array carrito
        articulosCarrito = [...articulosCarrito, infoCurso];
    }
    //console.log(articulosCarrito);
    carritoHTML();
}


//Muestra carrito en el HTML
function carritoHTML() {    
    //Limpiar HTML
    limpiarHTML();
    articulosCarrito.forEach( curso =>{
        
        const row = document.createElement('tr');
        row.innerHTML = `
            <td><img src="${curso.image}" width="100"></td>
            <td>${curso.title}</td>
            <td>${curso.price}</td>
            <td>${curso.cantidad}</td>
            <td><a href="#" class="deletebtn" data-id="${curso.id}">X</a></td>
        `;
        //Agregar en el Tbody
        contenedorCarrito.appendChild(row);

        //Total
        total = curso.cantidad + curso.cantidad
        console.log(total);
    })
    
}

function limpiarHTML(){
    // contenedorCarrito.innerHTML = '';

    while(contenedorCarrito.firstChild){
        contenedorCarrito.removeChild(contenedorCarrito.firstChild)
    }
}

External CSS

  1. https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css

External JavaScript

This Pen doesn't use any external JavaScript resources.