Responsive web window

Grid is “usually” used to define your skeleton structure and flexbox “usually” for the smaller edits of content.

image-20240427214356787

flex inside of grid

image-20240427214632721

grid inside of a flex box

image-20240427214724722

media query

image-20240427165954399

1
2
3
4
5
6
7
8
9
10
11
12
/* Default styles for all screen sizes */
p {
font-size: 16px;
}

/* Media query for screens with a maximum width of 600 pixels */
@media (max-width: 600px) {
p {
font-size: 14px;
}
}

Flexbox (display)

flex is a value for the display property.

overview1

overview2

—> flex vs. inline-flex

when you use flex, it no longer abides by inline/block/inline-block/none

When you assign display: flex; to an element, it changes the default behavior of that element and its children.

By default:

  • <div> elements are block-level elements, meaning they typically start on a new line and take up the full width available.
  • <span> elements are inline-level elements, meaning they don’t start on a new line and only take up as much width as necessary.

When you apply display: flex; to a parent element, it turns into a flex container, and its children become flex items. The flex container can then control the layout of its flex items using various flexbox properties.

1
2
3
4
5
6
7
8
9
.flex-container {
display: flex;
gap: 20px; /* This is the flex gap */
}

.flex-item {
background-color: #f0f0f0;
padding: 10px;
}

flexbox

image-20240427171706301

flex

Flex Direction

https://www.w3schools.com/cssref/css3_pr_flex-direction.php

try to run and play with this code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flex Direction Example</title>
<style>
.container {
display: flex;
border: 2px solid #333;
}

.item {
flex = 1;
padding: 20px;
border: 1px solid #000;
margin: 10px;
}
</style>
</head>
<body>

<h2>flex-direction: row;</h2>
<div class="container" style="flex-direction: row;">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</div>

<h2>flex-direction: row-reverse;</h2>
<div class="container" style="flex-direction: row-reverse;">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</div>

<h2>flex-direction: column;</h2>
<div class="container" style="flex-direction: column;">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</div>

<h2>flex-direction: column-reverse;</h2>
<div class="container" style="flex-direction: column-reverse;">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</div>

</body>
</html>

In this HTML document, each flex container demonstrates a different flex-direction value: row, row-reverse, column, and column-reverse. You can copy and paste this code into an HTML file and open it in a web browser to see the visual layout changes produced by each flex-direction value.

flex basis has to go on to the child not on the container

In Flexbox, certain properties are applied to the flex container, while others are applied to the flex items. Here’s a breakdown:

Properties for the Flex Container:

  1. display: Specifies the container as a flex container. Use display: flex; or display: inline-flex; on the container element.
  2. flex-direction: Defines the direction in which flex items are placed in the flex container. Options include row, row-reverse, column, and column-reverse.
  3. flex-wrap: Determines whether flex items are forced onto a single line or can wrap onto multiple lines. Options include nowrap, wrap, and wrap-reverse.
  4. justify-content: Aligns flex items along the main axis of the flex container. Options include flex-start, flex-end, center, space-between, and space-around.
  5. align-items: Aligns flex items along the cross axis of the flex container when they do not take up all the available space. Options include flex-start, flex-end, center, stretch, and baseline.
  6. align-content: Aligns a flex container’s lines within the flex container when there’s extra space in the cross axis. Options are similar to align-items.

Properties for the Flex Items:

  1. flex: Shorthand for flex-grow, flex-shrink, and flex-basis. It specifies how a flex item will grow, shrink, and its initial size.
  2. flex-grow: Specifies the ability for a flex item to grow if necessary. It accepts a unitless value that serves as a proportion. If all items have flex-grow set to 1, the remaining space in the container will be distributed equally among the items.
  3. flex-shrink: Specifies the ability for a flex item to shrink if necessary.
  4. flex-basis: Specifies the initial main size of a flex item before additional space is distributed according to flex-grow and flex-shrink.
  5. order: Specifies the order in which a flex item appears in the flex container. By default, all flex items have an order of 0, but this property allows you to change the order.
  6. align-self: Allows the default alignment set by align-items to be overridden for individual flex items. It accepts the same values as align-items.

Flex Layout

https://appbrewery.github.io/flex-layout/

  • align-self: flex-start

it makes this item separate from the group things to do its own thing

https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Flex Size

content width < width < flex-basis < min-width/max-width

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Width Properties Example</title>
<style>
.container {
display: flex;
justify-content: space-around;
align-items: center;
border: 1px solid #ccc;
padding: 20px;
margin-bottom: 20px;
}

.item {
background-color: #f0f0f0;
padding: 10px;
margin: 5px;
}

/* Set different width properties */
.content-width {
/* Default value */
}

.width {
width: 200px;
}

.flex-basis {
flex-basis: 150px;
}

.min-max-width {
min-width: 100px;
max-width: 300px;
}
</style>
</head>
<body>
<div class="container">
<div class="item content-width">Content Width</div>
</div>

<div class="container">
<div class="item width">Width</div>
</div>

<div class="container">
<div class="item flex-basis">Flex Basis</div>
</div>

<div class="container">
<div class="item min-max-width">Min-Max Width</div>
</div>
</body>
</html>

  1. Content Width (content-width):
    • The .content-width class doesn’t have any specific width properties applied to it. Therefore, its width is determined solely by the content it contains. This is the default behavior of block-level elements like <div>.
    • In the example, the .content-width item will expand or shrink based on the width of the content inside it, along with any padding and margins applied to it.
  2. Width (width):
    • The .width class sets a fixed width of 200 pixels for the .item element. This overrides the default content width and any other sizing properties.
    • In the example, the .width item will always have a width of 200 pixels, regardless of the content it contains or the space available within its container.
  3. Flex-Basis (flex-basis):
    • The .flex-basis class sets the initial main size of the .item element to 150 pixels when it’s used within a flex container. This property behaves similarly to width, but it’s specific to flex items.
    • In the example, the .flex-basis item will initially have a width of 150 pixels within the flex container. However, it can still grow or shrink based on the available space and the flex layout algorithm.
  4. Min-Width and Max-Width (min-width and max-width):
    • The .min-max-width class sets constraints on the width of the .item element, ensuring it doesn’t become narrower than 100 pixels and wider than 300 pixels.
    • In the example, the .min-max-width item will have a width that adapts to its content if it’s less than 100 pixels wide. However, it won’t shrink below 100 pixels due to the min-width constraint. Similarly, it won’t expand beyond 300 pixels due to the max-width constraint.

flex grow flex shrink

https://www.freecodecamp.org/news/even-more-about-how-flexbox-works-explained-in-big-colorful-animated-gifs-a5a74812b053/

  • Flex-shrink: This property controls how much a flex item can shrink relative to the rest of the flex items when there’s not enough space in the flex container. By default, the value is 1, meaning the item can shrink to prevent overflow.
  • flex-shrink: 0: This explicitly disables shrinking for the flex item. It tells the browser not to allow the item to shrink, regardless of the available space and the shrinking potential of other flex items.

image-20240427211818113

Let’s break down flex: 1 1 0 :

  1. flex-grow: This property determines how much the flex item can grow relative to other flex items within the same flex container when there is extra space available. In the case of flex: 1 1 0, flex-grow is set to 1, meaning the item will grow proportionally to other items with a flex-grow value of 1. If all items in the flex container have the same flex-grow value, they will grow equally to fill the available space.
  2. flex-shrink: This property determines how much the flex item can shrink relative to other flex items when there isn’t enough space in the flex container. Again, in flex: 1 1 0, flex-shrink is set to 1, indicating that the item can shrink proportionally to other items with a flex-shrink value of 1. If all items have the same flex-shrink value, they will shrink equally to prevent overflow or wrapping.
  3. flex-basis: This property defines the initial size of the flex item before any extra space is distributed among flex items. In flex: 1 1 0, flex-basis is set to 0. This means the initial size of the item will be determined solely by its content and any constraints imposed by min-width and max-width. Setting flex-basis to 0 allows the flex container to distribute space evenly among flex items based on their flex-grow and flex-shrink values without considering their initial sizes.

image-20240427212055382

https://appbrewery.github.io/flexbox-sizing-exercise/

answer:

image-20240427213251709

CSS grid

flex vs grid

https://appbrewery.github.io/grid-vs-flexbox/

grid display

image-20240427215050218

image-20240427215345790

the grid will try to take up the full width of the screen so we need to set the width to 800 px, otherwise when the window is larger there will be gap between columns.

grid sizing

image-20240427215741981

its eqaul to :

​ grid-template: 100px 200px / 400px 800px;

1
2
3
4
5
6
7
8
9
.grid-container {
display: grid;
grid-template-columns: auto auto auto; /* Three columns with equal width */
/* Other grid properties */
}

.item {
/* Styles for grid items */
}

In this example:

  • grid-template-columns: auto auto auto; sets up a grid container with three columns, each with a width determined by the content inside it. The “auto” keyword tells the browser to automatically size the columns based on the content within them.
  • Each “auto” column will expand to fit its content. If one column has more content than another, it will expand accordingly.

image-20240427221447005

when you use auto on a row, it’s going to fit the content

while you use auto on columns, it’s going to fit the 100% width

grid sizing: https://appbrewery.github.io/grid-sizing/

  • gractional size:

image-20240427225230663

  • MinMaz size

image-20240427225421390

wont wont be bigger than 800 px and wont be smaller than 400px

  • repeat

    image-20240427225726154

image-20240427225849044

the extra one will get an automatic size based on its height and also any existing column size. it will match with the existing column size

image-20240427230009425

create a new row that doesnt fit in the grid, then give it a 300 px of the height

image-20240427230310246

image-20240427230359575

Grid Placement

  • Grid Container -> div

  • tracks

image-20240428113007527

  • cells

image-20240428113040763

  • lines

image-20240428113133602

  • exmaple

image-20240428113629207

if you don’t set the height to 100 vh, the height will be automatically sett according to the content.

we dont need to use margin or padding to separate the grids because we have gap : 3 rem;

use FlexBox to align item in the center of each grid!

justify-content, align-items

  1. justify-content:
    • This property aligns flex items along the main axis of the flex container.
    • It controls how flex items are spaced out or distributed along the main axis.
    • Values for justify-content include flex-start, flex-end, center, space-between, and space-around, among others.
    • For a flex container with a horizontal main axis, justify-content will control horizontal alignment.
    • Example: justify-content: center; will center flex items along the main axis.
  2. align-items:
    • This property aligns flex items along the cross-axis of the flex container.
    • It controls how flex items are positioned along the perpendicular axis to the main axis.
    • Values for align-items include flex-start, flex-end, center, baseline, and stretch.
    • For a flex container with a horizontal main axis, align-items will control vertical alignment.
    • Example: align-items: center; will center flex items along the cross axis.

image-20240428114312972

image-20240428114337157

grid-column

mdn web docs

1
2
3
4
5
6
7
8
9
.grid-container {
display: grid;
grid-template-columns: 100px 100px 100px; /* Three columns each 100px wide */
}

.grid-item {
grid-column-start: 2;
grid-column-end: span 2; /* Spanning across 2 columns */
}

In this example:

  • The grid item starts at the second column line (grid-column-start: 2) in the grid layout.
  • It spans across two columns (grid-column-end: span 2), covering both the second and third columns in the grid.

image-20240428115821739

image-20240428115949491

grid-row

the same with grid-column

grid -order

image-20240428120925397

1
2
3
4
5
6
7
8
9
10
11
12
13
.grid-container {
display: grid;
grid-template-columns: 100px 100px 100px; /* Three columns each 100px wide */
grid-template-rows: auto;
}

.grid-item {
/* By default, grid items have an order value of 0 */
}

.grid-item:nth-child(2) {
order: 3; /* This grid item will be displayed third, regardless of its source order */
}

In this updated example:

  • All .grid-item elements have a default order value of 0, meaning they will be displayed in their source order.
  • The .grid-item:nth-child(2) selector targets the second grid item and sets its order to 3. This means it will be displayed third within the grid container, overriding its default order.

another way:

image-20240428121524621

equal to:

grid-area

image-20240428121559716

The values you provided, grid-area:2/1/3/4, represent the grid area using four line numbers: row-start / column-start / row-end / column-end.

Let’s break it down:

  • The first value, 2, represents the starting row line.
  • The second value, 1, represents the starting column line.
  • The third value, 3, represents the ending row line.
  • The fourth value, 4, represents the ending column line.

overlapping layout

grid lletsyou overlay items, but flex box doesn’t allow you to do so

image-20240428122305424

bootstrap framework

it’s an external layout system 🥰

how to use bootstrap?

https://getbootstrap.com/docs/5.2/getting-started/introduction/

make sure your custom css occurs below the bootstrap link, so the custom css can override the bootstrap

As reference, here are our primary CDN links.

Description URL
CSS https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css
JS https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js

CDN stands for Content Delivery Network.

Imagine you want to share a big cake with your friends at a party. Instead of bringing the whole cake to each friend individually, you cut it into slices and give each friend a slice.

A CDN is like having multiple friends with slices of cake all around the party. When someone wants a slice, they can get it from the friend closest to them instead of waiting for you to bring it from the kitchen. This makes sure everyone gets cake faster and nobody has to wait too long.

In the same way, a CDN has servers (like friends with cake slices) spread out in different places. When you want to access a website or its content, the CDN finds the closest server to you and gives you the content from there. This makes websites load faster for you, no matter where you are.

12 Column System

https://getbootstrap.com/docs/5.2/layout/columns/

image-20240428135001357

image-20240428141046256

Bootstrap Breakpoints

https://getbootstrap.com/docs/5.0/layout/breakpoints/

Breakpoint Class infix Dimensions
X-Small None <576px
Small sm ≥576px
Medium md ≥768px
Large lg ≥992px
Extra large xl ≥1200px
Extra extra large xxl ≥1400px

image-20240428142204650

  1. sm: Represents small screens, typically smartphones in portrait orientation.
  2. md: Represents medium-sized screens, often tablets or laptops.
  3. lg: Represents large screens, such as desktop monitors or large laptops.

image-20240428142331315

col will automatically adjust the size to take up whatever proportion remains

Bootstrap Component

prebuilt component

button: https://getbootstrap.com/docs/5.3/components/buttons/#base-class

Bootstrap JavaScript

how to include bootstrap css and js? https://getbootstrap.com/docs/5.3/getting-started/introduction/

add javascript so that the dropdown menu and all these clicking functions work