Utente:Valerio Bozzolan/CSS grid layout

Esempio di un layout a griglia visualizzato su tre dispositivi.

Una griglia, nella progettazione di una interfaccia utente ed in particolare nel web design, è una pratica che descrive come poter disporre i contenuti in righe e colonne sfruttando lo spazio a disposizione, con comportamenti di ri-dimensionamento prevedibili, flessibili, per ottenere un design responsivo.[1][2][3]

Storia modifica

La definizione formale del concetto di griglia nasce essenzialmente per poter creare facilmente uno o più layout prevedibili e adattivi in funzione dello spazio grafico a disposizione. Per questo motivo, fin dalla prima bozza del World Wide Web Consortium nel 2011 in materia, la griglia si contrappone all'utilizzo di una tabella più tradizionale:[4]

(EN)

«Come le tabelle, la griglia permette ad un autore di allineare elementi in colonne e righe, ma a differenza delle tabelle, la griglia non ha una struttura dei contenuti, e quindi permette una grande varietà di layout non possibili con le tabelle.»

(IT)

«Like tables, the Grid enables an author to align elements into columns and rows, but unlike tables, the Grid doesn't have content structure, and thus enables a wide variety of layouts not possible with tables.»

Con questo tipo di layout,, una pagina può Sebbene esistano innumerevoli implementazioni, ciò che accomuna 11 marzo 2021[5]

[6][7] }}[5] | authors = | base_standards = CSS | related_standards = | abbreviation = Grid, grid layout | domain = CSS | license = | website = w3.org, https://www.w3.org/TR/css-grid-1/. }}

Nel CSS, la struttura CSS a griglia [8]

In Cascading Style Sheets, CSS grid layout or CSS grid creates complex responsive web design grid layouts more easily and consistently across browsers.[9] Historically, there have been other methods for controlling web page layout methods, such as tables, floats, and more recently, CSS Flexible Box Layout (Flexbox). CSS grid is currently not an official standard (it is a W3C Candidate Recommendation) although it has been adopted by the recent versions of all current major browsers.[10]

Motivation modifica

CSS grid can create more robust and flexible layouts than the previous options like CSS floats. It also allows for more standardized code that works across browsers. This is in contrast to relying on specific browser hacks or complicated workarounds.[11]

One issue with exploiting floats in CSS is that if content gets added to one portion of the page it could disrupt the flow of the page and break the layout. This is due to the varying heights for layout elements.[11] Though CSS flex box supports flexible layouts and provides the flexibility of creating complex layouts, it fails when the need for creating responsive layouts in 2-dimensional space arises.

History modifica

The first comprehensive draft of a grid layout for CSS was created by Phil Cupp at Microsoft in 2011 and implemented in Internet Explorer 10 behind a -ms- vendor prefix. The syntax was restructured and further refined through several interations in the CSS Working Group, led primarily by Elika Etemad and Tab Atkins Jr. The feature was widely adopted by web developers after evangelism led primarily by Rachel Andrew and Jen Simmons.[12]

Browser support modifica

As of October 2017, Chrome, Firefox, Safari and Edge all support CSS grid without vendor prefixes.[13][14][15] IE 10 and 11 support CSS grid but with an outdated specification. On mobile, all modern browsers support CSS grid except for Opera Mini and brave Browser. Web developers targeting older browsers can utilize Modernizr 3.5.0 to detect and gracefully degrade the webpage as needed.[16]

Utilization in frameworks modifica

Tailwind CSS incorporates CSS grid into its utilities for controlling how elements are sized and placed.[17] However many other current web frameworks do not incorporate CSS grid, such as Bootstrap 4 and Foundation 6.[18]

the fr unit modifica

The "fr" unit is often used with CSS grid layout.[19][20][21] The "fr" unit, part of the CSS grid layout specification, represents a fraction of the leftover space in the grid container.[11]

Examples modifica

"Holy grail" layout modifica

The following is an example of the "holy grail" layout:

HTML Output
<html>
<style>
div { border: 1px solid; }
body {
    display: grid;
    grid-template-columns: 10em auto 10em;
    grid-template-areas: 
        "header header header"
        "left   middle right"
        "footer footer footer";
}
</style>
<body>
    <div style="grid-area: header">The header</div>
    <div style="grid-area: footer">The footer</div>
    <div style="grid-area: left">The left panel</div>
    <div style="grid-area: middle; height: 200px">The main content area</div>
    <div style="grid-area: right">The right panel</div>
</body>
</html>
 

Table of values modifica

The following is an example of a table of values:

HTML Output
<html>
<style>
.wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-gap: 0.5em;
}
div { 
    border: 1px solid; 
}
</style>
<body>
    <div class="wrapper">
        <h3>Header1</h3><h3>Header2</h3><h3>Header3</h3>
        <div>value11</div><div>value12</div><div>value13</div>
        <div>value21</div><div>value22</div><div>value23</div>
        <div>value31</div><div>value32</div><div>value33</div>
        <div>value41</div><div>value42</div><div>value43</div>
        <div>value51</div><div>value52</div><div>value53</div>
        <div>value61</div><div>value62</div><div>value63</div>
        <div>value71</div><div>value72</div><div>value73</div>
    </div>
</body>
</html>
 

References modifica

  1. ^ (EN) Can I use CSS grid?, su caniuse.com. URL consultato il 17 marzo 2022.
  2. ^ (EN) Grid Layout, su w3.org, 7 aprile 2011. URL consultato il 17 marzo 2022.
    «Grid Layout contains features targeted at web application authors. The Grid can be used to achieve many different layouts. It excels at dividing up space for major regions of an application, or defining the relationship in terms of size, position, and layer between parts of a control built from HTML primitives.»
  3. ^ (EN) CSS Grid Layuot, su developer.mozilla.org.
    «CSS Grid Layout excels at dividing a page into major regions or defining the relationship in terms of size, position, and layer, between parts of a control built from HTML primitives.»
  4. ^ (EN) Grid Layout, su w3.org, 7 aprile 2011. URL consultato il 17 marzo 2022.
  5. ^ a b CSS Grid Layout Module Level 2, su drafts.csswg.org, CSS Working Group, 11 marzo 2021.
  6. ^ Grid Layout, su w3.org, CSS Working Group, 7 aprile 2011.
  7. ^ CSS Grid Positioning Module Level 3, su w3.org, CSS Working Group, 5 settembre 2007.
  8. ^ CSS Grid Layout Module Level 1 Publication History - W3C, su w3.org, n.d..
  9. ^ CSS Grid – Table layout is back. Be there and be square., su developers.google.com, January 2017.
  10. ^ CSS Grid Layout (level 1) | Can I use... Support tables for HTML5, CSS3, etc, su caniuse.com.
  11. ^ a b c Errore nelle note: Errore nell'uso del marcatore <ref>: non è stato indicato alcun testo per il marcatore w3c-latest
  12. ^ (EN) Aaron Gustafson, The Story of CSS Grid, from Its Creators, su alistapart.com, 19 ottobre 2017.
  13. ^ Microsoft's newest browser gets a significant boost with EdgeHTML 16, 13 September 2017.
  14. ^ Chrome 57 arrives with CSS Grid Layout and API improvements | VentureBeat, in VentureBeat, 9 March 2017.
  15. ^ CSS Grid Layout, su caniuse.com, n.d..
  16. ^ Modernizr 3.5.0, 13 aprile 2017.
  17. ^ Grid Column Start / End - Tailwind CSS, su tailwindcss.com.
  18. ^ Flexbox grids and frameworks, su gist.github.com, 16 febbraio 2017.
  19. ^ Alligator.io, CSS Grid Layout: The Fr Unit, su digitalocean.com, DigitalOcean, 3 settembre 2020.
  20. ^ Fractional. — Ethan Marcotte, su ethanmarcotte.com, 18 luglio 2018.
  21. ^ An Introduction to the 'fr' CSS unit, su css-tricks.com, 12 giugno 2017.

External links modifica

Template:W3C Standards