Responsive Web Design Flashcards
Columns
Columns are defined as the vertical sections that span the width of a page. In web design, it’s common to see layouts consisting of 12 or 16 columns, while other may only feature three columns. Defining the number of columns depends on what’s appropriate for your design, device, and or screen viewing size. They can be dependent on each other, meaning they are used to organize related content such as a continuation of a paragraph. They can also be independent of each other, meaning they are used for organizing the layout of unrelated content such as a sidebar. This allows for the flexibility of organizing information.
Name three major components of the grid anatomy
When designing a website, the grid comprises three major components: columns, gutters, and margins.
Gutters
a gutter is the negative space between each column. Gutters help in ensuring the columns don’t run together, which would negate the purpose of using a column-based grid. No content can spill into the gutter unless it is using the next column.
Margins
Margins appear on the left and right sides of the column-based grid. These ensure the content of your designs doesn’t match up to the edges of the browser window.
It’s important to note, margins may vary depending on the width of the grid, browser window, or device. For larger displays, margins may be very noticeable while on smaller screens, they may have the same width as a gutter.
Grid rows
Rows are the horizontal lines on a grid. Think of rows as invisible boxes that group content together by height. Rows are commonly used in web designs to group content together and re-order other content to allow for more whitespace.
What’s the difference between display: flex; and display: inline-flex;?
Much like the difference between display: block; and display: inline;, the main difference between display: flex; and display: inline-flex; is that display: inline-flex; will make the flex container an inline element while its content maintains its flexbox properties.
flex-start (justify-content property)
all items will be positioned in order, starting from the left of the parent container, with no extra space between or before them.
five commonly used values for the justify-content property
flex-start
flex-end
center
space-around
space-between
flex-end (justify-content property)
all items will be positioned in order, with the last item starting on the right side of the parent container, with no extra space between or after them.
center (justify-content property)
all items will be positioned in order, in the center of the parent container with no extra space before, between, or after them.
space-around (justify-content property)
items will be positioned with equal space before and after each item, resulting in double the space between elements.
space-between (justify-content property)
items will be positioned with equal space between them, but no extra space before the first or after the last elements.
five commonly used values for the align-items property
flex-start
flex-end
center
baseline
stretch
flex-start (align-items property)
all elements will be positioned at the top of the parent container.
flex-end (align-items property)
all elements will be positioned at the bottom of the parent container.
center (align-items property)
the center of all elements will be positioned halfway between the top and bottom of the parent container.
baseline (align-items property)
the bottom of the content of all items will be aligned with each other.
stretch (align-items property)
if possible, the items will stretch from top to bottom of the container (this is the default value; elements with a specified height will not stretch; elements with a minimum height or no height specified will stretch).
flex-grow
The flex-grow property allows us to specify if items should grow to fill a container and also which items should grow proportionally more or less than others. the default value of flex-grow is 0. Margins are unaffected by flex-grow and flex-shrink.
flex-shrink
the flex-shrink property can be used to specify which elements will shrink and in what proportions. the default value of flex-shrink is 1, and this causes the flex items to shrink when the flex container is too small, even though we do not declare the property. Margins are unaffected by flex-grow and flex-shrink.
flex-basis
flex-basis allows us to specify the width of an item before it stretches or shrinks.
Is flex-basis the same as setting width?
It’s not! We can think of flex-basis as the width OR height (depending on flex-direction) of our flex items before they are constrained by a flex container.
flex (property)
The shorthand flex property provides a convenient way for specifying how elements stretch and shrink, while simplifying the CSS required. The flex property allows you to declare flex-grow, flex-shrink, and flex-basis all in one line.
Note: The flex property is different from the flex value used for the display property.
Give an example of declaring declare flex-grow, flex-shrink, and flex-basis all in one line.
.small {
flex: 1 2 100px;
}
Give a few instances where using the shorthand flex property is unnecessary to use:
- To set only the flex-basis and use the default flex-shrink: 1;
- To set only the flex-basis and flex-shrink properties without specifying a flex-grow value as well, because we cannot set flex-shrink and flex-basis using two values for the flex property
- To use only flex-shrink or flex-basis, we can however set flex-grow if we use a single value on the flex property
flex-wrap property
Sometimes, we don’t want our content to shrink to fit its container. Instead, we might want flex items to move to the next line when necessary. This can be declared with the flex-wrap property.
Note: The flex-wrap property is declared on flex containers.
Give the three values of the flex-wrap property
wrap
wrap-reverse
nowrap
wrap (flex-wrap value)
child elements of a flex container that don’t fit into a row will move down to the next line
wrap-reverse (flex-wrap value)
the same functionality as wrap, but the order of rows within a flex container is reversed (for example, in a 2-row flexbox, the first row from a wrap container will become the second in wrap-reverse and the second row from the wrap container will become the first in wrap-reverse)
nowrap (flex-wrap value)
prevents items from wrapping; this is the default value and is only necessary to override a wrap value set by a different CSS rule.
align-content
If a flex container has multiple rows of content, we can use align-content to space the rows from top to bottom.
Note: The align-content property is declared on flex containers.
Give the more commonly used align-content values?
flex-start
flex-end
center
space-between
space-around
stretch
flex-start (align-content value)
all rows of elements will be positioned at the top of the parent container with no extra space between.
flex-end (align-content value)
all rows of elements will be positioned at the bottom of the parent container with no extra space between.
center (align-content value)
all rows of elements will be positioned at the center of the parent element with no extra space between.
space-between (align-content value)
all rows of elements will be spaced evenly from the top to the bottom of the container with no space above the first or below the last.
space-around (align-content value)
all rows of elements will be spaced evenly from the top to the bottom of the container with the same amount of space at the top and bottom and between each element.
stretch (align-content value)
if a minimum height or no height is specified, the rows of elements will stretch to fill the parent container from top to bottom (default value).
Name the axes of the flex containers.
flex containers have two axes: a main axis and a cross axis. By default, the main axis is horizontal and the cross axis is vertical.
Explain the main axis and what it is used for.
The main axis is horizontal. The main axis is used to position flex items with the following properties:
justify-content
flex-wrap
flex-grow
flex-shrink
Explain the cross axis and what it is used for.
The cross axis is vertical. The cross axis is used to position flex items with the following properties:
align-items
align-content
Name which properties we position using the main axis.
The main axis is used to position flex items with the following properties:
justify-content
flex-wrap
flex-grow
flex-shrink
Name which properties we position using the cross axis.
The cross axis is used to position flex items with the following properties:
align-items
align-content
flex-direction property
This property makes the main axis and cross axis be interchangeable. We can switch them using this property. If we add the flex-direction property and give it a value of column, the flex items will be ordered vertically, not horizontally.
Note: The flex-direction property is declared on flex containers.
Name the four values of the flex-direction property
The flex-direction property can accept four values:
row
row-reverse
column
column-reverse
row (flex-direction)
elements will be positioned from left to right across the parent element starting from the top left corner (default).
row-reverse (flex-direction)
elements will be positioned from right to left across the parent element starting from the top right corner.
column (flex-direction)
elements will be positioned from top to bottom of the parent element starting from the top left corner.
column-reverse (flex-direction)
elements will be positioned from the bottom to the top of the parent element starting from the bottom left corner.
Why would we use flex-direction: row-reverse/column-reverse;?
The use of flex-direction: row-reverse/column-reverse; will mostly be decided by design/layout specifications for our site, however, a couple great use cases:
altering the order of flex items with CSS instead of JavaScript, for example: clicking a sort button could switch order of elements from ascending to descending
altering the order of flex items for CSS animations/transitions/effects
flex-flow
Like the shorthand flex property, the shorthand flex-flow property is used to declare both the flex-wrap and flex-direction properties in one line.
The first value in the flex-flow declaration is a flex-direction value and the second is a flex-wrap value. All values for flex-direction and flex-wrap are accepted.
Note: The flex-flow property is declared on flex containers.
CSS Flexbox
The CSS display: flex property sets an HTML element as a block level flex container which takes the full width of its parent container. Any child elements that reside within the flex container are called flex items.
Flex items change their size and location in response to the size and position of their parent container.
div {
display: flex;
}
justify-content Property
The CSS justify-content flexbox property defines how the browser distributes space between and around content items along the main-axis of their container. This is when the content items do not use all available space on the major-axis (horizontally).
div {
display: flex;
justify-content: center;
}
Values of justify-content
justify-content can have the values of:
flex-start
flex-end
center
space-between
space-around
flex Property
The flex CSS property specifies how a flex item will grow or shrink so as to fit within the space available in its flex container. This is a shorthand property that declares the following properties in order on a single line:
flex-grow
flex-shrink
flex-basis
/* Three properties declared on three lines: */
.first-flex-item {
flex-grow: 2;
flex-shrink: 1;
flex-basis: 150px;
}
/* Same three properties declared on one line: */
.first-flex-item {
flex: 2 1 150px;
}
flex-direction Property
The flex-direction CSS property specifies how flex items are placed in the flex container - either vertically or horizontally. This property also determines whether those flex items appear in order or in reverse order.
align-content Property
The align-content property modifies the behavior of the flex-wrap property. It determines how to space rows from top to bottom (ie. along the cross axis). Multiple rows of items are needed for this property to take effect.