<div class="example-container">
	<h2>Show overlay on hover</h2>
	<div class="example1"></div>
</div>

<div class="example-container">
	<h2>Increased legibility</h2>
	<div class="example2">
		Oh no, I'm a white text on a sky background, no one would be able to read me if it wasn't for this cool overlay
	</div>
</div>

<div class="example-container">
	<h2>Gradient overlay</h2>
	<div class="example3">
		Fancy Text
	</div>
</div>
.example1 {
	position: relative;
	width: 200px;
	height: 200px;
	border: solid 4px #4b4b4b;
	border-radius: 4px;
	&::before {
		content: '🐧';
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		display: none;
		font-size: 64px;
		background: rgba(0,0,0,.5);
	}
	&:hover {
		&:before {
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
}

.example2 {
	position: relative;
	background-image: url('https://i.imgur.com/QXvGf9f.png');
	width: 200px;
	height: 200px;
	border: solid 4px #4b4b4b;
	border-radius: 4px;
	color: white;
	padding: 10px;
	z-index: 10;
	&::before {
		content: '';
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		display: none;
		font-size: 64px;
		background: rgba(0,0,0,.2);
		z-index: -1;
	}
	&:hover {
		&:before {
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
}

.example3 {
	position: relative;
	width: 200px;
	height: 200px;
	border: solid 4px #4b4b4b;
	border-radius: 4px;
	display: flex;
	align-items: flex-end;
	padding: 10px;
	font-family: cursive;
	font-size: 32px;
	color: white;
	&::before {
		content: '';
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		display: block;
		font-size: 64px;
		background: linear-gradient(0deg, rgba(120,120,120,1) 0%, rgba(0,0,0,0) 70%);
		z-index: -1;
	}
}

/* Exemple page styles */

* {
	box-sizing: border-box;
}

h2 {
	font-family: sans-serif;
	font-size: 28px;
	margin-bottom: 20px;
}

.example-container {
	margin-bottom: 100px;
}

body {
	padding: 50px;
	color: #4b4b4b;
}
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.