Created
March 21, 2022 11:08
-
-
Save lagenceoueb/4381cf61b8fd2dcb751f736eb41e82ad to your computer and use it in GitHub Desktop.
center a child <div> wider than the parent (thx to https://www.w3docs.com/snippets/css/how-to-make-a-child-div-element-wider-than-the-parent-div.html)
This file contains hidden or 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> | |
<title>My centered div wider than the parent div</title> | |
<style> | |
* { | |
box-sizing: border-box; | |
} | |
.parent { | |
max-width: 400px; | |
margin: 0 auto; | |
position: relative; | |
background-color: #ecbd33; | |
} | |
.child { | |
width: 100vw; | |
position: relative; | |
left: calc(-50vw + 50%); | |
height: 100px; | |
background-color: green; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="parent"> | |
<div class="child"></div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment