+```css
@keyframes margin {
-
-to { margin-right: 7rem; }
-
+ to { margin-right: 7rem; }
}
.margin {
-
-display: inline-block;
-
-height: 5rem;
-
-width: 5rem;
-
-background-color: lightblue;
-
-vertical-align: top;
-
+ display: inline-block;
+ height: 5rem;
+ width: 5rem;
+ background-color: lightblue;
+ vertical-align: top;
}
.margin:first-of-type {
-
-margin-right: 0;
-
-animation: margin 4s ease 0s infinite;
-
+ margin-right: 0;
+ animation: margin 4s ease 0s infinite;
}
-
+```
### Padding
@@ -70,7 +59,7 @@ animation: margin 4s ease 0s infinite;
Padding is the space between the content and the border of an element. In the demo (#2), it shows a box in which its padding is increasing.
-
+```css
@keyframes padding {
to { padding: 2rem; }
@@ -78,113 +67,90 @@ to { padding: 2rem; }
}
.padding {
-
-display: inline-block;
-
-padding: 0;
-
-background-color: lightgreen;
-
-animation: padding 2.5s ease 0s infinite;
-
+ display: inline-block;
+ padding: 0;
+ background-color: lightgreen;
+ animation: padding 2.5s ease 0s infinite;
}
-
+```
+
### Height
* Accepts a non-negative number, this number is overridden however by (min/max)-height
* Initial value: auto
-“Height” is the height of an element without its padding, border, or margin. In the demo (#3) you can see the boxes’ height shrink, and each box begins it’s animation at a different time.
+“Height” is the height of an element without its padding, border, or margin. In the demo (#3) you can see the boxes' height shrink, and each box begins its animation at a different time.
-
+```css
@keyframes height {
-
-to { height: .01rem; }
-
+ to { height: .01rem; }
}
.height {
-
-display: inline-block;
-
-height: 4rem;
-
-width: 3rem;
-
-background-color: violet;
-
-animation: height 1.25s ease 0s infinite;
-
-vertical-align: top;
-
+ display: inline-block;
+ height: 4rem;
+ width: 3rem;
+ background-color: violet;
+ animation: height 1.25s ease 0s infinite;
+ vertical-align: top;
}
.height:nth-of-type(n) {
-
-animation: height 1.25s ease .2s infinite alternate;
-
+ animation: height 1.25s ease .2s infinite alternate;
}
.height:nth-of-type(2n) {
-
-animation: height 1.25s ease .4s infinite alternate;
-
+ animation: height 1.25s ease .4s infinite alternate;
}
.height:nth-of-type(3n) {
-
-animation: height 1.25s ease .6s infinite alternate;
-
+ animation: height 1.25s ease .6s infinite alternate;
}
-
+```
### Width
* Accepts a non-negative number, this number is overridden however by (min/max)-width
* Initial value: auto
-“Width” is the width of an element without its padding, border, or margin. In the demo (#4), it is similar to #3, however, it’s the width being affected as opposed to the height.
+“Width” is the width of an element without its padding, border, or margin. In the demo (#4), it is similar to #3, however, its the width being affected as opposed to the height.
-
+```css
@keyframes width {
-
-to { width: .01rem; }
-
+ to { width: .01rem; }
}
.width {
-
-margin-bottom: .2rem;
-
-height: 3rem;
-
-width: 6.5rem;
-
-background-color: bisque;
-
+ margin-bottom: .2rem;
+ height: 3rem;
+ width: 6.5rem;
+ background-color: bisque;
}
.width:nth-of-type(n) {
-
-animation: width 1.25s ease .2s infinite alternate;
-
+ animation: width 1.25s ease .2s infinite alternate;
}
.width:nth-of-type(2n) {
-
-animation: width 1.25s ease .4s infinite alternate;
-
+ animation: width 1.25s ease .4s infinite alternate;
}
.width:nth-of-type(3n) {
-
-animation: width 1.25s ease .6s infinite alternate;
-
+ animation: width 1.25s ease .6s infinite alternate;
}
-
-
+```
### Conclusion
-And so with this we can add another collection of animations to our toolbelt! If you’re wondering why I left border out of this box-model post, it’s because I have already written a post dedicated to just the [border animation](https://brandonrozek.com/2015/05/animatable-border/). Here are some of the resources I looked at for this post. Hopefully I’ll come back with another animatable post soon!
+```css
@keyframes background-position {
-
to { background-position: 100% 0%; }
-
}
.background-position {
background-image: url(https://upload.wikimedia.org/wikipedia/commons/d/d3/Tajik_mountains_edit.jpg);
-
height: 6rem;
-
width: 8rem;
-
background-size: 200% 100%;
-
background-position: 0% 0%;
-
animation: background-position 5s linear .1s infinite alternate;
-
}
-
+```
+
+
### position with left, right, top, bottom
* Accepts length, percentage, or some keywords
* Initial value: auto
-The left, right, top, and bottom properties require the position to be set to something other than static. When you add a value to any of these properties just imagine that value pushing the element on that side. For example: for “left: 2rem” imagine that the element is being pushed on the left side by 2rem, making it move to the right 2rem. In the demo (#2), the box is being pushed in a square path.
+The left, right, top, and bottom properties require the position to be set to something other than static. When you add a value to any of these properties just imagine that value pushing the element on that side. For example: for `left: 2rem` imagine that the element is being pushed on the left side by 2rem, making it move to the right 2rem. In the demo (#2), the box is being pushed in a square path.
-
+```css
@keyframes position {
-
25% {
-
top: 0;
-
left: 3rem;
-
}
50% {
-
top: 3rem;
-
left: 3rem;
-
}
75% {
-
top: 3rem;
-
left: 0;
-
}
-
}
.position {
-
position: relative;
-
top: 0;
-
left: 0;
-
height: 3rem;
-
width: 3rem;
-
background-color: lightblue;
-
animation: position 1.5s ease .1s infinite;
-
}
-
-
-
+```
### vertical-align
@@ -126,23 +99,18 @@ The left, right, top, and bottom properties require the position to be set to so
Vertical-align sets how vertically the inline element or text is compared to the baseline. In the Codepen demo (#3), the question has its vertical align being manipulated which causes the “Maybe” to bounce up and down.
-
+```css
@keyframes vertical-align {
-
to { vertical-align: 1rem; }
-
}
.vertical-align {
-
font-size: 1.5rem;
-
vertical-align: 0;
-
animation: vertical-align 1s ease-out .1s infinite alternate;
-
}
-
+```
+
### z-index
@@ -151,78 +119,58 @@ Vertical-align sets how vertically the inline element or text is compared to the
If elements overlap, z-index determines which element appears on top. If the z-index is the same, then it is controlled by source order. In the demo (#4), The z-index of the biggest box changes, revealing what is under it.
-
+```css
@keyframes z-index {
-
to { z-index: 0; }
-
}
.z-index {
-
position: absolute;
-
left: 1rem;
-
display: inline-block;
-
}
.z-index:nth-child(1) {
-
height: 1rem;
-
width: 1rem;
-
background-color: lightgreen;
-
z-index: 4;
-
}
.z-index:nth-child(2) {
-
height: 2rem;
-
width: 2rem;
-
background-color: #F4FFA4;
-
z-index: 3;
-
}
.z-index:nth-child(3) {
-
height: 3rem;
-
width: 3rem;
-
background-color: #DEB0ED;
-
z-index: 2;
-
}
.z-index:nth-child(4) {
-
height: 4rem;
-
width: 4rem;
-
background-color: #D8EADF;
-
z-index: 5;
-
animation: z-index 1s ease .1s infinite alternate;
-
}
-
+```
### Conclusion
-By animating the location of an element, it opens up a whole bunch of different opportunities. Using motion, you can signify that the user has indeed pressed the button, instead of what would otherwise leave them there clicking on the button multiple times thinking that nothing has happened. Using motion, you can bring a webpage that would’ve otherwise been boring to life. Use these animations to work, and I’ll be back with another animatable post soon!
+By animating the location of an element, it opens up a whole bunch of different opportunities. Using motion, you can signify that the user has indeed pressed the button, instead of what would otherwise leave them there clicking on the button multiple times thinking that nothing has happened. Using motion, you can bring a webpage that would've otherwise been boring to life. Use these animations to work, and I'll be back with another animatable post soon!
#### The links
-
- <link rel='stylesheet' href='style.css' />
-
+```html
+
+```
Link the Javascript file
-
- <script src='script.js'></script>
-
+```html
+
+```
-Give the tag a class of hello and id of world to use in CSS and Javascript +Give the `
` tag a class of hello and id of world to use in CSS and Javascript -
- <p class='hello' id='world'></p>
-
+```html
+
+```
### In CSS
-Refer to any element with class=’hello’ and change it’s text color to red.
+Refer to any element with `class='hello'` and change it's text color to red.
-
+```css
.hello { color: red; }
-
+```
-Any element with an id=’world’ will have it’s font-size changed to 2rem
+Any element with an `id='world'` will have it's font-size changed to 2rem
-
+```css
#world { font-size: 2rem; }
-
+```
-You don’t have to only use the class and id attributes in html, you can refer to any attribute. This code snippet grabs any canvas element with data=’sales’ and changes it’s border to be 5px thick, dashed, and the color blue.
-
+You don't have to only use the class and id attributes in html, you can refer to any attribute. This code snippet grabs any canvas element with `data='sales'` and changes it's border to be 5px thick, dashed, and the color blue.
+
+```css
canvas[data=sales] { border: 5px dashed blue; }
-
+```
### In Javascript
Javascript has many properties and methods you can use to reference different HTML elements To grab (an) element(s)
-
+```js
document.getElementById();
document.getElementsByClassName(); //Returns an array of element(s)
document.querySelector(); //Returns the first matching selector
document.querySelectorAll(); //Returns an array of element(s)
-
+```
To add a class to an element
-
+```js
element.className += “ random-class” //Note the space
-
+
+```
To check whether a certain condition is true in the browser
-
+```js
window.matchMedia('aspect-ratio: 12/8'); //Returns true if the aspect ratio is 12/8
window.innerHeight; //Is the height of the window
window.innerWidth; //Is the width of the window
-
+```
_And a lot more_
## What should handle what?
-HTML, CSS, and Javascript should all handle what each of them does best. HTML should handle the content, CSS should handle the styles/presentation, and Javascript should handle the behavior of the webpage. Why, you ask? One reason is that it demonstrates a “separation of concerns”. It would be a mess if you’re writing an article in the HTML and you put style attributes all over the place. That would make the markup confusing and hard to read/edit.
+HTML, CSS, and Javascript should all handle what each of them does best. HTML should handle the content, CSS should handle the styles/presentation, and Javascript should handle the behavior of the webpage. Why, you ask? One reason is that it demonstrates a “separation of concerns”. It would be a mess if you're writing an article in the HTML and you put style attributes all over the place. That would make the markup confusing and hard to read/edit.
-## Can’t I just put everything in a Javascript file?
+## Can't I just put everything in a Javascript file?
-Yes you can, but then you lose some of the great features of HTML and CSS. HTML and CSS ignore everything that it doesn’t understand. When Javascript encounters something it doesn’t understand, it stops running the code completely, regardless of what comes after. Please note that I am only speaking about what gets served to the user. When it comes to what’s actually on your server, then store your content however you wish.
+Yes you can, but then you lose some of the great features of HTML and CSS. HTML and CSS ignore everything that it doesn't understand. When Javascript encounters something it doesn't understand, it stops running the code completely, regardless of what comes after. Please note that I am only speaking about what gets served to the user. When it comes to what's actually on your server, then store your content however you wish.
## Conclusion
-To me personally, my first lecture was a mess. Some of my examples didn’t work properly in the first type-through and I was everywhere. Though, to be sharing the little knowledge I do have, comes with it’s own joy. It must not have gone as terrible as I imagined it in my head because they seemed enthusiastic for the next lecture. So I’m excited to share this outline with you, and hopefully I’ll have many more to come. Until next time. 🙂
\ No newline at end of file
+To me personally, my first lecture was a mess. Some of my examples didn't work properly in the first type-through and I was everywhere. Though, to be sharing the little knowledge I do have, comes with its own joy. It must not have gone as terrible as I imagined it in my head because they seemed enthusiastic for the next lecture. So I'm excited to share this outline with you, and hopefully I'll have many more to come. Until next time. 🙂
\ No newline at end of file