WordPress + Understrap (with SASS + GIT) set up (locally)

Worpress installation.

Download the latest version of WordPress from wordpress.org. Unzip the folder and move the new folder to your sites directory. Rename the wordpress folder to your project name.

Database

Launch phpMyAdmin. Create a new database, user and password. Make a note of these details.

Understrap Theme

Log into WP-Admin. Go to Appearance -> Themes.  Press the Add New button and search for Understrap. Install and activate.

Create Child Theme & set up Visual Studio Code Workspace

Go to the Understrap Child GitHub Project page. Download the project folder. Unzip and move to the wp-content/themes folder.

Rename as per your project.

Open up Visual Studio Code. Select Add Folder to Workspace. Select the new renamed child theme folder and drag into the Explorer window.

Save as new workspace (save this into the main work folder, not the _site folder.

Create new Screenshot.png

Open up a new file in Illustrator or Photoshop – artboard size 880px x 660px. Create new screenshot image and save as wp-content/themes/childtheme/screenshot.png

Edit style.css with theme information

Open up style.css and edit with relevant theme information.

Go into Appearance->Themes and activate the new child theme.

Setting up Sass, JS compilation and BrowserSync

The gulp task ‘watch-bs’ (as defined in gulpfile.js) Starts the Sass watcher (watch), Javascript watcher (scripts) and the browser-sync function.

Custom Javascript

The gulpfile.js identifies the path src/js/custom-javascript.js for custom scripts so create this file and add any custom JS to this file.

Sass

The Gulp watch task monitors any .scss file within any folder within the sass folder (ie assets or themes).

Make any variable changes within _child_theme_variables.scss

Create your own files within the theme directory to simplify things for example:

_header.scss

_navigation.scss

_footer.scss

_utilities.scss

_base.scss

_components.scss

_mixins.scss

You could create an individual folder for each of the pages ie:

sass/pages/_home.scss

sass/pages/_contact.scss

Make sure to @import any custom partials in child-theme.scss

Browser Sync

To utilise browserSync you must configure the proxy option in browserSyncOptions in gulpconfig.json

eg: “proxy” : “localhost:800/randrgardenlandscapes.co,.uk

Compiling using Gulp

First install dependencies (node.js and browsersync must be installed globally)

Open terminal and cd to the theme root folder OR open Terminal->New Terminal in VisualStudio Code and type the following command

npm install

Start Gulp watch, scripts and Browsersync with the following command:

gulp watch-bs

*To stop gulp watch service, press ctrl+C

Setting Up Git

STEP 1: Create local GIT repository
  • Open Terminal
  • CD to root of intended repository
  • type: git init
  • Create a .gitignore file if you don’t want files to be included
STEP 1.2 : Initial Commit
git add -A to add all untracked and modified files
git commit -a -m “initial commit”
Set up remote Repository: BITBUCKET / GIT
STEP 2: Create remote Bitbucket repo
  • Log in to Bitbucket (duncan@samwell.me) / GIT veryselfishman
  • Create a new Repository
STEP 3: Clone and migrate local repo
  • Open terminal and CD to the path of the local repository
  • Type the following code:
git push -u origin master
You can use GitLens in Visual Studio to track, commit and push Git changes.

Setting up Sass

Install Sass in local environment

Create a folder called sass and a file within that called main.scss

(You can use terminal commands (mkdir, touch))

Configuring package.json

Determine how to compile sass by setting scripts in package.json

"scripts": {
 "compile:sass": "node-sass sass/main.scss css/style.css -w"
},

To compile Sass, open terminal and type:  npm run compile:sass

The -w tag will watch for changes within the source file and auto compile.

Live Server

Install using npm

npm install live-server -save

or install globally

sudo npm install live-server -g

type live-server in command prompt and cmd will auto launch

Installing Sass locally using NPM

NPM & the Node Ecosytem

node.js

An open source JavaScript runtime, allows developers write and run JS app on the server. Can also be used to write tools to help with local web development.

NPM

Node Package Manager. Command line interface to allow installation and management of packages on local systems.

Make sure the latest version of node.js is installed (download from node.js website).

node -v on the command line will inform you what version of node.js is on the system.

package.json

First thing to create when creating a new project. Will contain the definitions of the project and where NPM will install the tools and packages its required.

npm init will help you create a package.json file.

You can use pakage.json file to install all the dependencies if you need to work on the project elsewhere, just type npm install

Install Sass

$ npm install node-sass --save-dev

Use NPM to install other dependencies such as jquery (include –save)

npm install jquery --save

This will show in the dependencies (not the devdependencies.

When setting up GIT, make sure to ignore all node_modules so as not to include all the dependencies

Sass – the basics

Features

  • Variables: for reusable values such as colours, font-sizes, spacing, etc;
  • Nesting: To nest selectors inside of one another, allowing us to write less code;
  • Operators: For mathematical operations right inside of CSS;
  • Partials & Imports: To write CSS in different files and importing them all into one single file;
  • Mixins: To write reusable pieces of CSS code;
  • Functions: similar to mixins, with the difference that they produce a value that can then be used; ie darken(color, i%)
  • Extends: To make different selectors inherit declarations that are common to all of them;
  • Control Directives: for writing complex code using conditionals and loops;

Sass syntax vs SCSS syntax

Sass: no requirement for brackets or semi-colons

SCSS similar to traditional CSS, clearer to follow and easier to convert old CSS projects.

Mixins, Functions & Extends

Mixins

ie Clearfix mixin:

@mixin clearfix {
 &::after {
  content: "";
  clear: both;
  display: table;
 }
}

nav {
 @include clearfix;
}

Mixins are groups of CSS that can be reused. Use @include to insert the mixin.

You can also pass arguments through mixins:

@mixin style-link-text($colour) {
 text-decoration: none;
 text-transform: uppercase;
 color: $colour;
}

@include style-link-text(#FFF);

Functions

Functions are like mixins but you can perform mathematical action using arguments passed in parenthesis:

@function divide($a, $b) {
 return $a / $b;
}

Sass has a number of built in functions such as darken() and lighten().

Extends

 

%btn-placeholder {
 styling
}

extend %btn-placeholder

Like mixins, this allows you to reuse code, however instead of copying the code to each element, when compiled it will group all the elements together and apply the style. Use instead of mixins when the elements are related to each other.

CSS Animations

Two Types of animation

@Keyfrees

Create a keyframes function:

 
@keyframes animationLabel {
0% {
opacity: 0;
transform: translateX(-100px); // this element will be reposition 100px to the left
}
100% {
opacity: 1;
transform: translate(0);
}
 
Use the following CSS tags to call the animation
.movingElement {
animation-name: moveInLeft;
animation-delay: 3s
animation-duration: 1s
animation-iteration-count: 3;
animation-timing-function: ease | ease-in | ease-out | ...
backface-visibility: hidden;
animation-fill-mode: backwards; //will automatically apply keyframe 0 before animation starts
}

Refer to online documentation for all the animation properties.

If animation is shakey use backface-visibility property on element.

Transition Property

button:hover {
 transform: translateY(-3px);
 box-shadow: 0 10px 20px rgba(0,0,0,.2);
}

button:active {
 transform: translateY(-1px);
 box-shadow: 0 5px 10px rgba(0,0,0,.2);
}

button:link, button:visited {
 transition: all .2s;
}

transition:  property | duration;

 

CSS Tips

3 Pillars of writing HTML & CSS

Responsive Design, Maintainable & Scalable Code, Web Performance

Reset CSS

*,
a::before,
a::after {
 margin: 0;
 padding: 0;
 box-sizing: inherit;
}

body {
 box-sizing: border-box; // padding are not added to width of box, width size is set at border level
}

Font Sizing, REMs and Responsive text sizing

Bad practice to declare font-size as pixels (prevents users from changing font-size in their browsers). Declaring font-size in REM sizes font to a multiple of the root font size (set by the browser, usually 16px).

If you wish to change the root font size, do so under the html element and as a percentage of the browser root:

html {
 font-size: 87.5%; // 14px if browser root is 16px
}

You can then use media queries to resize all fonts proportionately by changing the size declared in html.

Not supported in IE9.

Scaling divs in relation to Viewport Height:

Use [int]vh; (Integer is percentage of viewport height.

header : 95vh // Header is 95% of height of viewport

Clearfix

<nav class="clearfix">

.clearfix::after {
 content: "";
 clear: both;
 display: table;
}

Gradient

background-image: linear-gradient(to right bottom, rgba1, rgba2), url(../img/hero.jpg);

The above CSS puts an opaque gradient from top left to right bottom over a hero image.

Clip-Path / Polygon

clip-path: polygon(x y, x y, x y, x y, x y)

Creates a clipping mask over the element. Use polygon to create a shape. Parameters are Top-right, top-left, bottom-left, bottom-right.

Use Clippy to generate polygon

Translate (transform)

Reposition the elements top/left co-ordinates. Useful when using absolute position to centre an element:

.element {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
}

g

Flexbox

Flexbox is a new module in CSS3 that makes it easy to align elements to ne another in different directions and orders.

Gives the container the ability to expand and shrink elements to best use the available space.

Replaces float layouts.

Concepts

Flex Container & Flex Items, Main and Cross Axis

display: flex

Container
flex-direction: row | row-reverse | column | column-reverse

which direction the Main Axis goes (left>right, up or down)

row-reverse inverts item order along main axis

column aligns items on top of each other down the cross axis (column-reverse reverses order)

flex-wrap: nowrap | wrap | wrap-reverse

Defines if the flex items should go to a next line if not enough space

justify-content: flex-start | flex-end | center | space-betweem | space-around | space-evenly

How flex items will be aligned on the main axis:

center: center justified

space-between = fully justified

space-around : space space around each item

space-evenly: similar to above but equal space between each element

flex-end / flex start: right/left justified

align-items: stretch | flex-start | flex-end | center |  baseline

How flex items will be aligned on the cross axis

align-content: stretch | flex-start | flex-end | center | space-between | space-around

Defines how flex items are aligned on the cross axis when there is more than one row.

stretch – resizes all items to size of largest.

center: horizontal alignment of items

flex-start / flex-end: aligns all items to top / bottom of div

baseline:  aligns items by the bottom (baseline) of the text contained on all items horizontally.

Item
align-self: auto | stretch | flex-start | flex-end | center | baseline

Similar to align-items but for single items

order: 0 | <integer>

defines order in one specific item should appear (to reorder)

flex-grow: 0 | <integer>

Maximum width

flex grow: 1 will allow the item to expand as much as possible to take all available space in the container

flex-shrink: 1 | <integer>

minimum width

1: element is allowed to shrink

0: element no longer allowed to shrink

flex-basis: auto | <length>

Base width

Percentage based (only if there is available space)

flex: 0 1 auto