Computer Science 318


Fundamentals of Web Design

New Lab 14


Goal

Learn

body{
    display:grid;
}

display:grid;

Defines the element as a grid container and establishes a new grid formatting context for its contents. Display Grid is a layout system available in CSS. Unlike Display Flex which only allows control for either rows or columns, Display Grid allows the user to control both rows and columns.

body{
     display:grid;
     grid-template-columns: 40px 15% auto 10rem;
     grid-template-rows:25% 100px auto;
}

grid-template-rows

Defines the rows of the grid with a space-separated list of values. The values represent the track size, and the space between them represents the grid line.

grid-template-columns

Defines the columns of the grid with a space-separated list of values. The values represent the track size, and the space between them represents the grid line.

Values: can be a length, a percentage, or a fraction of the free space in the grid (using the fr unit).

Below is a representation of the display grid properties and values from the code above. The white outline is the edge of the <body> and the white vertical and horizontal lines represent the start and end of each column or row. The green values shown along the bottom and right are the numbers assigned to each horizontal and vertical line that create the grid. These numbers can be referenced with grid-item properties to move and stretch the elements within different cells in the grid.

Display Grid Visual Layout

gap

body{
     display:grid;
     grid-template-columns: 40px 15% auto 10rem;
     grid-template-rows:25% 100px auto;
     gap: 1rem;
}

Defines the gaps (gutters) between rows and columns.

Grid-Item Properties

By default any elements that are direct descendants of the grid container will be assigned a grid cell. The will be ordered from left to right, wrapping to a new row as needed. The placement of individual elements can be changed with the following properties:

.item1{
    grid-column-start:1;
    grid-column-end:4;
    grid-row-start:1;
    grid-row-end:3;
}

Hint: When using the grid-item properties to move elements around there is not a unit assigned.

The properties above define a grid item's location within the grid by referring to specific grid lines (the green numbers in the image above). So if the <body> had a four <div> each with a class such as item-1, item-2, etc... We could use grid-row-start, grid-column-start, grid-row-end, and grid-column-end to move the elements into grid cells they were initially assigned to or multiple cells. Like below:

Display grid - grid-area long hand

.item4{
     grid-column:1/4;
     grid-row:3/4;
}

The code above is a shorter version of the grid-item properties above. When using grid-row and grid-column the grid line values are separated by a slash. The values also go in this order: start/end.

Display grid - grid-area med hand

.item-2{
    grid-area: 1/4/3/5;
}

The code above is the shortest version of the grid-items properties. The values for grid-area are: row-start/column-start/row-end/column-end.

Display Grid - grid-area short hand

Practice

Experiment Try moving the items around the grid using the image above as a guide. Use grid-area, grid-column, grid-row, grid-row-start, grid-column-start, grid-row-end, or grid-column-end to move the items.

HTML

<div class="item-1">Item 1</div> <div class="item-2">Item 2</div> <div class="item-3">Item 3</div> <div class="item-4">Item 4</div>

CSS

.item-1{ background-color:aqua; } .item-2{ background-color:red; } .item-3{ background-color:yellow; } .item-4{ background-color:blue; } body{ display:grid; grid-template-columns: 40px 15% auto 10rem; grid-template-rows:25% 100px auto; color:white; background-color:black; }

Preview

Complete Grid Garden

With your cs-318 repository selected, Click open in Visual Studio code.

Create a new folder called lab14

Create a new files called index.html, ankh-morpork.html, characters.html, author.html, and books.html in the lab14 folder

Setup your HTML files

Create your stylesheet

Link your stylesheet to the HTML

Change Document in the <title> element to "Discworld"

Index.html

Add a header, main, and footer

In the header add

In the footer add two divs

In the first div add the same links as the nav plus one for the home page.

HTML links in blue on the Discworld index page

In the second div add a p with the following text : Postal Address:Discworld Emporium, Guild House, Station Road, Wincanton, Somerset BA9 9FE Call us: 07940 286605 Email: shop@discworldemporium.com

Use the break tag to separate the lines of text within the paragraph

Add anchors around the phone number and email. Use mailto: and tel: in the href to setup the link.

Paragraph using breaks and anchors

We are going to use the hover pseudo class to make a dropdown in the navigation. To do this the HTML must be set up so there is a container around the link with the dropdown box inside as well. That way the are grouped together.

Around the link for characters add a div with the class "dropdown"

Inside the div after the anchor add another div. Inside this div we will add all of our jump links for the characters page.

Add the following anchors for the jump links

Around the link for books add a div with the class "dropdown"

Inside the div after the anchor add another div. Inside this div we will add all of our jump links for the books page.

Add the following anchors for the jump links

In the links find "Faust" add a <s> tag around the word. This will create a strike through.

Lab 14 Discworld homepage will all nav links

Copy everything on the index file and paste it on to all the other html files.

Index.html

In the main add two sections

Section1

Add a class of hero

In the section add

Section 2

Add class of home-about

Add two divs

div 1

div 2 add the following paragraphs

Lab 14 Home page content

Characters.html

On the main add class characters

In the main add four sections

Section 1

Add a hgroup tag. In the hgroup tag add

Hint: There will be many images it may behoove you to have subfolders inside the images folder for each page.

Lab 14 section one on characters page

Section 2

Add hgroup

Add five <figure> tags. Inside each one add a image tag and a <figcaption> tag.

Lab 14 Character setup city watch

Section 3

add hgroup

Add four <figure> with a image tag and <figcaption> tag inside each.

Section 4

hgroup

Add seven <figure> with a image tag and <figcaption> tag inside each.