Difference between revisions of "CS49"

From Coder Merlin
Line 1: Line 1:
= HTML Class Attribute =
== CSS Grid ==


=== 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!


Remember all the CSS you learned in the previous lesson? Now imagine this: every time you write an HTML tag, you have to write the CSS for that tag all over again. Wouldn't writing the same CSS over and over again become annoying? Well, the "class" attribute is here to save the day!
=== 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:
<syntaxhighlight>
.grid-container {
  display: grid;
}
</syntaxhighlight>


=== Formatting the class attribute ===
To add a grid-item you will use this syntax:
<syntaxhighlight>
<div class="grid-container">
  <div class="grid-item">1</div>
  <div class="grid-item">2</div>
</div>
</syntaxhighlight>


The tag .class is often used to assign specific formatting styles (font, color, size, etc.) to multiple elements under that class.
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:


=== Example: ===
===== column-gap: =====
<syntaxhighlight>
.grid-container {
  display: grid;
  column-gap: 50px;
}
</syntaxhighlight>


  .city {
===== row-gap: =====
  background-color: tomato;
  color: white;
  margin: 20px;
  padding: 20px;
  }
 
In the above example, the class is named "city" and has specific formatting styles attached to it. To apply the class to multiple elements, you would use this syntax:
 
=== Example: ===
<syntaxhighlight>
<syntaxhighlight>
   <div class="city">
.grid-container {
    <p>London</p>
   display: grid;
   </div>
   row-gap: 50px;
 
}
    <p>Paris</p>
</syntaxhighlight>


  <div class="city">
===== gap: =====
    <p>Tokyo</p>
The gap property is a shorthand property for the row-gap and the column-gap properties.
  </div>
</syntaxhighlight>
As you can see, the tag:
<syntaxhighlight>
<syntaxhighlight>
   <div class="city">
.grid-container {
   display: grid;
  gap: 50px 100px;
}
</syntaxhighlight>
</syntaxhighlight>


will apply the formatting styles defined under the class ".city" to the heading tags that say London and Tokyo. This would make "London" and "Tokyo" have a background color of tomato and give the text a white color.
=== Conclusion ===
 
=== Purpose ===
 
The HTML class attribute can make code more efficient and prevent writing the same styles over and over again.

Revision as of 18:20, 25 January 2023

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

CSS Grid[edit]

Introduction[edit]

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!

The Basics[edit]

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

.grid-container {
  display: grid;
}

To add a grid-item you will 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, you can 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]