12/8/2018

Positioning

CSS Positioning allows you to apply specific positioning to HTML elements.

CSS Position Values

  • static
  • relative
  • absolute
  • fixed

w3Schools

Awesome css-tricks post

Static Position

Static CSS positioning is the default value of the position property.



    .class{
        position:static;
        top: 100px; /*ignored*/
        right:100px; /*ignored*/
    }
        

Relative Position

Positions element relative to where it should be. It respects top, left, right and bottom. Content will not shift to take up the space.



    .class{
        position:relative;
        top: 100px; 
        right:100px; 
    }
        

Example

See the Pen UAITR-Relative Positioning by Jon (@Middaugh) on CodePen.

Fixed Position

Fixed position elements are positioned based on the screen. Content will shift to take up the space the element would take up.



    .class{
        position:fixed;
        top: 100px; 
        right:100px; 
    }
        

Example

See the Pen UAITR-FixedPositioning by Jon (@Middaugh) on CodePen.

Absolute Position

Absolute positioned elements are positioned based of the closest parent element that has a position that is not static. If no parent is found, it is positioned off the the document.



    .class{
        position:absolute;
        top: 100px; 
        right:100px; 
    }
        

More on this here.

Example

See the Pen UAITR-FixedPositioning by Jon (@Middaugh) on CodePen.

Positioning tricks

Horizontally Align Absolute positioned element


.horizantal{
    position: absolute;
    left: 50%;
    -webkit-transform: translateX(-50%);
    transform: translateX(-50%)
}
            

Vertially Align Absolute positioned element


.vertical{
    position: absolute;
    top: 50%;
    -webkit-transform: translateY(-50%);
    transform: translateY(-50%)
}
            

Example

See the Pen UAITR-FixedPositioning by Jon (@Middaugh) on CodePen.

Modals/Dialogs

Modals allow you to present a small amount of content to the user without navigating away from the screen.

Common Uses

  • Terms of Service
  • Contact Forms
  • Help Screens
  • Small Signups/Forms

Best Practices

  • Visible Title
  • Easy to close
    • Visible close button
    • Pressing ESC
    • Clicking outside of the dialog
  • No auto open
    • Make the user perform an action
  • Don't put too much information in it.

Plugins / Demos

Website Rotators

Rotators provide interactive slide shows to users. They are frequently used to highlight important callouts or for featuring specific items.

Common things to feature

  • Important parts of your site
  • Recent Events
  • Featured products
  • Work overview
  • Product List

Things to consider

  • Mobile Friendly
  • Slide Count
  • Image Sizes
  • Customization

Coding a basic rotator from scratch is not that hard.

It is a good exercise to learn new JavaScript features.

Video on how to write one

Slick.js

"The last rotator you will ever need"

http://kenwheeler.github.io/slick/

Html


    
your content
your content
your content

CSS


    
    

JS


    
    

JS - initialization


    $(document).ready(function(){
        $('.your-class').slick({
            setting-name: setting-value
        });
    });
        

Start with their examples and customize them.

>