Class 2
Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Some "rules":
Thank you to our wonderful TAs!
Course website: http://anything.codes
Instructor contact info: lizs@girldevelopit.com
index.html
file from last week and change My Home to Africaafrica.html
, My Diet to diet.html
, and Stripes to stripes.html
We're going to code several different page templates
border-radius rounds the corners of an element
No image editing required! The border-radius property is part of CSS3 (the latest version of CSS)
Clockwise from the top left
selector {
border-radius: topLeft topRight bottomRight bottomLeft;
}
img {
border-radius: 10px 30px 60px 150px;
}
becomes
selector {
border-radius: topLeftAndBottomRight topRightAndBottomLeft;
}
img {
border-radius: 10px 150px;
}
selector {
border-radius: all;
}
img {
border-radius: 40px;
}
selector {
border-radius: 50%;
}
img {
border-radius: 50%;
}
Note: The element must be square to make a perfect circle.
Otherwise border-radius: 50%;
will make an oval.
Let's make our profile image into a circle
Organize your CSS by section and use comments for each section
/* Header */
header {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: rgba(255, 255, 255, 0.54);
}
nav {
float: right;
}
/* Banner */
#banner {
height: 483px;
}
#banner img {
width:154px;
border-radius: 50%;
}
This will make your life much easier down the road, as you add more CSS
Tired of using the same old, boring "web-safe" fonts?
(No offense, CSSFontStack.com)
Use Google Web Fonts! Google has hundreds of free fonts that have been optimized for the web, and are ready for us to use!
Google Web Fonts don’t rely on fonts installed on users’ computers
Instead, these fonts are stored on Google’s servers and served to your website (like an image from another server is served to your website)
In our design, we've used Lato for the body and Bree Serif for the headlines
You can use any fonts you'd like!
<link>
to your CSS file<link href='https://fonts.googleapis.com/css?family=Lato|Bree+Serif' rel='stylesheet' type='text/css' />
font-family
properties Google provides
body {
font-family: 'Lato', sans-serif;
}
Add some Google Web Fonts to your site
While we're at it, let's also clean up our header and banner/hero to match the design
Developers typically get these measurements from Photoshop
Make your global, site-wide elements first
For example, our project's header, banner/hero, and footer are global, site-wide elements
Recap of display:inline;
versus display:block;
See the Pen Inline vs. Block by Liz Shaw (@anythingcodes) on CodePen.
Block elements push sibling elements to another line. Inline elements allow sibling elements to sit to their right and left.
Our navigation links need:
display
value that doesn't force sibling elements to a new linedisplay:inline;
)display
value whose top and bottom padding is relative to the box itself, not relative to the text baselinedisplay:block;
)But these needs are at odds with one another! 👎
display:inline-block;
display
Inline | Block | Inline-Block | |
---|---|---|---|
Can have a set width & height | ✗ | ✔ | ✔ |
Allow other elements to their left & right (i.e. don't force sibling elements to new line) |
✔ | ✗ | ✔ |
Respect left & right margins | ✔ | ✔ | ✔ |
Respect top & bottom margins & padding | ✗ | ✔ | ✔ |
NEW: By default is as wide as its content | ✔ | ✗ | ✔ |
display:inline-block;
on our navigation's anchor links and add a hover statedisplay:inline-block;
on the banner's span
so we no longer need to set a widthBonus Question: Where is the 16px coming from?
SVG: Scalable Vector Graphic
SVG graphics do not lose any quality if they are zoomed, which is perfect for modern retina displays
By comparison, raster graphics (PNGs, JPEGs, GIFs, etc.) lose quality when zoomed
SVGs are typically used for typography, icons, and other graphics with clearly-defined lines, while raster graphics are typically used for photography
SVGs are often used for animation, since each component of an SVG can be animated with CSS
<img>
Reference the .svg file like any other image:
<img src="image.svg" alt="My image" />
SVG is so new that only modern browsers support it
If you need to support older browsers, save a copy of your SVG as a PNG, then use the PNG as a fallback within the onerror
attribute:
<img src="image.svg" alt="My image" onerror="this.onerror=null; this.src='image.png'" />
Tip: Use caniuse.com to check browser compatibility of modern HTML5 & CSS3 features
Let's add SVG icons to our footer!
Since we need to add a top margin to our <li>
s, display:inline-block;
will also come in handy here.
Browser View
Minimize your browser window. Things should look responsive!
Device View
On an actual device, however, things look rough:
Add a viewport
Without a viewport, mobile devices will render the page at a typical desktop screen width, scaled to fit the screen
Add the following to the <head>
:
<meta name="viewport" content="width=device-width, initial-scale=1" />
Chrome has a built-in emulator where you can preview how your page might look on a device
Other Options
Let's add a viewport to your page!
<meta name="viewport" content="width=device-width, initial-scale=1" />
Once we're done, let's check out the page in Chrome's emulator
The transition
CSS property lets us create awesome animations without any Javascript
Each transition
property value requires:
selector {
transition: width 2s;
}
With a state change (:hover
, :checked
, :focus
, etc.)
Every animation has a before selector and an after selector
Before Selector: The element as it is naturally
After Selector: The element when it is interacted with (e.g. when it is hovered over)
In the before selector, apply transition
along with what properties change during the transition
The after selector indicates the values after a transition is complete. Never use transition
on the after selector.
Before Selector | After Selector | Example |
---|---|---|
|
|
Example (before) » Example (after) » |
|
|
Example (before) » Example (after) » |
Let's add a transition to our navigation menu links!
Additional Animation Effects & Responsive Grid Systems
If you haven't already, try to use each of the CSS properties discussed today!