Network:
Password:
All slides are available at:
https://erindepew.github.io/gdi-featured-html-css-intermediate/#/Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
We've set up the folder structure for the site today to reflect common practices used.
Different browsers display HTML elements differently
A reset file returns all HTML elements to a baseline style
Examples include:
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
list-style: none;
Each browser has their own:
.hero img {
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
-ms-border-radius: 50%;
-o-border-radius: 50%;
border-radius: 50%;
}
Order matters! The non-prefixed version should always go last.
While you should always use the vendor prefixes when writing code, today we're just going to use the non-prefixed property.
This is to save time during the code exercises
* not recommended for professional web development
<!DOCTYPE html>
Minimum information required to ensure that a browser renders using standards mode
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Technically, you can name an element anything:
But you should use a div with a semantic class name
Remember, it's squares all the way down
Even when we break the grid
Developer plugin to view the internet like a web crawler
CSS grid new spec for complex layouts without flexbox
This is a very popular UX for navigation because:
However, can often take up valuable screen real-estate and require complicated loading scripts for different devices
nav {
position: fixed;
top: 0;
left: 0;
background: #fafafa;
border-bottom: 2px solid #ccc;
height: 70px;
width: 100%;
}
position: static
) parentposition
property in action
position: fixed
means we need to move the body
content down in order to prevent the navigation from overlapping
body {
padding-top: 70px;
}
nav {
position: fixed;
top: 0;
left: 0;
background: #fafafa;
border-bottom: 2px solid #ccc;
height: 70px;
width: 100%;
}
Align navigation elements and increase click area*
nav {
position: fixed;
top: 0;
left: 0;
background: #fafafa;
border-bottom: 2px solid #ccc;
height: 70px;
width: 100%;
}
nav li {
float: left;
width: auto;
}
nav li a {
padding: 25px 10px;
display: block;
}
* The recommended minimum click area is 44x44px for accessibility, for more standards check out Web Accessibility Initiative
We can use an
H1
with text replacement to display our logo
.brand {
color: transparent;
background: url(../images/z.png) no-repeat top left;
height: 60px;
width: 60px;
float: left;
margin: 5px;
}
nav ul {
float: right;
width: auto;
}
We also need to account for large monitors, let's control the width of our page with a container
Let's give the container a fixed width and see what happens.
.container {
width: 1024px;
margin: 0 auto;
}
Let's make some small tweaks to the navigation
text-decoration
<section class="hero">
IMA Zebra
Africa
</section>
.hero {
background: url(../images/zebra.jpg) no-repeat top left;
color: #fafafa;
text-align: center;
height: 350px;
padding: 25px 0;
}
Remember our Box Model. Padding adds to the height & width of elements.
So the height of our hero will be
400px
.hero img {
width: 150px;
}
20px radius on all corners
.hero img {
border-radius: 20px;
}
10px radius on top left & bottom right
40px on top right & bottom left
.hero img {
border-radius: 10px 40px;
}
10px radius on top left
20px radius top right
40px radius bottom right
80px radius bottom left
.hero img {
border-radius: 10px 20px 40px 80px;
}
50% radius on all corners
.hero img {
border-radius: 50%;
}
.hero {
background: url(../images/zebra.jpg) no-repeat top left;
color: #fafafa;
text-align: center;
height: 350px;
padding: 25px 0;
background-size: cover;
}
cover
scales the image to the largest size such that both its width and its height can fit inside the content area.
Let's make some small tweaks to the Hero
Commonly used layout due to:
<section class="main-content">
...
<section class="column">
<img src="images/africa.png" alt="Africa">
<h4>My Home</h4>
<p>Wild zebras live in Africa.</p>
<a href="home.html" class="btn">See my home</a>
</section>
<!-- Repeat .column x3 -->
</section>
.column {
float: left;
width: 30%;
padding: 15px;
}
100% width / 3 columns = 30% column width
Images won't scale with the columns, because they ignore constraints like
div
width, unless you tell them to do so.
.column img {
width: 90%;
max-width: 90%;
border-radius: 50%;
}
Make sure the columns are inside of our container div in order to preven them from stretching too far
Why not wrap everything in a separate container?
Because DRY: Don't Repeat Yourself
Let's make some small tweaks to the columns
Every image file format has their advantages and disadvantages, but general rule of thumb:
Use Adobe Illustrator, or another vector program, to create a high quality image.
Save it as a .svg file.
Compress the svg file for web using SVGOptimizer
Image source:

Embed:
Background image:
.logo {
display: block;
color: transparent;
width: 100px;
height: 82px;
background: url(logo.svg);
background-size: 100px 82px;
}
</section> class="social">
<ul>
<li>
<a href="..">
<img src="images/facebook.svg" alt="Facebook" />
</a>
</li>
<!-- Repeat for all social links you want to include -->
</ul>
</section>
.social {
background: #57BEC5;
color: #fafafa;
padding: 25px 0;
overflow: hidden;
}
.social li {
float: left;
width: auto;
padding: 20px;
}
First we should put our social links in a container! We'll also add in a headline.
<section id="social">
<div class="container">
<h3>...</h3>
<ul>
...
</ul>
</div>
</section>
Next we'll center the
ul
with a very flexible technique that will allow us to have a list of any width
Very broad topic with lots of exciting developments: Web Typography & Layout: Past, Present, and Future
But for today, we're just going to focus on how to use them
Professional sites will often have custom designed fonts hosted on their own servers
For the rest of us, Google offers free, web-optimized, hosted fonts
In our example, we've used Lato for the body and Bree Serif for the headlines
@import url(http://fonts.googleapis.com/
css?family=Lato:300,400,700,300italic,400italic|Bree+Serif);
What does that do?
body{
font-family: 'Lato', sans-serif;
}
h1, h2, h3, h4, h5, h6 {
font-family: 'Bree Serif', serif;
}
font-size
and line-height
rgba = Red Green Blue Alpha
Alpha controls the alpha channel of a color, aka the opacity
opacity
controls the opacity of an element
Opacity is always a decimal value from 0 (transparent / not visible) - 1 ( fully visible)
#example1 { text-shadow: 2px 2px 10px red; }
#example2 {
text-shadow: 1px 1px 10px red,
10px 10px 10px orange,
15px 15px 10px yellow,
20px 20px 10px green,
25px 25px 10px blue,
30px 30px 10px purple;
}
box-shadow: offset-x offset-y color
.example1 { box-shadow: 5px 5px red; }
box-shadow: offset-x offset-y blur spread color
.example { box-shadow: 0 0 5px 5px red; }
box-shadow: offset-x offset-y blur spread color
.example { box-shadow: 0 2px 5px 0px red; }
.linear-example1 {
background-image: linear-gradient(red, orange, yellow, green, blue, indigo, violet);
}
.linear-example2 {
background-image: linear-gradient(right, red, orange, yellow, green, blue, indigo, violet);
}
.linear-example3 {
background-image: linear-gradient(bottom right, red, orange, yellow, green, blue, indigo, violet);
}
.linear-example4 {
background-image: linear-gradient(red, white);
}
.linear-example5 {
background-image: linear-gradient(right, red, white);
}
.linear-example6 {
background-image: linear-gradient(bottom right, red, white);
}
.radial-example1 {
background-image: radial-gradient(circle cover, red, orange, yellow, green, blue, indigo, violet);
}
.radial-example2 {
background-image: radial-gradient(0 0, circle, red, orange, yellow, green, blue, indigo, violet);
}
.radial-example3 {
background-image: radial-gradient(0 50%, circle, red, orange, yellow, green, blue, indigo, violet);
}
.radial-example4 {
background-image: radial-gradient(circle cover, red, white);
}
.radial-example5 {
background-image: radial-gradient(0 0, circle, red, white);
}
.radial-example6 {
background-image: radial-gradient(0 50%, circle, red, white);
}
The names of CSS properties that should be transitioned
.example1 { transition-property: background-color; }
Set to all to transition all CSS properties
.example2 { transition-property: all; }
The number of seconds or milliseconds a transition animation should take to complete
.example1 { transition-duration: 2s; }
2s duration
delay transitions from the moment a trigger happens
.example1 { transition-delay: 0s; }
.example2 { transition-delay: 1s; }
.example3 { transition-delay: 2s; }
.example4 { transition-delay: 3s; }
determines how intermediate values are calculated
.example { transition-timing-function: ease; }
Lucky for us, someone has created a tool that makes our lives easier.
scales the element
transform: scale(sx[, sy]);
rotates the element degrees around its origin
transform: rotate(angle);
move element using x and y coordinates
transform: translate(ax[, ay]);
the x and y origin for transformation
transform-origin: x-offset y-offset;
RWD is a design approach that suggests that the design & development of a site should respond to the user's behavior and environment.
RWD allows for every user to have access to the same content
With fixed-width sites, we have to adjust the height and width of elements manually.
With fluid grids, the height and width of elements is dependent upon the device height and width.
Images expand to the width of their parent
img {
max-width: 100%;
}
Media queries apply certain CSS in certain situations, we can target
Media queries should come last because they will overwrite other styles in the cascade
#header-image CSS
Larger image for screens > 1200px wide
Hide image for print media
Device width >= 320px and < 480px
/* Smartphones (portrait and landscape) */
@media only screen and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
Device width >= 768px and < 1024px and orientation landscape
/* iPads (landscape)*/
@media only screen and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
Use this to control the size of the viewport.
<meta name="viewport" content="width=device-width,
user-scalable=true;">
Width=device-width makes the viewport the size of the device.
User-scalable=true allows the user to pinch and zoom on your site.
Retina screens have twice the pixel density than regular screens.
Requires two images: one for retina and one fore regular screens
Exception is SVG because it's a vector graphic
@media
(-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
/* Retina-specific stuff here */
}
Regular resolution icon
2x resolution icon
@media
(-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
.icon {
background-image: url(images/icon-2x.png) no-repeat 0 0;
background-size: 20px 20px;
}
}
Download a pre-built framework with built-in basic styles
.pull-right
, .btn
, etc.CSS preprocessors transpile code
Sass => transpilation => CSS
/* SASS */
@mixin rounded-corners(@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
-ms-border-radius: @radius;
-o-border-radius: @radius;
border-radius: @radius;
}
#footer {
@include rounded-corners(10px);
}
/* CSS */
#footer {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-ms-border-radius: 10px;
-o-border-radius: 10px;
border-radius: 10px;
}
/* SASS */
#header {
h1 {
font-size: 26px;
font-weight: bold;
}
p { font-size: 12px;
a { text-decoration: none;
&:hover { border-width: 1px }
}
}
}
/* CSS */
#header h1 {font-size: 26px;font-weight: bold;}
#header p {font-size: 12px;}
#header p a {text-decoration: none;}
#header p a:hover {border-width: 1px;}
/* SASS */
@function lighten($color, $amount) {
//function code here
@return $hex-value
}
p {
color: lighten(@base, 5%);
}
/* CSS */
p {
color: #fff00;
}
/* SASS */
$blue: #199FD9;
p {
color: $blue;
}
}
/* CSS */
p {
color: #199FD9;
}