Cards
Insight Card
19 Sep 2022
Insight card with responsive preview
HTML
SCSS
PostCSS
JS
<a href="#" class="insight-card">
<div class="photo">
<img src="./assets/images/test.jpg" alt=""/>
</div>
<div class="top-info">
<div class="date">00/00/0000</div>
</div>
<h5>Lorem ipsum dolor sit amet, consectetur adipiscing elit</h5>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet aspernatur
beatae culpa dolor ducimus eos iusto laborum minima numquam, optio pariatur,
qui quo reprehenderit repudiandae sequi veniam vitae? Delectus, labore.
</p>
<button type="button" class="btn"> Read More</button>
</a>
/* Card */
.insight-card {
display: flex;
flex-direction: column;
max-width: 400px;
.photo {
@include aspect-ratio(16, 9, 250px);
border-radius: 20px;
margin-bottom: 20px;
img {
@include transition-all;
}
}
.top-info {
display: flex;
align-items: center;
justify-content: space-between;
}
.date {
font-family: var(--font-main);
font-size: ac(14px, 11px);
color: var(--primary);
margin-left: auto;
margin-bottom: 10px;
}
h5 {
@include max-line-length(2);
}
p {
@include max-line-length(5);
margin-bottom: 20px;
}
&:hover {
.photo img {
transform: scale(1.12);
}
}
}
.btn {
min-width: ac(140px, 110px);
width: fit-content;
height: ac(50px, 38px);
display: flex;
align-items: center;
justify-content: center;
padding: 5px 10px;
background: var(--secondary);
border-radius: 10px;
margin-bottom: 15px;
cursor: pointer;
@include transition-all;
&:hover {
color: var(--black);
background: var(--primary);
}
}
/* Mixins */
@define-mixin aspect-ratio $width, $height, $maxHeight: 9999px, $minHeight: 0px {
position: relative;
overflow: hidden;
/* fix for hover scale on image on Safari 15.1 */
mask-image: radial-gradient(white, black);
&::before {
content: "";
display: block;
padding-bottom: max(min(perc($height, $width), $maxHeight), $minHeight);
}
img {
width: 100%;
height: 100%;
position: absolute;
object-fit: cover;
top: 0;
left: 0;
}
}
@define-mixin transition-all $time: 0.25s {
transition: ease-in-out $time;
}
@define-mixin max-line-length $number {
padding: 0 !important;
display: -webkit-box;
-webkit-line-clamp: $number;
-webkit-box-orient: vertical;
overflow: hidden;
}
/* Card */
.insight-card {
display: flex;
flex-direction: column;
max-width: 400px;
.photo {
@mixin aspect-ratio 16, 9, 250px;
border-radius: 20px;
margin-bottom: 20px;
img {
@mixin transition-all;
}
}
.top-info {
display: flex;
align-items: center;
justify-content: space-between;
}
.date {
font-family: var(--font-main);
font-size: ac(14px, 11px);
color: var(--primary);
margin-left: auto;
margin-bottom: 10px;
}
h5 {
@mixin max-line-length 2;
}
p {
@mixin max-line-length 5;
margin-bottom: 20px;
}
&:hover {
.photo img {
transform: scale(1.12);
}
}
}
.btn {
min-width: ac(140px, 110px);
width: fit-content;
height: ac(50px, 38px);
display: flex;
align-items: center;
justify-content: center;
padding: 5px 10px;
background: var(--secondary);
border-radius: 10px;
margin-bottom: 15px;
cursor: pointer;
@mixin transition-all;
&:hover {
color: var(--black);
background: var(--primary);
}
}
// Functions for pcss
const maxWidth = 1440;
const minWidth = 768;
export function ac( startSize, endSize, minBreakpoint = minWidth, maxBreakpoint = maxWidth) {
const startSizeFormatted = startSize.replace("px", "");
const endSizeFormatted = endSize.replace("px", "");
const difference = startSizeFormatted - endSizeFormatted;
if (difference > 0) {
return `min(max(calc(${endSize} + ${difference} * ((100vw - ${minBreakpoint}px) / ${maxBreakpoint - minBreakpoint})),${endSize}),${startSize})`;
} else {
return `min(max(calc(${endSize} + ${difference} * ((100vw - ${minBreakpoint}px) / ${maxBreakpoint - minBreakpoint})),${startSize}),${endSize})`;
}
}
export const perc = (number1, number2 = maxWidth) => `${(number1 * 100) / number2}%`;