JSFiddle - React, Tailwind, and code Playground
by Gregor Adams
HTML
<div class="item">
<div class="item-tester" >
<div class="item-icon"></div>
<div class="item-title">Item Title</div>
</div>
<div id="item_click" onmousedown="new_class(event)" onmouseup="revert_class(event)" onmouseout="revert_class(event)"></div>
</div>
CSS
* {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor:default;
}
body {
background: #012139;
font-family: Helvetica, Arial;
color: #fff;
}
.item {
height: 150px;
width:150px;
overflow:hidden;
position:relative;
margin:20px;
}
#item_click {
height: 150px;
width:150px;
overflow:hidden;
position:absolute;
margin:0;
background:rgba(0,0,0,0);
z-index:3;
}
.item-title {
position:absolute;
bottom:0;
left:0;
width:110px;
height:10px;
padding:10px 20px 10px 20px;
font-size: 12px;
z-index:1;
}
.item-icon {
position:absolute;
margin:50px;
width:50px;
height:50px;
background:#fff;
border-radius:25px;
z-index:1;
}
.item-tester {
position:absolute;
top:0;
left:0;
margin:0;
padding:0;
height:150px;
width:150px;
background: #055080;
z-index:0;
}
.item.added-class div.item-tester {
background:#000;
}
JavaScript
function new_class(event) {
wClick = document.getElementById("item_click");
wTile = wClick.parentNode;
wTile.className = wTile.className + " added-class";
}
function revert_class(event) {
wTile.className = "item";
}