Creating full-width elements within a limited-width container, such as a centered text column, requires clever CSS techniques. One common approach uses relative left positioning and a negative left margin based on the viewport width. While this method has limitations (e.g., needing hidden overflow on the body and a centered container), it's relatively simple and doesn't interfere with other container elements.
Alternative methods using CSS Grid have been widely discussed:
- Tyler's "Breaking Out with CSS Grid Layout" and Rachel's response.
- Rachel's "Editorial Design Patterns With CSS Grid And Named Columns."
- Selen Gora's "Setting the box in container to full width with CSS Grid."
- Bryan Robinson's "Use CSS Subgrid to layout full-width content stripes in an article template."
These methods share a common assumption: an edge-to-edge grid spanning the entire page. This raises the question: Is using body { display: grid; }
for the entire page layout a practical approach? While some developers do this, it presents potential challenges.
Several drawbacks exist:
- Headers and footers, typically full-width elements, require explicit placement and spanning within the grid, adding complexity compared to using simple block-level elements. A more flexible approach might involve a central edge-to-edge grid with block-level headers and footers.
- Positioning all elements within a central column (e.g.,
article > * { grid-columns: 2 / 3; }
) to selectively expand some items feels cumbersome. For predominantly centered content, a parent element managing layout offers a simpler, more robust solution than individually positioning each element on the grid.
While not inherently flawed, the edge-to-edge grid approach can feel less intuitive and potentially more complex for many layouts. This observation might stem from a preference for simpler, more modular approaches.
It's crucial to avoid applying display: grid;
directly to the element. Browser extensions injecting elements into the body can disrupt the grid layout. A better practice is to use a child
<div> to contain the grid, mirroring the React best practice of avoiding direct body manipulation for improved scoping and maintainability.</div>
The above is the detailed content of Full-Width Elements By Using Edge-to-Edge Grid. For more information, please follow other related articles on the PHP Chinese website!

In a perfect world, our projects would have unlimited resources and time. Our teams would begin coding with well thought out and highly refined UX designs.

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons

SVG has its own set of elements, attributes and properties to the extent that inline SVG code can get long and complex. By leveraging CSS and some of the forthcoming features of the SVG 2 specification, we can reduce that code for cleaner markup.

You might not know this, but JavaScript has stealthily accumulated quite a number of observers in recent times, and Intersection Observer is a part of that

We may not need to throw out all CSS animations. Remember, it’s prefers-reduced-motion, not prefers-no-motion.

PWA (Progressive Web Apps) have been with us for some time now. Yet, each time I try explaining it to clients, the same question pops up: "Will my users be

It's extremely surprising to me that HTML has never had any way to include other HTML files within it. Nor does there seem to be anything on the horizon that

There are a lot of different ways to use SVG. Depending on which way, the tactic for recoloring that SVG in different states or conditions — :hover,


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software