I'm attempting to design a basic bookshelf using only CSS and HTML. However, I'm finding it challenging to have the book currently being hovered over appear with the highest z-index
.
Is this achievable without JavaScript? Maybe through some clever utilization of CSS selectors?
HTML
<div class="bookshelf">
<div class="book">
<div class="side spine">
1
</div>
<div class="side top">
</div>
<div class="side cover">
Book 1
</div>
</div>
<div class="book">
<div class="side spine">
2
</div>
<div class="side top">
</div>
<div class="side cover">
Book 2
</div>
</div>
<div class="book">
<div class="side spine">
3
</div>
<div class="side top">
</div>
<div class="side cover">
Book 3
</div>
</div>
</div>
CSS
.bookshelf {
width: 100%;
/* height: 800px; */
margin-top: 32px;
border: 1px solid #CCC;
display: flex;
}
.book {
width: 50px;
height: 280px;
position: relative;
transform-style: preserve-3d;
transform: translateZ(0) rotateY(0);
transition: transform 1s;
}
.side {
position: absolute;
border: 2px solid black;
font-weight: bold;
color: black;
text-align: center;
transform-origin: center left;
}
.spine {
width: 50px;
height: 280px;
line-height: 200px;
background-color: yellow;
transform: rotateY(0deg) translateZ(0px);
}
.top {
width: 50px;
height: 190px;
line-height: 200px;
background-color: green;
transform: rotateX(90deg) translateZ(95px) translateY(-95px);
}
.cover {
width: 190px;
height: 280px;
line-height: 200px;
background-color: cyan;
left: 50px;
transform: rotateY(90deg) translateZ(0);
transition: transform 1s;
}
.book:hover {
transform: rotateX(-25deg) rotateY(-40deg) rotateZ(-15deg) translateY(50px) translateX(-30px);
}