Creating Page Layouts w/CSS: Flex
CS 130: �Tools and Technologies of the World Wide Web
Spring, 2022
1
Outline
2
CSS & Layouts
Layouts are the hardest thing about CSS for many reasons:
3
Layout Tips
Activity: Composing a Layout in CSS
Let’s deconstruct this template website:
5
Outline
6
The Box Model
7
References:
The Box Model
Exercise 1: Box Model
Open 01-box-model and create this card:
Outline
10
Semantic, Block-Level Elements
<address> <article> <aside> <blockquote> <canvas> <dd> <div> <dl> <dt> <fieldset> <figcaption> <figure> <footer> <form> <h1>-<h6> <header> <hr> <li> <main> <nav> <noscript> <ol> <p> <pre> <section> <table> <tfoot> <ul> <video>
Semantic, Inline Elements
<a> <abbr> <acronym> <b> <bdo> <big> <br> <button> <cite> <code> <dfn> <em> <i> <img> <input> <kbd> <label> <map> <object> <output> <q> <samp> <script> <select> <small> <span> <strong> <sub> <sup> <textarea> <time> <tt> <var>
Outline
13
Using Media Queries
Media queries allow you to set CSS style rules based on the type of media and the device dimensions of the viewport. Example:
“Turning On” Media Queries in your HTML
In order to make sure that media queries are honored, you need to include a meta tag in the <head></head> of your html file:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Challenge: Can you make the card look different on a mobile device?
16
Outline
17
Flexbox Resources
Some resources:
Using Flexbox: Suggested Strategy
�Parent Container�Put the display into “flex mode” display: flex and then use the following properties to align the child items:
Child Container
Apply sizing to the child container as needed.
Flexbox: Practice 1
Open 02-flexbox. Can you create the following layouts?
1
2
3
Flexbox: Practice 1 Cont’d – Using Media Queries
Make it so that #1 is for Desktop screens, #2 is for Tablet, and #3 is for Mobile
1
2
3
Flexbox: Practice 2 (Lab 1)
Open 03-flexbox-media-queries and create these screens:
Desktop
Tablet
Mobile
Flexbox: Practice 3: Navigation Bar
Open 04-nav-bar, and try to make the following: