Chapter5 CSS Flexbox
Chapter5 CSS Flexbox
LECTURE
OUTLINE
C: FLEX ITEM PROPERTIES
Flex Items:
The child elements within a flex container are called ‘flex items’.
These items are laid out along a single axis or multiple axes, depending on how the container is
configured.
The flex container becomes flexible by setting the display property to flex
as follows:
.flex-container {
display: flex;
}
.flex-container {
display: flex;
flex-direction: column;
}
Column-reverse: this stacks the flex items vertically (but from bottom to
top).
.flex-container {
display: flex;
flex-direction: column-reverse;
}
Row: the row value stacks the flex items horizontally from left to right.
.flex-container {
display: flex;
flex-direction: row;
}
Row-reverse: the row value stacks the flex items horizontally (but from
right to left.
.flex-container {
display: flex;
flex-direction: row-reverse;
}
.flex-container {
display: flex;
flex-wrap: wrap;
}
Flex-wrap:
The flex-wrap property specifies whether the flex items should wrap or not.
.flex-container {
display: flex;
flex-wrap: wrap;
}
The flex-wrap: no wrap specifies that the flex items will not wrap (this is default).
.flex-container {
display: flex;
flex-wrap: nowrap;
}
CIS 1203 - WEB TECHNOLOGIES – DR. OUSSAMA HAMID 15
JUSTIFY-CONTENT & ALIGN-ITEMS
Flex-grow: The flex-grow property specifies how much a flex item will
grow relative to the rest of the flex items.
<div class="flex-container">
<div style="flex-grow: 1">1</div>
<div style="flex-grow: 1">2</div>
<div style="flex-grow: 8">3</div>
</div>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div style="flex-basis: 200px">3</div>
<div>4</div>
</div>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div style="align-self: center">3</div>
<div>4</div>
</div>
CIS 1203 - WEB TECHNOLOGIES – DR. OUSSAMA HAMID 21
ORDER
Order: The order property specifies the order of the flex items.
<div class="flex-container">
<div style="order: 3">1</div>
<div style="order: 2">2</div>
<div style="order: 4">3</div>
<div style="order: 1">4</div>
</div>
Responsive web design is about creating web pages that look good in all devices.
A responsive web design will automatically adjust for different screen sizes and
viewports.
It is when you use CSS and HTML to resize, hide, shrink, enlarge, or move the
content to make it look good on any screen.
Media Queries
In addition to resize images, it is also common to use media queries in responsive
web design.
With media queries you can define completely different styles for different browser
sizes.
What are media queries useful for?
Imagine you are designing a website, and you want it to look good on both big
computer screens and small phone screens. Media queries help you achieve this.
The following is a more specific syntax with additional control over how the media
query is evaluated.
@media is the beginning of a media query rule. It indicates that you are defining
styles that should be applied under certain conditions.
not | only these are optional keywords that modify how the media query is evaluated.
not means the enclosed styles will apply when the condition specified is not true.
only means that the enclosed styles will apply only when the condition specified is true.
media_type this is where you specify the type of media for which the styles should be
applied. Common media types include things like “screen,” “print,” “all,” “speech,”
etc. For example, if you want your styles to apply only when printing a webpage,
you’d use ‘print’ as the media type.
conditions these are criteria that determine when the enclosed styles should be
applied. Conditions can include things like screen width, screen height, orientation,
and more. We use logical operators like ‘and’, ‘not’ and ‘only’ to combine these
conditions.
CSS rules: Inside the curly braces, you put CSS styles that should be applied when
the conditions in the media query are met.
Example:
@media screen and (max-width: 600) {
/* CSS rules; */
}
This media query is used to define CSS rules that will be applied to screens (like computers and
mobile devices) when their width is 600 pixels or less.
<aside>
The <aside> element is a semantic HTML5 element typically used for defining
some content aside from the content it is placed in.
SUMMAR with a more efficient way to distribute space and align content with a container,
even when the size of your elements is unknown or dynamic.
Y Key concepts and properties associated with CSS flexbox include flex container
and flex items.
Flex container properties include display, flex-direction, flex-wrap, and justify-
content.
Flex item properties include flex-grow, flex-shrink, flex-basis, flex-align, align-
self, and order.
Responsive website design uses CSS and HTML to resize, hide, shrink, enlarge,
or move the content to make it look good on any screen.
36
Flex Items
37