diff --git a/html-css-intermediate/index.html b/html-css-intermediate/index.html index dcdc9d5..1b8b224 100755 --- a/html-css-intermediate/index.html +++ b/html-css-intermediate/index.html @@ -4,10 +4,10 @@
-All slides are available at:
- http://girldevelopit.github.io/gdi-featured-intermediate-html-css/
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.
-Some "rules"
-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!
+Last reminder to download the files for today's class!
+We've set up the folder structure for the site today to reflect common practices used.
We've provided a copy of the site you'll be building today with notes on how to break down the layout of the page.
-HTML & CSS are awesome, right?
-But how do people use them - really? -
Here's a few things we'll be covering today:
-Even though HTML is the structure and CSS is the design, some HTML elements have default styles
-Different browsers display these things differently. A reset gets rid of these inconsistencies.
+Different browsers display HTML elements differently
+A reset file returns all HTML elements to a baseline style
Examples include:
@@ -164,7 +173,7 @@
@@ -184,169 +193,78 @@ Reset CSS
We've done all the hard work for you! Instead of typing this out - we've included this in our example files.
-- Fixed -
+Each browser has their own:
- 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: 1440px; /* if viewport is larger than 1440px,
- don't let it take up 100% */
- margin: 0 auto; /* center content in the viewport */
- }
-
- 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: -
.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.
Members from Apple, Mozilla, & Opera set out to develop HTML5.
First draft is written, but changes are still coming. HTML5 is continually evolving.
-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
Percentage of HTML5 Elements supported:
+* not recommended for professional web development
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
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
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;
@@ -463,11 +405,27 @@ Fixed Nav: CSS
width: 100%;
}
position: static
) parentposition
property in action
+ 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.
+position: fixed
means we need to move the body
content down in order to prevent the navigation from overlapping
body {
padding-top: 70px;
@@ -484,8 +442,7 @@ Fixed Nav: CSS
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.
+Align navigation elements and increase click area*
nav {
position: fixed;
top: 0;
@@ -504,15 +461,23 @@ Fixed Nav: CSS
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 include a brand, or logo, in the corner that will still work if images are turned off, making it accesible to screen readers.
H1
with text replacement to display our logo
#brand {
+ .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;
@@ -540,43 +505,40 @@ Fixed Nav: Text replacement & H1s
Why Text Replacement?
- - If we turn the CSS off for this page - the title will still be visible to the browser.
- - If a user is coming to our site with a screen reader - the title of the site will be readable to them
- - Search engines ♥ it!
+ - If CSS doesn't load - the title will still be visible to the browser.
+ - If a user is using a screen reader - the title of the site will be readable to them
+ - Improves SEO of our site
Fixed Nav: Container
- 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.
+ We also need to account for large monitors, let's control the width of our page with a container
-
-
-
+
+
+
+
+
Fixed Nav: Container
- Let's give the container a fixed width and see what happens.
+ 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.
-
Develop It!
- Let's make some small tweaks to the navigation
+
Let's make some small tweaks to the navigation
- Remove the underlines on the links with
text-decoration
@@ -586,14 +548,18 @@ Develop It!
+
+ Break Time
+
+
Hero Section
What is a Hero?
- - Large banner image, prominently placed on a web page, generally in the front and center
- - First visual a visitor encounters on the site and its purpose is to present an overview of the site's most important content
+ - Large banner image
+ - First impression of a site used to display the most important information
- Often consists of image and text, can be static or dynamic
@@ -619,158 +585,78 @@ Hero Examples
Our Hero
- section
should look a little something like this:
<section id="hero">
+ <section class="hero">
IMA Zebra
Africa
-</section>
-
Now is where the fun really happens!
-#hero {
- background: url(../images/zebra-hero.jpg) no-repeat top left;
- color: #fafafa;
- text-align: center;
-}
-
+</section>
Let's give it a height and some padding too.
-#hero {
+ .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
+
+ Remember our Box Model. Padding adds to the height & width of elements.
+So the height of our hero will be
400px
Things that are wrong with this hero right now: -
Let's make the profile image a little smaller.
-We'll use CSS Targeting with the descendant selector to style the image.
-#hero img {
+ .hero img {
width: 150px;
}
- That should do it
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 {
+ 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 {
+ 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 {
+ 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 {
+ 50% radius on all corners
+ .hero img {
border-radius: 50%;
}
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
-Notice how the image is too large for the section? Let's fix that with a new property called
- background-size
-
#hero {
+ .hero {
background: url(../images/zebra.jpg) no-repeat top left;
color: #fafafa;
text-align: center;
@@ -779,13 +665,13 @@ Background-size
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 +
Let's make some small tweaks to the Hero
Because 2 columns is so 2013
-Or, because it's a comfortable width for readability. And because 3 is a pleasing design construct.
+Commonly used layout due to:
+Our code should look something like this:
-<section id="main-content">
+ <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>
+ </section>
<!-- Repeat .column x3 -->
-</section>
+</section>
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: 15px;
}
- We used 30%, because it lets us perfectly spaced columns without doing math! Don't forget padding (or margin) to give the columns some space.
+100% width / 3 columns = 30% column width
The images didn't scale with the columns, because they ignore constraints like +
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!
-Let's add a border radius to it too, because we ♥ circles
-.column img {
- width: 90%;
- max-width: 90%;
border-radius: 50%;
}
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.
+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 these columns +
Let's make some small tweaks to the columns
Designers everywhere have always wanted to use vector based graphics on their sites because of their quality.
-Well now you can!
+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
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!
+Image source:
+
Use Adobe Illustrator, or another vector program, to create a high quality image.
-Save it as a .svg file.
-Save a high res .png image as a fallback.
+Embed:
+
+
+
+
Use SVG as an image:
-<img src="image.svg" onerror="this.onerror=null; this.src='image.png'">
- Use SVG as a background image:
-HTML:
-<a href="/" class="logo">
- GDI
-</a>
- CSS:
+Background image:
+
.logo {
display: block;
color: transparent;
width: 100px;
height: 82px;
- background: url(kiwi.svg);
+ background: url(logo.svg);
background-size: 100px 82px;
}
Our favorite topic - Internet Explorer
-Chris Coyer has written an amazing article with tons of work arounds for our BFF IE8.
-Now that we know how awesome SVG graphics are, let's use them in our social links section.
-<section id="social">
+ </section> class="social">
<ul>
<li>
<a href="..">
@@ -933,26 +803,24 @@ Social Links: HTML
</ul>
</section>
- We're using a list for these links for the exact same reason we used them in the navigation. They are a list of links, and should be marked up accordingly.
We'll need to add a background, some padding, account for the floated list items.
-#social {
+ .social {
background: #57BEC5;
color: #fafafa;
padding: 25px 0;
overflow: hidden;
}
-#social li {
+.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.
+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>
@@ -961,7 +829,7 @@ Centering the List
</ul>
</div>
</section>
- Next we'll center the +
Next we'll center the
ul
with a very flexible technique that will allow us to have a list of any width
The world of HTML has progressed beyond Times New Roman and Arial
-Yay!
-How do we use new and cool fonts?
+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
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.
-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
-You can use any font you'd like!
+In our example, we've used Lato for the body and Bree Serif for the headlines
@import url(http://fonts.googleapis.com/
@@ -1015,7 +875,7 @@ Using Google Fonts in 3 steps!
body{
font-family: 'Lato', sans-serif;
@@ -1027,23 +887,28 @@ Integrating into the CSS
Pick some fonts for your site using Google Fonts.
-Adjust the
- font-size
and
- line-height
to refine your fonts.
font-size
and line-height
In CSS, we can choose colors with hexadecimal #0000FF or rgb(0, 0, 255)
-In CSS3, there are ways to control opacity of a color too!
+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)
+controls the opacity of a color
-
-.example2 {
- background-color: rgba(255, 0, 0, 0.8);
-}
-
- color property using (red, green, blue, opacity)
-opacity is a decimal value from 0 to 1
-controls the opacity of an element
-
-.example2 {
- opacity: 0.8;
-}
-
- decimal value from 0 to 1
-Change some colors to have alpha transparency or opacity.
-Use http://hex2rgba.devoth.com/ to convert HEX to RGBA.
-Hint: Try making the navbar 80% opaque.
- +#example1 { text-shadow: 2px 2px 10px red; }
@@ -1157,13 +993,9 @@ text-shadow
Box Shadow
-
- box-shadow
- Adds a drop shadow to an element
-
box-shadow
- box-shadow: offset-x offset-y color
+ box-shadow: offset-x offset-y color
.example1 { box-shadow: 5px 5px red; }
@@ -1194,16 +1026,17 @@ Develop It!
Add shadows to your text
Remember: Be subtle!
Add a box-shadow to the nav
-
+
+
+
+
+ Break Time
+
-
+
CSS Gradients
-
-
- Gradients
- Build gradients with CSS - because doing it with images is annoying!
Linear gradients
@@ -1286,24 +1119,36 @@ Radial gradients
- CSS gradients are a pain to do from scratch
- That's why people have made things like the Ultimate CSS Gradient Generator to make our lives easier!
+ CSS Gradient Generator
+ Ultimate CSS Gradient Generator
-
+
Develop It!
-
- Add a background gradient to a section of your site
+
+ - Add a background gradient to a section of your site
+
-
+
Transitions
- Allow property changes in CSS values to occur smoothly over a specified duration
- Create some awesome effects without any JavaScript
-
+
the names of CSS properties that should be transitioned
+The names of CSS properties that should be transitioned
.example1 { transition-property: background-color; }
- set to all to transition all CSS properties
+Set to all to transition all CSS properties
.example2 { transition-property: all; }
- full list of supported properties -
+the number of seconds or milliseconds a transition animation should take to complete
+The number of seconds or milliseconds a transition animation should take to complete
.example1 { transition-duration: 2s; }
@@ -1393,14 +1240,19 @@ Pick a transition property and apply it to an element.
-Hint: The transition will only work if it has a pseudo class, like :hover
+Pick a transform property and apply it to an element.
-Hint: The transforms, like transitions, will only work if the element has a pseudo class, like :hover
-Extra Credit: Use it with transition to make the transform smoother.
+RWD is a design approach that suggests that the design & development of a site shoud respond to the user's behavior and environment.
+RWD is a design approach that suggests that the design & development of a site should 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.
+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 resolution.
+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.
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.
+Images expand to the width of their parent
img {
max-width: 100%;
}
Media queries apply certain CSS in certain situations.
+Media queries apply certain CSS in certain situations, we can target
They will overwrite previous styles because they are last in the cascade.
-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
+For devices that have dimensions no smaller than 320px and are not larger than 480px
+Device width >= 320px and < 480px
/* Smartphones (portrait and landscape) */
-@media only screen and (min-device-width : 320px)
+@media only screen and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
-iPad dimensions with the orientation in landscape.
-/* iPads (landscape) ----------- */
-@media only screen and (min-device-width : 768px)
-and (max-device-width : 1024px)
+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 */
}
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,
+ 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.
+Width=device-width makes the viewport the size of the device.
+User-scalable=true allows the user to pinch and zoom on your site.
Let's take a look at our site now on a phone (or you can resize your browser), and find ways to improve it.
-Add the viewport meta tag to the html.
-Use media queries to shift elements around on the page and to increase legibilty.
+Retina screens have twice the pixel density than regular screens.
-If you're not using SVG Graphics, you'll need two images, one for regular resolution and one for retina.
+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
Target only retina screens by using this media query:
-@media
-(-webkit-min-device-pixel-ratio: 2),
-(min-resolution: 192dpi) {
+@media
+(-webkit-min-device-pixel-ratio: 2),
+(min-resolution: 192dpi) {
/* Retina-specific stuff here */
}
- This takes care of two things, 2x pixel ratio on iOS devices and "high res" Android screens.
@media
-(-webkit-min-device-pixel-ratio: 2),
-(min-resolution: 192dpi) {
+@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;
@@ -1670,63 +1515,72 @@ 2x Images
}
- Or, you could just use SVG
+ Break Time
+
-
- Responsive frameworks
- Download a pre-built framework that has basic styles already set up.
+ Responsive Frameworks
+ Download a pre-built framework with built-in basic styles
- Fluid grids
- Flexible images
- Responsive media queries
- - Styles for buttons and forms, because they're a pain!
- - Lots of base styles like .pull-right, .btn, etc.
+ - Lots of base styles like
.pull-right
, .btn
, etc.
Bootstrap
- By far the most popular front-end framework out there.
-
+
Foundation
- Another very popular framework that is just as robust at bootstrap - but in a different way.
- What they include
+ What They Include
- Fully responsive out of the box
- - Embraces Mobile First standards
+ - Embraces mobile first standards
- Compiled CSS for all sorts of components
- - LESS or SASS stylesheets for rapid updates
+ - SASS stylesheets for rapid updates
- Javascript for popular components
- Pre-set styles for icons and buttons
- - Includes Glyphic icon set (awesome!)
+ - Includes Glyphic icon set
+
+
+
+ And a Few New Ones...
+
+ - Semantic UI
+ - Materialize
+ - Material UI
+ - Pure CSS
+ - Skeleton
+ - UIkit
+ - Milligram
- What are the cons?
+ Drawbacks of Using a UI Framework
- Default styles are ... default and not very exciting
- - Requires a fair amount of customization to make a unique looking site
+ - Requires hacks to make a unique looking site
- The documentation is daunting and can be very indimidating
- - Remembering all the class names can be overwhelming
+ - Frameworks add bloat and weight to site
+ - Difficult to refactor and switch to custom UI later on
+
+ SASS
+
- LESS & SASS?!
- These are two very popular CSS preprocessors
+ What is a CSS Preprocessor?
+ CSS preprocessors transpile code
+ Sass => transpilation => CSS
-
- What the what is a CSS Preprocessor?
- 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.
-
What they do
@@ -1741,9 +1595,11 @@ What they do
- Some highlights
- Mixins!
-/* LESS */ .rounded-corners (@radius: 5px) {
+ Mixins
+
+/* SASS */
+
+@mixin rounded-corners(@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
-ms-border-radius: @radius;
@@ -1752,11 +1608,13 @@ Some highlights
}
#footer {
- .rounded-corners(10px);
-}
+ @include rounded-corners(10px);
+}
+
- /* Compiled CSS read by the browser */
- #footer {
+/* CSS */
+
+#footer {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-ms-border-radius: 10px;
@@ -1766,7 +1624,8 @@ Some highlights
Nested Rules
-// LESS
+
+/* SASS */
#header {
h1 {
@@ -1779,47 +1638,107 @@ Nested Rules
}
}
}
-/* Compiled CSS */
+
+/* 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;}
-
+
Functions
- LESS
-p {
+
+/* SASS */
+
+@function lighten($color, $amount) {
+ //function code here
+ @return $hex-value
+}
+
+p {
color: lighten(@base, 5%);
}
- SASS
-p {
- color: hsl($hue: 0, $saturation: 100%, $lightness: 50%);
+
+/* CSS */
+
+p {
+ color: #fff00;
}
Variables
- LESS
-// LESS
-@blue: #199FD9;
-p {
- color: @blue;
-}
-// Compiled CSS
-p {
- color: #199FD9;
-}
-SASS
-// SASS
+
+/* SASS */
+
$blue: #199FD9;
+
p {
color: $blue;
}
-// Compiled CSS
+}
+
+/* CSS */
+
p {
color: #199FD9;
}
+
+
+
+ Resources
+
+
+
+ Resources
+
+
+
+ Resources
+
+
+
+ Resources
+
+ - Materialize
+ - Material UI
+ - Pure CSS
+ - Skeleton
+ - UIkit
+ - Milligram
+