• Tidak ada hasil yang ditemukan

Full-stack Programming: RWD – CSS Grid

N/A
N/A
Khairul Huda

Academic year: 2023

Membagikan "Full-stack Programming: RWD – CSS Grid"

Copied!
45
0
0

Teks penuh

(1)

Program Studi Teknik Informatika

Fakultas Teknik – Universitas Surabaya

RWD – CSS Grid

Week 13

1604C051 – Full-stack Programming

Jimmy

Source: https://www.w3schools.com/css/css_grid.asp

(2)

Introduction to Grid

01

(3)

Grid Layout

• The CSS Grid Layout Module offers a grid-based layout system, with rows and columns.

• It allows designing a web page layout without having to use floats and positioning.

(4)

Grid Layout Sample

• Note that “grid-container” is simply a class name (feel free to change it as needed).

• Related CSS scripts will be discussed in the following slides

(5)

Display: grid vs. inline-grid

Display: grid means the grid container will consumes the whole screen (viewport) width.

Display: inline-grid means the grid container will consumes a portion of the screen

depending on its content and also other items’

content

(6)

Grid Items

• All direct children of the grid container are automatically become grid items.

(7)

Grid Rows and Columns

(8)

Grid Gaps

The gap sizes are adjustable using one of the following properties:

• grid-column-gap

• grid-row-gap

• grid-gap

(9)

Grid Gaps Example

(10)

Grid Container

02

(11)

Grid Container

• To make an HTML element behave as a grid container, you have to set the display property to grid or inline-grid.

• Grid containers consist of grid items, placed inside columns and rows.

(12)

Create a simple HTML

(13)

Common.css

grid-container: grid-template-columns

• The grid-template-columns property defines the number of columns in your grid layout, and it can define the width of each column.

• The value is a space-separated-list, where each value defines the width of the respective column.

• If you want your grid layout to contain 4 columns, specify the width of the 4 columns, or "auto" if all columns should have the same width.

(14)

Custom column sizes

• We could also specify exact size for each column.

(15)

Common.css

grid-container: grid-template-rows

• The grid-template-rows property defines the height of each row.

• If there are more rows than specified, then HTML will reiterate starting from the first specified height.

(16)

Grid Content Horizontal Spacing

• If we specify grid column width with total width less than the

container width, then we need to specify how to justify the content.

• Justify content options:

– Space – evenly:

– Space – around – Space – between – Center

– Start – End

(17)

Justify Content: Space evenly

• give the columns equal amount of space between, and around them.

(18)

Justify Content: Space around

• give the columns equal amount of space around them.

(19)

Justify Content: Space between

• give the columns the maximum equal amount of space between them.

(20)

Justify Content: Center

• align the grid in the middle of the container

(21)

Justify Content: Start

• align the grid at the beginning of the container

(22)

Justify Content: End

• align the grid at the end of the container

(23)

Grid Content Vertical Alignment

• The align-content property is used to vertically align the whole grid inside the container.

• Options:

– Center

– Space-evenly – Space-around – Space-between – Start

– End

(24)

Algin Content: Center

• align the grid in the middle of the container

(25)

Align Content: Try other alignments

(26)

Grid Item

03

(27)

Grid Lines

(28)

Multiple Columns Grid

(29)

Multiple Columns Grid: Grid-Column

Grid-column: 1 / 5 means the grid will start at column 1 and end at column 5

(30)

Column Span

Item2 starts at column line 2 and span for 3 columns

(31)

Multiple Rows Grid

(32)

Multiple Rows Grid: grid-row

Item1 starts on row line 1 and ends on row line 4

(33)

Exercise

1

2 3

4 5 6 7

8

9

10 11 12

(34)

Grid-Area

• Grid-Area can be used as a shortcut to specify grid-row-start, grid- column-start, grid-row-end and the grid-column-end properties.

(35)

Grid-area: Naming Grid Items

• The grid-area property can also be used to assign a name to a grid item.

(36)

Using Named Grid Items

• Each row is defined using single quotes (' ')

The columns inside each row is defined within the quotes, separated by a space.

The example specifies one row with five columns (all columns are named as myArea).

• Item1 occupies all area named as myArea. Since all five columns in the specified row are named as myArea, item1 occupies all five columns.

(37)

Other Named Area Examples

(38)

Unnamed Area

• Period / dot (.) specifies area with no name.

(39)

Defining multiple Rows

• To define two or more rows, define the columns of the subsequent row inside subsequent set of apostrophes.

(40)

Sample of a Web Template

(41)

Grid Area: Order of the Items

• Using grid area, we can position an item as needed, independent from the order of the HTML code.

• E.g., the first item in the HTML code not necessarily appear as the first item in the grid.

(42)

Grid & Media Queries

04

(43)

Grid Layout based on Screen Size

Wide Screen (> 500px)

Small Screen (<= 500px)

(44)

Exercise

Create the following grid layout

Wide Screen (> 500px) Wide Screen (<= 500px)

(45)

That’s All

~

Referensi

Dokumen terkait