Network: GoogleGuest
No Password
Girl Develop It is here to provide affordable and accessible programs to learn about web development, design, and research through mentorship and hands-on instruction.
We'll be jumping into HTML/CSS right where the beginner class left off.
We will not be going over the previous class, we just don't have the time!
We'll be using Sublime Text 2 in class today.
Download ST2 from: www.sublimetext.com/2
http://silverli.github.io/intermediate-html-css/
Download the files and follow along with the slides!
We've set up the folder structure for the site today to reflect commonly used practices.
So how do people use HTML/CSS?
Formally, HTML5 is the W3C’s specification for the next version of HTML.
Informally, people use "HTML5" to refer to a whole set of new web standards and abilities:
Members from Apple, Mozilla, & Opera set out to develop HTML5.
First draft is written, but changes are still coming. HTML5 is continually evolving.
Percentage of HTML5 Elements supported:
Too much to cover in our time together
But here are some highlights:
frame, frameset, noframes
)font, big, center
)Gives some old elements semantic meaning and separates them from presentation (e.g.
b, i, strong, em
)
<!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">
<html>
<head></head>
<body>
<header>
<nav></nav>
</header>
<main>
<section></section>
<article></article>
<aside></aside>
</main>
<footer></footer>
</body>
</html>
Some HTML elements have default styles
Different browsers display these things differently. A reset gets rid of these inconsistencies and lets you start from fresh.
Defaults include:
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
list-style: none;
We've done all the hard work for you! Instead of typing this out - we've included this in the reset.css file.
Feel free to use this file on any and all projects you start in the future!
Fixed
Fluid
Wrappers are a good way to center content if the screen width is wider than your content.
.container {
width: 100%; /* take up full viewport width */
max-width: 1400px; /* if viewport is larger than 1440px,
don't let it take up 100% */
margin: 0 auto; /* center content in the viewport */
}
Let's include it in a header, since we know we'll be grouping related content here.
Remember, using fixed position is like using absolute position, except that it's fixed to the viewport, not the containing element.
We also have to define a width for it, and its location.
nav {
position: fixed;
top: 0;
left: 0;
background: #fafafa;
border-bottom: 2px solid #ccc;
height: 70px;
width: 100%;
}
Because we've fixed the nav to the top of the viewport, we need to bump the content of the
body
down to be visible to the user.
This should be the same, or more than, the height of the navigation bar.
body {
padding-top: 70px;
}
nav {
position: fixed;
top: 0;
left: 0;
background: #fafafa;
border-bottom: 2px solid #ccc;
height: 70px;
width: 100%;
}
Now we need to get those list items next to each other instead of stacked.
Let's float them to the left and add some padding to the links so they have a large clickable 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;
}
We can use an
H1
with text replacement to include a brand, or logo, in the corner that will still work if images are turned off, making it accesible to screen readers.
#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;
}
Notice how the edge of the nav bumps up against the edge of the browser? Let's fix that by adding a container around it.
Let's give the container a fixed width and see what happens.
.container {
width: 1024px;
margin: 0 auto;
}
Now wherever we use
.container
it will be 1024px wide and centered.
Let's make some small tweaks to the navigation
text-decoration
Our Hero
section
should look a little something like this:
<section class="hero">
Intermediate HTML & CSS
</section>
.hero {
position: relative;
margin-top:15px; /*this will depend on the height
of your fixed nav*/
}
.hero img {
width: 100%;
}
It's all about position
This will put your text to the right and bottom of the hero
.hero h2 {
position: absolute;
bottom: 25px;
right: 30px;
}
This will put your text in the center of the hero
.hero {
position: relative;
text-align: center;
}
.hero h2 {
position: absolute;
left: 0;
right: 0;
}
Okay, it's not really magic, it's just a bit of CSS3.
Simply put, allows you to create rounded corners on boxes.
Designers rejoice!
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%;
}
Put some border radius on anything!
You could put it on an:
HTML5 and CSS3 are still new!
This is great, but it means that not all browsers treat new CSS3 properties the same
Flags it as a work-in-progress
When finished, the browser should support the non-prefixed name
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
Because it's a comfortable width for readability.
And because 3 is a pleasing design construct.
Our code should look something like this:
<main class="main-content">
...
<section class="column">
..content here...
</section>
<section class="column">
..content here...
</section>
<section class="column">
..content here...
</section>
</main>
Now that we have our 3 columns, we want them to appear next to each other. We can do this by floating them all left.
.column {
float: left;
width: 30%;
padding-right: 2.5%;
}
.column:first-of-type {
padding-left: 2.5%;
}
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%;
}
There we go!
We've got our 3 column layout set, our images are scaled based on the width of the column, but our columns are still bumping against the edges of the browser.
<section id="main-content">
...
<section class="column">
...
</section>
<section class="column">
...
</section>
<section class="column">
...
</section>
</section>
Adding the container, which we already defined the width of, makes everything line up.
Let's play around with these columns a bit more:
You could:
RWD is a design approach that suggests that the design & development of a site shoud respond to the user's behavior and environment.
RWD modifies the presentation of a site, without modifying the content of the page. So no matter what, every user has access to the same information.
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 resolution.
Text scales easily on smaller devices, but images are a bit tricky.
Images will overflow their container elements if they're too big for them.
That's annoying.
By using max-width on images, they will only expand to the size of their parent.
If their parent has no width, it will just expand to the width of the viewport.
img {
max-width: 100%;
}
Media queries apply certain CSS in certain situations.
They will overwrite previous styles because they are last in the cascade.
I prefer to just think about max-width (get's too confusing, and that way, we're thinking mobile first)
@media only screen and (max-width : 480px) {
/* Styles */
}
For screens that are under 480px
@media only screen and (max-width : 1024px) {
/* Styles */
}
For screens that are under 1024px
Rather than looking for a type of device, they look at the capability of the device. You can use them to check for all sorts of things.
By designing sites with mobile first in mind, it makes scaling them down a lot easier.
Mobile first allows us to simplify the user flow to its basic elements and then enhance it as the screen size increases.
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.
Luckily, we've already added this for you!
Designers everywhere have always wanted to use vector based graphics on their sites because of their quality.
Well now you can!
It's been a W3C (World Wide Web Consortium) standard since 1999
In recent years browsers are becoming more and more compatable with SVG graphics.
Once upon a time, .png graphics weren't supported in browsers, soon the world will know about SVG!
Use Adobe Illustrator, or other vector program, to create a high quality image.
Save it as a .svg file.
Save a high res .png image as a fallback.
Use SVG as an image:
<img src="image.svg" alt='Cat'>
Use SVG as a background image:
HTML:
<a href="/" class="logo">
GDI
</a>
CSS:
.logo {
display: block;
width: 100px;
height: 82px;
background: url(image.svg);
background-size: 100px 82px;
}
Inline SVG
<section
<svg>
<g class='twitter'></g>
<svg>
</section>
You'll need to add a class to the g element. (We'll talk about that in a moment).
Rather than going into illustrator to change colors and borders of SVG, you can do it in CSS!
Some attributes:
Our favorite topic - Internet Explorer
Chris Coyer has written an amazing article with tons of work arounds for IE8.
Now that we know how awesome SVG graphics are, let's use them in our footer section.
We've included facebook, instagram, linked in, and twitter svgs in your images folder
The world of HTML has progressed beyond Times New Roman and Arial
Yay!
How do we use new and cool fonts?
Google has hundreds of free, open-source fonts that have been optimized for the web, and ready for us to use!
The service runs on Google's servers which are fast, reliable and tested. Google provides this service free of charge.
In our example, we've used Lato for the body and Bree Serif for the headlines
You can use any font you'd like!
@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
to refine your fonts.
#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;
}
Adds a drop shadow to an element
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; }
.element {
color: blue;
transition: blue 1s ease-in 0.5s;
/* transition: property duration timing function delay;*/
}
the number of seconds or milliseconds a transition animation should take to complete
2s duration
delay transitions from the moment a trigger happens
determines how intermediate values are calculated
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;
(Very similar to transitions and transforms)
img:hover, img:focus {
animation: 1s jumpTrophy 0.3s ease-in 1;
/* animation: duration keyframe-name
delay timing-function iteration-count */
}
@keyframes jumpTrophy {
0%, 20%, 50%, 80%, 100% {
transform: translateY(0);
}
40% {
transform: translateY(-30px);
}
60% {
transform: translateY(-15px);
}
}
See this example live: here
Build gradients with CSS - because doing it with images is annoying!
.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);
}
That's why people have made things like the Ultimate CSS Gradient Generator to make our lives easier!
Add a background gradient to a section of your site
Download a pre-built framework that has basic styles already set up.
By far the most popular front-end framework out there.
Another very popular framework that is just as robust at bootstrap - but in a different way.
These are two very popular CSS preprocessors
CSS preprocessors take code written in the preprocessed language and then convert that code into the same old css we’ve been writing for years.
Since we're not writing straight CSS, we're not limited to the restrictions of the language.
Mixins!
/* LESS */ .rounded-corners (@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
-ms-border-radius: @radius;
-o-border-radius: @radius;
border-radius: @radius;
}
#footer {
.rounded-corners(10px);
}
/* Compiled CSS read by the browser */
#footer {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-ms-border-radius: 10px;
-o-border-radius: 10px;
border-radius: 10px;
}
// LESS
#header {
h1 {
font-size: 26px;
font-weight: bold;
}
p { font-size: 12px;
a { text-decoration: none;
&:hover { border-width: 1px }
}
}
}
/* Compiled 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;}
LESS
p {
color: lighten(@base, 5%);
}
SASS
p {
color: hsl($hue: 0, $saturation: 100%, $lightness: 50%);
}
LESS
// LESS
@blue: #199FD9;
p {
color: @blue;
}
// Compiled CSS
p {
color: #199FD9;
}
SASS
// SASS
$blue: #199FD9;
p {
color: $blue;
}
// Compiled CSS
p {
color: #199FD9;
}
Please take this and help us improve future GDI classes and offerings!
Intermediate HTML/CSS Class Survey