{"id":3060,"date":"2022-08-29T00:39:56","date_gmt":"2022-08-29T04:39:56","guid":{"rendered":"https:\/\/ubwp.buffalo.edu\/art320\/?page_id=3060"},"modified":"2025-09-23T14:40:54","modified_gmt":"2025-09-23T18:40:54","slug":"exercise-4-css-flexbox","status":"publish","type":"page","link":"https:\/\/ubwp.buffalo.edu\/art320\/exercises\/exercise-4-css-flexbox\/","title":{"rendered":"Exercise 4: CSS Flexbox"},"content":{"rendered":"\n<h2 class=\"wp-block-heading has-large-font-size\">Flexbox<\/h2>\n\n\n\n<p>Flexbox (Flexible Box) is a <em>direction-<strong>agnostic<\/strong><\/em> layout model which makes it more efficient to arrange and align items within a container. Unlike the <em>direction-<strong>specific<\/strong><\/em> display of <code><strong>block<\/strong><\/code> (vertical) and <code><strong>inline<\/strong><\/code> (horizontal) objects, <code>flex<\/code> objects can be <strong>ordered in two directions<\/strong>, and can also <strong>expand<\/strong> to fill available space and <strong>shrink<\/strong> to prevent overflow.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>In the flex layout model, the children of a flex container can be laid out in any direction, and can \u201cflex\u201d their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated. Nesting of these boxes (horizontal inside vertical, or vertical inside horizontal) can be used to build layouts in two dimensions.<\/p>\n<cite><a href=\"https:\/\/www.w3.org\/TR\/css-flexbox\/\">W3C<\/a><\/cite><\/blockquote>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/css-tricks.com\/snippets\/css\/a-guide-to-flexbox\/\">A Complete Guide to Flexbox<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/css-tricks.com\/wp-content\/uploads\/2022\/02\/css-flexbox-poster.png\">Reference Chart<\/a><\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\" \/>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"http:\/\/flexbox.io\/\">Free Flexbox Course<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/buffalo.box.com\/s\/9vuti50pygb9g6pgz4ubiswka5exp3wp\">Free Flexbox Course Reference Files<\/a><\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Flex Containers and Flex Items<\/h2>\n\n\n\n<p>Some flexbox CSS properties are added to parent items (<strong>flex containers<\/strong>) while others are to be used on children (<strong>flex items<\/strong>).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Flex Container<\/h2>\n\n\n\n<p>If \u201cregular\u201d float-based layout is based on both <em>block and inline flow directions<\/em>, the flex layout is based on <em>flex-flow directions<\/em>. This figure explains the main idea behind the flex layout.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"310\" src=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2019\/02\/flex-directions.png\" alt=\"Figure showing flex-flow direction.\" class=\"wp-image-1722\" srcset=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2019\/02\/flex-directions.png 660w, https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2019\/02\/flex-directions-300x141.png 300w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>main axis<\/strong> &#8211; The primary axis along which flex items are placed. Direction may not always be horizontal, depending on the <code>flex-direction<\/code>property.<\/li>\n\n\n\n<li><strong>main-start | main-end<\/strong> &#8211; Flex items appear within the container starting from main-start and going to main-end.<\/li>\n\n\n\n<li><strong>main size<\/strong> &#8211; A flex item&#8217;s width or height, whichever is in the main dimension.<\/li>\n\n\n\n<li><strong>cross axis<\/strong> &#8211; The axis perpendicular to the main axis. Its direction depends on the main axis direction.<\/li>\n\n\n\n<li><strong>cross-start | cross-end<\/strong> &#8211; Flex lines are filled with items and placed into the container starting on the cross-start side of the flex container and going toward the cross-end side.<\/li>\n\n\n\n<li><strong>cross size<\/strong> &#8211; The width or height of a flex item, whichever is in the cross dimension, is the item&#8217;s cross size property.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-red-color has-css-opacity has-vivid-red-background-color has-background is-style-wide is-style-wide--1\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">CSS Properties for Flex Containers<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#display\">display<\/a><\/li>\n\n\n\n<li><a href=\"#flex-direction\">flex-direction<\/a><\/li>\n\n\n\n<li><a href=\"#flex-wrap\">flex-wrap<\/a><\/li>\n\n\n\n<li><a href=\"#flex-flow\">flex-flow<\/a><\/li>\n\n\n\n<li><a href=\"#justify-content\">justify-content<\/a><\/li>\n\n\n\n<li><a href=\"#align-items\">align-items<\/a><\/li>\n\n\n\n<li><a href=\"#align-content\">align-cont<\/a><a href=\"http:\/\/align-content\">ent<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/gap\">gap, row-gap, column-gap<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"display\">display<\/h3>\n\n\n\n<p> \u2014 defines a container as being flex, inline or block (default). <strong>All children will behave as flex items<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.container <span class=\"token punctuation\">{\n<\/span><span class=\"token property\">    display<\/span><span class=\"token punctuation\">:<\/span> flex<span class=\"token punctuation\">;<\/span><span class=\"token comment\">\n<\/span>}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-red-color has-css-opacity has-vivid-red-background-color has-background is-style-default\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"flex-direction\">flex-direction<\/h3>\n\n\n\n<p> \u2014 establishes the <strong>main-axis<\/strong>, defining the direction flex items appear in the flex container,&nbsp;either in horizontal rows or vertical columns. The <strong>cross-axis<\/strong> direction crosses the main-axis. For example, if the direction is <code>row<\/code>, and by default points left to right, the cross-axis is top to bottom.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.container {\n    flex-direction: row | row-reverse | column | column-reverse;\n}<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>row<\/strong><\/code> (default \u2014 you can leave this property out and direction will default to row): left to right<\/li>\n\n\n\n<li><code><strong>row-reverse<\/strong><\/code>: right to left <\/li>\n\n\n\n<li><code><strong>column<\/strong><\/code>: same as <code>row<\/code> but top to bottom<\/li>\n\n\n\n<li><code><strong>column-reverse<\/strong><\/code>: same as <code>row-reverse<\/code> but bottom to top<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full has-custom-border is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"410\" height=\"96\" src=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-1.png\" alt=\"Flex-direction: row\" class=\"wp-image-3124\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-1.png 410w, https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-1-300x70.png 300w\" sizes=\"auto, (max-width: 410px) 100vw, 410px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"163\" height=\"406\" src=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-3.png\" alt=\"flex-direction:column\" class=\"wp-image-3128\" style=\"border-radius:0px\" srcset=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-3.png 163w, https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-3-120x300.png 120w\" sizes=\"auto, (max-width: 163px) 100vw, 163px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-red-color has-css-opacity has-vivid-red-background-color has-background is-style-default\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"flex-wrap\">flex-wrap<\/h3>\n\n\n\n<p> \u2014 default behavior is for all items to try to fit in one line. This can be overridden by the <code>flex-wrap<\/code> property:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.container {\n    <span class=\"token property\">flex-wrap<\/span><span class=\"token punctuation\">:<\/span> nowrap | wrap | wrap-reverse<span class=\"token punctuation\">;<\/span>\n}<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>nowrap<\/code>&nbsp;&#8211; (default behavior): all flex items will be on one line<\/li>\n\n\n\n<li><code>wrap<\/code>&nbsp;&#8211; flex items will wrap onto multiple lines, from top to bottom.<\/li>\n\n\n\n<li><code>wrap-reverse<\/code>&nbsp;&#8211; flex items will wrap onto multiple lines from bottom to top.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-resized has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"610\" src=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-8.png\" alt=\"flex-wrap\" class=\"wp-image-3149\" style=\"border-radius:0px;width:473px;height:415px\" srcset=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-8.png 694w, https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-8-300x264.png 300w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<p><strong>Note<\/strong>: Flex will attempt to accommodate your item widths, but it will narrow the items to fit when set to <code>nowrap<\/code> .<\/p>\n\n\n\n<p><strong>Also note<\/strong>: flex items will stretch to fill their parent&#8217;s height, unless given their own height, or if <code>wrap<\/code> is applied.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"flex-flow\">flex-flow<\/h3>\n\n\n\n<p>This combined both <code>flex-direction<\/code> and <code>flex-wrap<\/code> into one property, which together define the flex container\u2019s main and cross axes. The default value is <code>row nowrap<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>.container { \n      flex-flow: column wrap; \n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-red-color has-css-opacity has-vivid-red-background-color has-background is-style-default\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"justify-content\">justify-content<\/h3>\n\n\n\n<p>\u2014 determines distribution along the main-axis.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.container {\n    justify-content<span class=\"token property\">:<\/span> flex=start | flex-center | flex-end\u2026 ;\n}<\/pre>\n\n\n\n<ul id=\"block-28a45a39-526f-4112-b2ce-77067ff9dca4\" class=\"wp-block-list\">\n<li><code>flex-start<\/code>&nbsp;(default): items gathered toward the start of the flex-direction.<\/li>\n\n\n\n<li><code>center<\/code>: items centered together along the line.<\/li>\n\n\n\n<li><code>flex-end<\/code>: items gathered toward the end of the flex-direction.<\/li>\n\n\n\n<li><code>space-between<\/code>: distributes items evenly in the line; from the start line to the end line.<\/li>\n\n\n\n<li><code>space-around<\/code>: distributes items evenly in the line with equal space around before and after the item.<\/li>\n\n\n\n<li><code>space-evenly<\/code>: items distributed so that the spacing between any two items (and the space to the edges) is equal.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"426\" height=\"664\" src=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-6.png\" alt=\"Examples of the justify-content property.\" class=\"wp-image-3142\" style=\"border-radius:0px\" srcset=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-6.png 426w, https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-6-192x300.png 192w\" sizes=\"auto, (max-width: 426px) 100vw, 426px\" \/><\/figure>\n\n\n\n<p><strong>Note<\/strong>: when using <code>flex-direction: column<\/code>, the parent container must have a height set, otherwise items will fill the space vertically.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-red-color has-css-opacity has-vivid-red-background-color has-background is-style-default\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"align-items\">align-items<\/h3>\n\n\n\n<p>\u2014 determines how flex items are distributed along the cross-axis. For example, when using <code>flex-direction: row<\/code>, align-items works vertically (perpendicular to the main-axis.)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.container {\n    align-items<span class=\"token property\">:<\/span> <span class=\"token property\"><span style=\"font-size: inherit\">stretch | flex-start | flex-end | center | baseline<\/span><\/span>\u2026 ;<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>stretch<\/code>&nbsp;(default): stretch to fill the container&#8217;s height.<\/li>\n\n\n\n<li><code>flex-start<\/code>: items are placed at the start of the cross-axis.<\/li>\n\n\n\n<li><code>flex-end<\/code>: items are placed at the end of the cross-axis.<\/li>\n\n\n\n<li><code>center<\/code>: items are centered in the cross-axis.<\/li>\n\n\n\n<li><code>baseline<\/code>: items are aligned according to their baselines, especially useful for text.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"803\" height=\"770\" src=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2023\/02\/align-items3.png\" alt=\"Visualization of the align-items property.\" class=\"wp-image-3385\" style=\"border-radius:0px\" srcset=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2023\/02\/align-items3.png 803w, https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2023\/02\/align-items3-300x288.png 300w, https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2023\/02\/align-items3-768x736.png 768w\" sizes=\"auto, (max-width: 803px) 100vw, 803px\" \/><\/figure>\n\n\n\n<p><strong>Note<\/strong>: Parent containers must have a defined height for <code>align-items<\/code> to function properly.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-red-color has-css-opacity has-vivid-red-background-color has-background is-style-default\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"align-content\">align-content<\/h3>\n\n\n\n<p>\u2014 determines how a container&#8217;s lines are distributed when there are multiple lines of code and extra space in the cross-axis.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.container {\n    align-content<span class=\"token property\">:<\/span> <span class=\"token property\"><span style=\"font-size: inherit\">stretch | flex-start | flex-end | center | baseline<\/span><\/span>\u2026 ;\n}<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>normal&nbsp;(default): items are packed in their default position as if no&nbsp;value was set.<\/li>\n\n\n\n<li><code>flex-start<\/code>: items packed to the start of the container. <\/li>\n\n\n\n<li><code>flex-end<\/code>&nbsp;: items packed to the end of the container. <\/li>\n\n\n\n<li><code>center<\/code>: items centered in the container.<\/li>\n\n\n\n<li>space-between: items evenly distributed; the first line is at the start of the container while the last one is at the end.<\/li>\n\n\n\n<li>space-around: items evenly distributed with equal space around each line.<\/li>\n\n\n\n<li>stretch: lines stretch to take up the remaining space.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"619\" src=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-10.png\" alt=\"align-content\" class=\"wp-image-3156\" style=\"border-radius:0px\" srcset=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-10.png 640w, https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-10-300x290.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"gap\">gap, row-gap, column-gap<\/h3>\n\n\n\n<p>\u2014controls the space between flex items. It applies that spacing&nbsp;<em>only between items<\/em>&nbsp;not on the outer edges.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>.container { <\/code>\n    <code>display: flex;<\/code>\n    <code>gap: 10px; <\/code>\n    <code>gap: 10px 20px; <em>\/* row-gap column gap *\/<\/em> <\/code>\n    <code>row-gap: 10px; <\/code>\n    <code>column-gap: 20px; <\/code>\n<code>}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-vivid-red-color has-css-opacity has-vivid-red-background-color has-background is-style-wide is-style-wide--2\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">CSS Properties for Flex Items<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#order\">order<\/a><\/li>\n\n\n\n<li><a href=\"#align-self\">align-self<\/a><\/li>\n\n\n\n<li><a href=\"#flex\">flex (flex-grow, flex-shrink, flex-basis)<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"order\">order<\/h3>\n\n\n\n<p>\u2014 by default flex items appear in the order they are written in html. You can alter the order of one or more items by setting an order value:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.item {<br>    <span class=\"token property\">order:<\/span> 1; \/* default is 0 *\/<br>}<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"140\" src=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-4.png\" alt=\".item3 { order: 1; }\" class=\"wp-image-3133\" style=\"border-radius:0px;width:401px;height:93px\" srcset=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-4.png 602w, https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-4-300x70.png 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"align-self\">align-self<\/h3>\n\n\n\n<p>\u2014 allows individual flex items to be assigned an alignment different from the alignment set for the container..<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.item {\n    <span class=\"token property\">align-self:<\/span> auto | flex-start | flex-end | center | baseline | stretch; }<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"333\" height=\"163\" src=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-11.png\" alt=\"align-self\" class=\"wp-image-3160\" style=\"border-radius:0px\" srcset=\"https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-11.png 333w, https:\/\/ubwp.buffalo.edu\/art320\/wp-content\/uploads\/sites\/103\/2022\/09\/image-11-300x147.png 300w\" sizes=\"auto, (max-width: 333px) 100vw, 333px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"flex\">flex (flex-grow, flex-shrink, flex-basis)<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>.item {<br>   flex: none | [ &lt;'flex-grow'&gt; &lt;'flex-shrink'&gt;? || &lt;'flex-basis'&gt; ]<br>}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>.item1 {<br>   flex: 10 5 400px;<br>}<\/code><\/pre>\n\n\n\n<p>\u2014 Used when you have too much space or not enough space for your items. Sets an item to expand or shrink a proportionate amount. <\/p>\n\n\n\n<p><code>flex-grow<\/code> \u2014 Defines proportionally how much a flex item can grow to fill excess space if necessary. It accepts a unitless value that serves as a proportion. Default is 0.<\/p>\n\n\n\n<p><code>flex-shrink<\/code> \u2014 Defines proportionally how much a flex item can shrink to fit into a narrower space, if necessary. Default is 1.<\/p>\n\n\n\n<p><code>flex-basis<\/code> \u2014 Defines the default size of an element before the remaining space is distributed. Default is  auto.<\/p>\n\n\n\n<p><code>flex<\/code> \u2014 the shorthand for flex-grow, flex-shrink and flex-basis combined. The second and third parameters (flex-shrink and flex-basis) are optional. The default is 0 1 auto.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-medium-font-size\">More Flex Learning Resources<\/h2>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/www.joshwcomeau.com\/css\/interactive-guide-to-flexbox\/\">Interactive Guide \u2014 Comeau<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/fjolt.com\/article\/a-guide-to-css-flexbox\">Interactive Guide \u2014 fjolt<\/a><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/flex\">More flex detail from MDN<\/a><\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide is-style-wide--3\" \/>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Instructions<\/h2>\n\n\n\n<p><em>In this exercise we will be creating a simple website using CSS Flexbox to layout our elements, including positioning nav within header and arranging thumbnails in a flexible grid<\/em>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create a flex-based nav bar<\/h3>\n\n\n\n<p><strong>Step<\/strong> <strong>1<\/strong>: Download and unzip the <a href=\"https:\/\/buffalo.box.com\/s\/ltanqfjmmqkiaoyzwu4887ujx5urow4m\">Exercise 4 Starter Files<\/a>. Add your last name before the folder name.<\/p>\n\n\n\n<p>Launch VS Code, then drag the exercise folder to the VS Code icon in your doc to see the files in the Explorer panel.<\/p>\n\n\n\n<p><strong>Step 2<\/strong>: View index.html in your browser using Responsive Design Mode. Note at narrow widths the nav items reflow  awkwardly. <\/p>\n\n\n\n<p>Examine the nav element in the html and css. While the item width is fluid (%) the nav can only accommodate a specific number of items before the line reflows. Adding a new link to the nav bar would require modifying the code.<\/p>\n\n\n\n<p><strong>Step 3<\/strong>: Using a flex approach, the <code>nav ul<\/code> will become the flex-container and the <code>ul li<\/code>&#8216;s will be the flex-items.<\/p>\n\n\n\n<p>Add a class to the <code>ul<\/code> html tag inside the <code>nav<\/code> element:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;ul class=\"flex-nav\"&gt;<\/code><\/pre>\n\n\n\n<p>Add this rule for the new class, in the section at the bottom commented: <br><code>\/* Flex Container *\/<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ul.flex-nav {\n      display:flex;<\/code>\n<code>      justify-content: space-around;<\/code>\n      gap: 10px;<code>\n}<\/code><\/pre>\n\n\n\n<p>Note that once display: flex is applied, the items spread out, taking up just as much room as they need.<\/p>\n\n\n\n<p><strong>Step 4:<\/strong> Add the flex property to the list items:<\/p>\n\n\n\n<p>Add this rule for the new class, in the section at the bottom commented: <br><code>\/* Flex Item *\/<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>.flex-nav li {\n       flex: 0 1 auto; \/* flex-grow flex-shrink flex-basis *\/\n <\/code>}<\/pre>\n\n\n\n<p><strong>Step 5:<\/strong> Adjust the flex to wrap the nav items every at two breakpoints:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>@media all and (max-width:600px) {\n   ul.flex-nav {\n        flex-wrap:wrap;\n   }\n   .flex-nav li {\n        flex: 1 1 50%;\n   }\n}\n\n@media all and (max-width:400px) {\n   .flex-nav li {\n        flex-basis:100%;\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create a flex-based image thumbnail gallery<\/h3>\n\n\n\n<p><strong>Step 6: <\/strong>Open the  gallery.html starter file in VS Code. Note that the height has been set to 100vh for initial visibility before content is added. A red border has been applied to help visualize the container.<br><br>Add nav ul to the .flex-nav class as on index.html.<\/p>\n\n\n\n<p><strong>Step 7:<\/strong> Embed eight images into the gallery div using the below code, modifying each line for all images:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;img src=\"images\/thumbs\/bird1.jpg\" alt=\"Bird\"  \/&gt;<\/pre>\n\n\n\n<p>Change the <code>#gallery height<\/code> value from <code>100vh<\/code> to <code>auto<\/code>.<\/p>\n\n\n\n<p>View gallery.html in your browser and notice the layout of the thumbnails at different page widths.<\/p>\n\n\n\n<p><strong>Step 8:<\/strong>  Add these three lines of code to <code>#gallery<\/code>, one line at a time, observing the results each time:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">  display: flex;\n  flex-wrap: wrap;\n  justify-content: space-around;<\/pre>\n\n\n\n<p>Experiment with different values for each property, then return to the above.<\/p>\n\n\n\n<p><strong>Step 9:<\/strong> <\/p>\n\n\n\n<p>Remove the <code>#gallery borde<\/code>r property.<\/p>\n\n\n\n<p><strong>Step 10:<\/strong> Save all files and upload completed site folder, making sure your last name in in the title, to the <a href=\"https:\/\/buffalo.box.com\/s\/ifg6oaf5imwss4xlczvymbt9dyisihnw\">Exercise 4 Box folder<\/a>.<\/p>\n\n\n\n<p>Option: Make bird1 clickable and link to the full size version of the image.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flexbox Flexbox (Flexible Box) is a direction-agnostic layout model which makes it more efficient to arrange and align items within a container. Unlike the direction-specific display of block (vertical) and [&hellip;]<\/p>\n","protected":false},"author":295,"featured_media":0,"parent":35,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_EventAllDay":false,"_EventTimezone":"","_EventStartDate":"","_EventEndDate":"","_EventStartDateUTC":"","_EventEndDateUTC":"","_EventShowMap":false,"_EventShowMapLink":false,"_EventURL":"","_EventCost":"","_EventCostDescription":"","_EventCurrencySymbol":"","_EventCurrencyCode":"","_EventCurrencyPosition":"","_EventDateTimeSeparator":"","_EventTimeRangeSeparator":"","_EventOrganizerID":[],"_EventVenueID":[],"_OrganizerEmail":"","_OrganizerPhone":"","_OrganizerWebsite":"","_VenueAddress":"","_VenueCity":"","_VenueCountry":"","_VenueProvince":"","_VenueState":"","_VenueZip":"","_VenuePhone":"","_VenueURL":"","_VenueStateProvince":"","_VenueLat":"","_VenueLng":"","_VenueShowMap":false,"_VenueShowMapLink":false,"footnotes":""},"class_list":["post-3060","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ubwp.buffalo.edu\/art320\/wp-json\/wp\/v2\/pages\/3060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubwp.buffalo.edu\/art320\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ubwp.buffalo.edu\/art320\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ubwp.buffalo.edu\/art320\/wp-json\/wp\/v2\/users\/295"}],"replies":[{"embeddable":true,"href":"https:\/\/ubwp.buffalo.edu\/art320\/wp-json\/wp\/v2\/comments?post=3060"}],"version-history":[{"count":109,"href":"https:\/\/ubwp.buffalo.edu\/art320\/wp-json\/wp\/v2\/pages\/3060\/revisions"}],"predecessor-version":[{"id":4186,"href":"https:\/\/ubwp.buffalo.edu\/art320\/wp-json\/wp\/v2\/pages\/3060\/revisions\/4186"}],"up":[{"embeddable":true,"href":"https:\/\/ubwp.buffalo.edu\/art320\/wp-json\/wp\/v2\/pages\/35"}],"wp:attachment":[{"href":"https:\/\/ubwp.buffalo.edu\/art320\/wp-json\/wp\/v2\/media?parent=3060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}