Difference between revisions of "CS49"

From Coder Merlin
m (Editorial review and minor corrections)
 
Line 2: Line 2:


=== Introduction ===
=== Introduction ===
In order to organize the different elements in a web page, websites often follow a specific layout. Many of them utilize the CSS Grid Layout which uses rows and columns to make it easier for designing. In this lesson, you are going to learn how to use this property so you can create a basic layout for your website!  
To organize the different elements in a web page, websites often follow a specific layout. Many of them use the CSS Grid Layout, which uses rows and columns to make it easier for designing. In this lesson, you will learn how to use this property so you can create a basic layout for your website!  


=== The Basics ===
=== The Basics ===
A grid layout consists of a parent element, with one or more child elements. To display a grid you will use this syntax:
A grid layout consists of a parent element, with one or more child elements. To display a grid, use this syntax:
<syntaxhighlight>
<syntaxhighlight>
.grid-container {
.grid-container {
Line 12: Line 12:
</syntaxhighlight>
</syntaxhighlight>


To add a grid-item you will use this syntax:
To add a grid item, use this syntax:
<syntaxhighlight>
<syntaxhighlight>
<div class="grid-container">
<div class="grid-container">
Line 20: Line 20:
</syntaxhighlight>
</syntaxhighlight>


Grid items have vertical lines called columns, horizontal lines called rows, and spaces between each column and row called gaps. To adjust the gap size for these properties, you can use any of these code segments:
Grid items have vertical lines called ''columns'', horizontal lines called ''rows'', and spaces between each column and row called ''gaps''. To adjust the gap size for these properties, use any of these code segments:


===== column-gap: =====
===== column-gap: =====

Latest revision as of 19:59, 8 February 2023

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

CSS Grid[edit]

Introduction[edit]

To organize the different elements in a web page, websites often follow a specific layout. Many of them use the CSS Grid Layout, which uses rows and columns to make it easier for designing. In this lesson, you will learn how to use this property so you can create a basic layout for your website!

The Basics[edit]

A grid layout consists of a parent element, with one or more child elements. To display a grid, use this syntax:

.grid-container {
  display: grid;
}

To add a grid item, use this syntax:

<div class="grid-container">
  <div class="grid-item">1</div>
  <div class="grid-item">2</div>
</div>

Grid items have vertical lines called columns, horizontal lines called rows, and spaces between each column and row called gaps. To adjust the gap size for these properties, use any of these code segments:

column-gap:[edit]
.grid-container {
  display: grid;
  column-gap: 50px;
}
row-gap:[edit]
.grid-container {
  display: grid;
  row-gap: 50px;
}
gap:[edit]

The gap property is a shorthand property for the row-gap and the column-gap properties.

.grid-container {
  display: grid;
  gap: 50px 100px;
}

Conclusion[edit]

Believe it or not, this is just the beginning of CSS Grid Layout!