Last active
July 5, 2024 08:54
-
-
Save andxbes/11747ff231fc627e4cbc34b49cbe8929 to your computer and use it in GitHub Desktop.
--scrollbar-width
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
document.addEventListener('DOMContentLoaded', () => { | |
function getScrollBarWidth() { | |
let el = document.createElement("div"); | |
el.style.cssText = "overflow:scroll; visibility:hidden; position:absolute;"; | |
document.body.appendChild(el); | |
let width = el.offsetWidth - el.clientWidth; | |
el.remove(); | |
return width; | |
} | |
document.body.style.setProperty('--scrollbar-width', `${getScrollBarWidth()}px`); | |
}); |
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
body{ | |
--scrollbar-width: 0px; | |
} | |
.full-width{ | |
width: calc(100vw - var(--scrollbar-width) /2); | |
max-width: calc(100vw - var(--scrollbar-width)/2); | |
position: relative; | |
left: 50%; | |
right: 50%; | |
margin-left: -50vw; | |
margin-right: -50vw; | |
box-sizing: border-box; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment