Browsers (in the past) have been incredibly inconsistent with the default styling of elements. To bring everything to zero and build up from there.
Resets must be the first thing in your CSS file. You can either create a separate reset.css file or include these styles at the very beginning of your CSS.
Originated in 2007. It is still used today. It's purpose is to bring all default values to zero.
See the Pen UA-ITR-CSS-Reset by Jon (@Middaugh) on CodePen.
See the Pen UA-ITR-CSS-Reset by Jon (@Middaugh) on CodePen.
Normalize is a more modern approach to a CSS reset. It is larger in size, but leaves a lot of the default styling.
Normalize.css Repository Normalize.css fileBox sizing tells the browser what to include in the overall height and width of an element.
.elm{ box-sizing: [value]}
content-box
- content is the only thing that is included in the height and widthborder-box
- content, padding, and border are included. Not marginSee the Pen UA-ITR-BoxSizing by Jon (@Middaugh) on CodePen.
See the Pen UA-ITR-BoxSizing by Jon (@Middaugh) on CodePen.
* { /*css rules*/ }
* { color : red}
See the Pen UA-ITR-UniversalSelector by Jon (@Middaugh) on CodePen.
h1 { /*css rules*/ }
Applies rules to all tags that match.
See the Pen UA-ITR-Tag Selector by Jon (@Middaugh) on CodePen.
div p {/*css rules*/ }
.my-container p {/*css rules*/ }
.my-container p .highlight {
/*css rules*/
}
See the Pen UA-ITR-Descendant Selector by Jon (@Middaugh) on CodePen.
div, p {/*css rules*/ }
See the Pen UA-ITR-GroupingSelector by Jon (@Middaugh) on CodePen.
You can make your selectors more specific by using multiple selectors joined together
div.class {}
.class1.class2 {}
See the Pen UA-ITR-CombinedSelectors by Jon (@Middaugh) on CodePen.
jQuery was introduced in late 2006. It is designed to help developers write consistent cross browser compatible JavaScript. It's used by roughly 65% of the top 10 million most popular websites on the internet. This is down due to rise of more complex libraries such as Angular and React.
jQuery's syntax is designed to make it easier to navigate a document, select DOM elements, create animations, handle events, and develop Ajax applications.
jQuery is designed to be easily extended to create complex plugins that can be implemented quickly.
We need to include a reference to jQuery so that we can use it. We can do this several different ways.
Your jQuery reference needs to be the first JavaScript include at the bottom of the page.
$(element)
$('selector')
The document.ready method allows you to setup code to not execute until the page is ready for manipulation.
$(document).ready(function(){
console.log('We are ready!');
});
Selectors provide an easy way to retrieve elements from the DOM
$('a')
$('input')
$('form .btn')
$('.list')
$('#btnSubmit')
Wiring up events are pretty straight forward and are easier to read than raw JavaScript.
document.getElementById('button').addEventListener('click', update);
$('#button').on('click', update);
jQuery can make modifying HTML a lot easier.
var html = document.getElementById('div').innerHTML
var html = $('div').html()
document.getElementById('div').innerHTML = "New HTML";
$('div').html('New HTML')
You can interact and modify input values a lot like you are used to html
var value = document.getElementById('txtUserName').value
var value = $('txtUserName').val()
document.getElementById('txtUserName').value = "New Value";
$('txtUserName').val('New Value')
Shows and hides an element by using CSS
$('element').show()
$('element').hide()
Detects if the element is visible or hidden and will apply the opposite style.
$('element').toggle()
We can extend the functionality by passing in parameters.
$('element').show('slow')
$('element').hide('fast')
$('element').show(200)
$('element').hide(500)
See the Pen UA-ITR-JQ-Effects by Jon (@Middaugh) on CodePen.
Fades the selected element in and out of view.
$('element').fadeIn()
$('element').fadeOut()
$('element').fadeToggle()
$('element').fadeIn('fast')
$('element').fadeOut('slow')
$('element').fadeIn(200)
$('element').fadeOut(500)
See the Pen UA-ITR-JQ-Effects-Fade by Jon (@Middaugh) on CodePen.
Expands and collapses an element
$('element').slideDown()
$('element').slideUp()
$('element').slideToggle()
$('element').slideDown('fast')
$('element').slideUp('slow')
$('element').slideDown(200)
$('element').slideUp(500)
See the Pen UA-ITR-JQ-Effects-Slide by Jon (@Middaugh) on CodePen.
The following block of code will execute at almost the same time
$('element').fadeOut(200)
$('element2').slideUp(500)
JavaScript doesn't wait for the first line to finish before the second line is executed.
$('element').slideDown(duration, callback)
$('div').slideDown(1000, function(){
$('p').fadeIn(1000);
});
See the Pen UA-ITR-jQuery Callbacks by Jon (@Middaugh) on CodePen.
You can use this CSS property to modify how your mouse cursor appears when moused over an element.
div {
cursor:pointer; // changes the arrow to a pointer
}