Fullwidth website with sidebar
Description
Buckle up! We have a website with page content of a specific max-width, but we are also displaying sidebar…
Honestly, I'm not really sure how should I define and approach a "full-width alignment" with this website layout. Seeing the Cover Image block examples below will tell you much more than my words.
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), special media queries (additional information below), and complicated calculations especially with boxed website layout.
Our full-width alignment wrapper (the .align-wrap
) helps us quite a bit with this layout case.
Fullwidth Cover Image
with fixed background
CSS code prerequisites
Change these values in the code to your needs.
min-width: 900px
- there is no sidebar layout below this breakpoint
.62
- in website layout with sidebar this is calculated as 100 / Primary_Content_Width_% (if your content and sidebar width is set in percent; usually, "primary" stands for the actual page content area and "secondary" stands for sidebar)
CSS code
.alignfull { width: 100vw; max-width: 100vw; margin-left: calc(50% - 50vw); } @media screen and (min-width: 900px) { .alignfull { width: auto; margin-left: calc(50% / .62 - 50vw); } }
Wasn't that bad, was it? :)
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 prerequisites
Change these values in the code to your needs.
min-width: 900px
- there is no sidebar layout below this breakpoint
.62
- in website layout with sidebar this is calculated as 100 / Primary_Content_Width_% (if your content and sidebar width is set in percent; usually, "primary" stands for the actual page content area and "secondary" stands for sidebar)
CSS code
.align-wrap { width: 100vw; margin-left: calc(50% - 50vw); } @media screen and (min-width: 900px) { .align-wrap { width: auto; margin-left: calc(50% / .62 - 50vw); } } .align-wrap .alignfull { width: 100%; margin: 0 0 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.
We have more flexibility with the block width now.