Created
March 19, 2025 07:21
-
-
Save kidGodzilla/c6183bfd7f63e014e4bf83fefd35ca7a to your computer and use it in GitHub Desktop.
Flexbox center a div (wrong answers only)
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
<script> | |
class FlexCenter extends HTMLElement { | |
constructor() { | |
super(); | |
const shadow = this.attachShadow({ mode: 'open' }); | |
const wrapper = document.createElement('div'); | |
wrapper.classList.add('center'); | |
const slot = document.createElement('slot'); | |
wrapper.appendChild(slot); | |
const style = document.createElement('style'); | |
style.textContent = ` | |
.center { | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
height: 100%; | |
width: 100%; | |
} | |
`; | |
shadow.appendChild(style); | |
shadow.appendChild(wrapper); | |
} | |
} | |
customElements.define('flex-center', FlexCenter); | |
</script> | |
<flex-center style="height: 100vh;"> | |
<div>Centered Content</div> | |
</flex-center> |
Author
kidGodzilla
commented
Mar 19, 2025

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment