Pseudo CSS Before After

Mengaplikasikan pseudo CSS before after kedalam sebuah elemen

by Miftah Faroq

HTML

<h1 class="intro">Pseudo CSS Before After Tutorial</h1>

	<div class="container">
		<div class="card">
			<img src="https://picsum.photos/400/400" alt="" class="card__img">
			<div class="card__text">
				<h3 class="card__title">Card Title</h3>
				<p class="card__body">And here is some text</p>
			</div>
		</div>
		<div class="card">
			<img src="https://picsum.photos/399/400" alt="" class="card__img">
			<div class="card__text">
				<h3 class="card__title">Card Title</h3>
				<p class="card__body">And here is some text</p>
			</div>
		</div>
	</div>

CSS

@import url('https://fonts.googleapis.com/css?family=Oswald');

*, *::before, *::after {
	box-sizing: border-box;
}


body{
    font-family: 'Oswald', sans-serif;
    font-size: 1rem;
    line-height: 1.4;
    color: grey;
    text-align: center;
}

h1, h2, h3, h4, h5{
	text-transform: uppercase;
	line-height: .9;
	color: #c31;
}

.container{
	width: 80%;
	margin: 0 auto;
	display: flex;
	justify-content: center;
}

.intro{
	position: relative;
	display: inline-block;
}

.intro::before{
	content: '';
	height: 101%;
	display: block;
	position: absolute;
	background: white;
	z-index: -1;
	left: -20px;
	right: -20px;
}


.intro::after{
	content: '';
	height: 100%;
	display: block;
	position: absolute;
	background: red;
	width: 100vw;
	left: 50%;
	top: 0;
	transform: translateX(-50%);
	z-index: -2;
}

.card{
	position: relative;
	margin: 1em;
	background: grey;
}

.card::before{
	content: '';
	position: absolute;
	top: 1.25em;
	bottom: 1.25em;
	left: 1.25em;
	right: 1.25em;
	transition: transform ease-out 250ms;
	transform: scale(0, 1);
	border-top: 1px solid white;
	border-bottom: 1px solid white;
}

.card::after{
	content: '';
	position: absolute;
	top: 1.25em;
	bottom: 1.25em;
	left: 1.25em;
	right: 1.25em;
	transition: transform ease-out 250ms;
	transform: scale(1, 0);
	border-left: 1px solid white;
	border-right: 1px solid white;
}

.card:hover::after{
	transform: scale(1, 1.05);
}

.card:hover::before{
	transform: scale(1.05, 1);
}


.card__img{
	max-width: 100%;
	display: block;
	transition: opacity ease-out 250ms;
	opacity: 1;
}

.card:hover .card__img{
	opacity: .4;
}

.card__text{
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: white;
	opacity: 0;
	transition: opacity ease-out 250ms;
}

.card:hover .card__text{
	opacity: 1;
}

.card__title{
	font-size: 2rem;
	color: white;
	margin-bottom: 0;
}

h2{
	margin-top: 1.2em;
	margin-bottom: 0;
}

p{
	margin-top: .25em;
}