Created
March 8, 2022 04:37
-
-
Save ImBIOS/cbd444c2312bf9293f585042e1b1d5a7 to your computer and use it in GitHub Desktop.
Simple way to center a text over an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<style> | |
.container { | |
position: relative; | |
text-align: center; | |
color: white; | |
} | |
.centered { | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<img | |
src="https://images.unsplash.com/photo-1483728642387-6c3bdd6c93e5?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxfDB8MXxyYW5kb218MHx8ZGFyayxsYW5kc2NhcGV8fHx8fHwxNjQ2NDg1ODcw&ixlib=rb-1.2.1&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=1080" | |
alt="Cool Mountains" | |
style="width: 100%" | |
/> | |
<div class="centered">Cool and Centered</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment