Full-width website with content container: Centered content layout
Description
This is probably the most used styling approach in WordPress themes without a sidebar. The page content is actually encapsulated in a container with a specific max-width.
To style our full-width Gutenberg alignment class we need to "break free" from the content container, which is again pretty easy to achieve.
Disadvantage of this approach could be a possible horizontal scrollbar displayed in web browsers on Windows operating system (check the "About" page for how to resolve) and styles not really working for pages with sidebar.
For our additional full-width alignment wrapper (the .align-wrap
below) we need to apply slightly more code. Again, no real need to use the wrapper with this layout case.
Fullwidth Cover Image
with fixed background
CSS code
.alignfull { width: 100vw; max-width: 100vw; margin-left: calc(50% - 50vw); }
What if we used additional wrapper?
This CSS code is valid only when we use an additional wrapper around .alignfull
blocks.
Wrapped in .align-wrap
:
Fullwidth Cover Image
with fixed background
CSS code
.align-wrap { width: 100vw; margin-left: calc(50% - 50vw); } .align-wrap .alignfull { width: 100%; max-width: 100%; margin: 0 auto; }
You should use either this or the previous non-wrapper CSS code, depending on whether there is a wrapper div. Do not use both of them. If you want to introduce a wrapper div on your website front-end now (with Gutenberg 3.6.2), I've created a useful function for you.
Number of lines of code compared to non-wrapper CSS: +4.
Additional wrapper div is not particularly useful with this website layout.