<a class="post-card" href="#">
<div class="thumb">
<img src="https://i.picsum.photos/id/1000/5626/3635.jpg?hmac=qWh065Fr_M8Oa3sNsdDL8ngWXv2Jb-EE49ZIn6c0P-g">
<!-- Condition - exists file -->
<div class="alt-text">Image not found :/</div>
</div>
<div class="content">
<div class="title">Post card in CSS</div>
<div class="description">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam lectus justo, vulputate eget mollis sed, tempor sed magna. Lorem ipsum dolor sit amet.
</div>
<div class="extended-information">1. 1. 2021 | 2 minutes reading</div>
</div>
</a>
@import url("https://fonts.googleapis.com/css2?family=Exo+2&display=swap");
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-family: "Exo 2", sans-serif;
background-color: #1e1f26;
}
.post-card {
position: relative;
overflow: hidden;
width: 100%;
max-width: 350px;
margin: 1rem;
border: 1px solid #ebebeb;
color: #151515;
cursor: pointer;
border-radius: 15px;
background-color: #ffffff;
transition: all 0.12s ease-in-out;
text-decoration: none;
.thumb {
position: relative;
height: 0;
padding-bottom: 55%;
background-color: #e9e9e9;
.alt-text {
position: absolute;
top: 50%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
text-transform: uppercase;
font-size: 2rem;
color: #bfbfbf;
z-index: 1;
}
img {
object-fit: cover;
object-position: center center;
position: absolute;
width: 100%;
height: 100%;
z-index: 2;
}
}
.content {
padding: 1rem;
.title {
padding-top: 5px;
padding-bottom: 5px;
font-size: 1.6rem;
margin: 0;
}
.description {
padding-top: 5px;
padding-bottom: 5px;
height: 100px;
overflow: hidden;
line-height: 1.5;
font-size: 1rem;
}
.extended-information {
padding-top: 0.4rem;
padding-bottom: 0.4rem;
color: #7a7a7a;
font-size: 0.8rem;
}
}
&:hover {
transform: translateY(-5px);
box-shadow: 0 5px 35px rgba(0, 0, 0, 0.35);
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.