11/1/2018

Font Libraries

You don't have to settle with the default fonts that are on your machine for web pages. Adding a custom font to your website is very easy process to do.

First checkout what you can already use.

CssFontStack.com

Step 1

Find a font you have permission to use your website and include the files in your project.

Step 2 - Declare a font-face in your css


@font-face {
    font-family: my-font-name;
    src: url(path/to/font.eof),
        url(path/to/font.woff),
        url(path/to/font.woff2)

}
    

Step 3 - Done

You can use your font immediately after declaring the font-family in your CSS


        .css{
            /*Make sure you include a fallback */
            font-family:my-font-name, Arial, sans-serif;
        }
        

Custom Font Drawbacks

There is always a cost doing something fancy on the web. Custom fonts are the same way.

  • Slows down page load
  • Flash of default font type or no font at all.
  • Inconsistent experiences in different browsers.

Self Hosting Alternatives

These are some alternatives to using a self hosted font type. These are traditionally more optimized for the web world.

Google Font Installation


    
        
    .my-div{
        font-family: 'Roboto', sans-serif;
    }

Icon Font Libraries

Icon Font Libraries are an incredible way to speed up your development time and spend less time cutting out small images.

What is an Icon Font Library

It takes a set of Scalable Vector Graphic icons and compresses them into a font file for you to use.

  • Chevron
  • Bars
  • Facebook
  • Cog
  • Flag

Advantages

  • Fewer web requests
  • Easy to use
  • Scalable
  • CSS manipulation

Disadvantages

  • 1 heavy web request
  • Many icons, but may only need 4 or 5
  • Icons may not match branding

Popular Icon Libraries

Make your own

IcoMoon

Using FontAwesome


       
    

        
        
        
        
        
        
     
    
More Examples

Questions?

CSS Flexbox

Flexbox provides a more predictive page layout for responsive screens. It doesn't use floats and adjusts to the available space better than traditional floats. Flexbox aims to fill all available space without overflowing its container.

It has gained a lot of popularity over the years. It doesn't support older versions of IE.

Flex Container

The flex container is the element that is wrapping all of the items you want to align.

Implementing

To implement Flexbox, we need to apply a property to a container.


    .container{
        display:flex;
    } 
        

Code

See the Pen UA-Flex-Flex by Jon (@Middaugh) on CodePen.

Flex Direction

Flex Direction is a relatively unique CSS property. It dictates the actual direction and orientation.

  • row default - flows content from left to right
  • row-reverse - flows from right to left
  • column - vertically orients content from top to bottom
  • column-reverse - vertically orients content from bottom to top

Flex Direction

See the Pen UA-Flex-Flex-Direction by Jon (@Middaugh) on CodePen.

Flex Wrap

By default, flex will want to fit everything into one row/column. Flex wrap allows the flex items to wrap if needed.

  • nowrap - default - All on one line
  • wrap
  • wrap-reverse

Flex Wrap

See the Pen UA-Flex-Flex-Wrap by Jon (@Middaugh) on CodePen.

Justify Content

Justify Content defines how flex items are aligned across the main axis.

  • Row - horizontal axis
  • Column - vertical axis
  • flex-start default - align to the start of the container
  • flex-end - aligns to the end of the container
  • center - items are aligned to the center. Similar to margin:auto
  • space-between Items become even spaced. First items butts up against start point and last element butts up against the end point.
  • space-aroundItems are evenly spaced through out the available space.

Justify Content

See the Pen UA-Flex-Justify-Content by Jon (@Middaugh) on CodePen.

Flex Align

Flex align defines how items are positioned over the intersecting axis.

  • stretch - Fill the container
  • flex-start - positions items in very start of the flex container
  • flex-end - positions elements at the very end of the flex container
  • center - centers items based on their overall height
  • baseline - aligns based off the content

Flex Align

See the Pen UA-Flex-Flex-Align by Jon (@Middaugh) on CodePen.

Align Content

Align content defines the alignment of content when there is more than one row/column. This property doesn't do anything if there is only one line of content.

  • stretch - default - takes up all available space
  • flex-start - compresses all elements to the start of the container
  • flex-end - compresses all elements to the end of the container
  • center- compresses all elements to the end of the container
  • space-between
  • space-around

Align Content

See the Pen UA-Flex-Align-Content by Jon (@Middaugh) on CodePen.

Flex Item Properties

  • order
  • flex-grow
  • flex-shrink
  • flex-basis

Order

Flex items are ordered as they appear from top to bottom in source code. The order property allows to you position the display order as you need.

This can be useful as you can better arrange items going from desktop to mobile or vice versa.

Order

See the Pen UA-Flex-Item-Order by Jon (@Middaugh) on CodePen.

Flex-Grow

Sets the proportion of how much space you want an element to take up. By default, it is set to 0. Setting all items to 1 will evenly distribute space. Setting 2 will try to take up twice as much space.

It accepts positive unitless numbers

Flex-Grow

See the Pen UA-Flex-Item-Flex-Grow by Jon (@Middaugh) on CodePen.

Flex Shrink

Creates the ability for a flex item to shrink.

I've been getting inconsistent results when trying to figure this one out.

Flex Basis

Sets the size of an element before the remaining space is calculated and distributed.

Flex-Basis

See the Pen UA-Flex-Item-Flex-Basis by Jon (@Middaugh) on CodePen.

Exercise 22

>