Girl Develop It!
Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Introduction to RWD
And why you should care
And why RWD is preferred
Understanding media queries
@media screen and (min-width: 768px) {
/* window >= 768 pixels wide */
}
@media screen and (max-width: 768px) {
/* window <= 768 pixels wide */
}
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
<meta name="viewport" content="width=device-width, initial-scale=1.0">
https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag
Edit exercises/class-1/style.css
so our design is responsive.
Solutions to some of the most common problems
img {
max-width: 100%;
height: auto;
}
<nav>
<a href="#" id="toggle">Menu</a>
<ul id="menu">
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
</ul>
</nav>
#menu {
display: none;
}
#toggle:focus + #menu {
display: block;
}
Design to code & responsive images
@media screen and (min-width: X) {
/* greater than or equal to X */
}
@media screen and (max-width: X) {
/* less than or equal to X */
}
Using a pen or pencil, block out each element on the page
<picture>
<source srcset="http://placehold.it/800x800" media="(min-width: 800px)">
<source srcset="http://placehold.it/500x500" media="(min-width: 500px)">
<img src="http://placehold.it/200x200" alt="" />
</picture>
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture
CSS Frameworks
Homework review
Use one of the above frameworks to create this website:
Flexbox, in depth
The flexbox layout consists of:
By default, flexbox items are displayed in a row, left-to-right (ltr).
Copy the HTML below into a new pen in Codepen.io
<div class="flex-container">
<div class="flex-item">flex item 1</div>
<div class="flex-item">flex item 2</div>
<div class="flex-item">flex item 3</div>
</div>
We are setting up a flex container with three flex items.
Now copy this CSS.
We're giving our items a width and height (and background color so we can see them).
.flex-container {
}
.flex-item {
background-color: #bada55;
width: 100px;
height: 100px;
margin: 10px;
}
To use the flexbox layout, simply set the display
property on the parent element.
display: flex;
All the items are now flexbox items, and they are aligned LTR in a straight line. Now let's finish our container:
We're going to split up the flexbox properties. The following properties apply to the container.
Display items in a line horizontally or vertically. Values:
Let's try it on our flex container:
flex-direction: row-reverse;
Flex will ignore our items' width by default. Add three more flex items. What happened?
Let's make them wrap. Add this to the flex container:
flex-wrap: wrap;
Shorthand for flex-direction and flex-wrap. Flex direction always goes first.
flex-flow: column nowrap;
- or -
flex-flow: row wrap;
Aligns items along the main axis (x-axis). Values:
Try it out! Delete the three extra items so there are only three. Add the justify-content property to the container.
justify-content: flex-end;
- or -
justify-content: space-between;
Same as justify-content, but along the cross axis (y-axis). Also allows for vertical stretching of items:
Try it out: change the alignment of your elements to stretch:
align-items: stretch;
What happened? Now take the height off of our items and try again...
Here are the properties that apply to the flex items
Allows you to change the order in which items appear, regardless their order in the markup.
The value is any integer. Example:
This property specifies the flex grow factor, which determines how much the flex item will grow relative to the rest of the flex items in the flex container when positive free space is distributed.
Make sense?
Example: All items have the same value for flex-grow:
Here, the second items takes up more room relative to its neighbors:
Simiar to flex-grow. If the item has a set width which is being overwritten by flex, flex-shrink: 0
will allow it to keep its original width.
The auto (the default value) keyword means "look at my width or height property"
Tyr it out: Add three more items so they all get squished, and add a class to one of them.
Next, set that new class to flex-shrink: 0;
. What happened?
Takes same values as width or height. It sets the initial size of a flex item before space is distributed among the other items.
Try it:
What happened?
Put it all together! flex
is a shorthand property for flex-grow
, flex-shrink
, and flex-basis
:
.flex-item {
flex: 0 0 auto
}