JSFiddle - React, Tailwind, and code Playground

by jakirseu

HTML

<div id="shirtImage">
    <h4 id="buyNowButton">Buy Now!</h4>    https://jsfiddle.net/f5L7b53r/#embed
</div>

CSS

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/*
This method uses css transitions to slide the hidden button into view, there is another below using opacities.
*/

/*
#shirtImage {
    background: rgba(230,230,230,1);
    width: 200px;
    height: 200px;
    position: relative;
    overflow: hidden;
}

#buyNowButton {
    cursor: pointer;
    background: rgba(190,190,190,1);
    color: rgba(50,50,50,1);
    border: 1px solid red;
    width: 200px;
    height: 200px;
    text-align: center;
    line-height: 100px;
    position: absolute;
   
    transition: bottom 0.2s;
}

#shirtImage:hover > #buyNowButton {
    bottom: 0;
    transition: bottom 0.5s;
}
*/

/*
The below uses opacities.
*/

#shirtImage {
    background: rgba(230,230,230,1);
    width: 200px;
    height: 200px;
    position: relative;
    overflow: hidden;
}

#buyNowButton {
    cursor: pointer;
    background: rgba(190,190,190,0);
    color: rgba(50,50,50,0);
    border: 1px solid red;
    width: 100%;
    height: 100%;
    text-align: center;
    line-height: 50px;
    position: absolute;
    bottom: 0px;
    transition: background 0.2s;
    display:none;
}

#shirtImage:hover > #buyNowButton {
    background: rgba(190,190,190,1);
    color: rgba(50,50,50,1);
    transition: background 0.5s;
        display: block;
}

JavaScript

shirtImage = document.getElementById('shirtImage');
buyNowButton = document.getElementById('buyNowButton');

buyNowButton.addEventListener("click", function() {
    alert("Hello!");
});