Daglig Shaarli
November 7, 2024
Jamie Marsland demonstrates how to use Negative Margins.
- Negative margins in WordPress Gutenberg allow overlapping content blocks, enabling creative layouts.
- Understanding the CSS Box Model (content, padding, and margin) is crucial for effectively using negative margins.
- Negative margins can be applied to specific sides of a block (top, right, bottom, left) by adjusting the margin settings.
- By combining negative margins with column blocks, impressive overlapping layouts can be created quickly.
He also recommends to disable negative margins on mobile (globally) with some CSS
/*
-ckn-: Remove negative margins on mobile - by courtesy of Jamie Marsland
*/
@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 }
}
However, be aware that if you make this globally, there's no option to make local variation to margins on mobile !