Created
May 14, 2024 04:53
-
-
Save jamiemarsland/2cc05e0c3146629c2fcc9947acb0cfca to your computer and use it in GitHub Desktop.
Disable Negative Margins Globally on mobile
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
/* CSS to reset any negative margins on mobile devices */ | |
@media (max-width: 768px) { | |
* { | |
margin-top: 0 !important; | |
margin-right: 0 !important; | |
margin-bottom: 0 !important; | |
margin-left: 0 !important; | |
} | |
} |
I agree, the code is quite "dangerous" to use as it messes up all margins on mobile devices. I suggest maybe updating the code to something like this:
@media (max-width: 768px) {
[style*="margin-top:-"] { margin-top: 0 !important }
[style*="margin-right:-"] { margin-right: 0 !important }
[style*="margin-bottom:-"] { margin-bottom: 0 !important }
[style*="margin-left:-"] { margin-left: 0 !important }
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is not only resetting negative margins, it is also resetting positiv margins.
So if you are not using block-spacing in you theme, this can completely mess up your theme.