Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jamiemarsland/2cc05e0c3146629c2fcc9947acb0cfca to your computer and use it in GitHub Desktop.
Save jamiemarsland/2cc05e0c3146629c2fcc9947acb0cfca to your computer and use it in GitHub Desktop.
Disable Negative Margins Globally on mobile
/* 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;
}
}
@RatzeR
Copy link

RatzeR commented May 14, 2024

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.

@webmandesign
Copy link

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