Garrick Aden-Buie
rstudio::conf(2020, "JavaScript for Shiny Users")
Which type of display doesn't have a width or height?
Which type of display doesn't have a width or height?
Which type of display is shown on its own line?
Which type of display doesn't have a width or height?
Which type of display is shown on its own line?
What are some examples of inline elements?
Which type of display doesn't have a width or height?
Which type of display is shown on its own line?
What are some examples of inline elements?
Examples of block elements?
.not-down { display: block; background: red; color: white;}
<p class="not-down"> ...never gonna...</p>
He sings the songs that remind him of the good times. He sings the songs that remind him of the best times.
Oh, Danny Boy.
I get knocked down, but I get up again. You're never gonna to keep me down.
.best { display: inline; background: red; color: white;}
<span class="best"> the best times</span>
He sings the songs that remind him of the good times. He sings the songs that remind him of the best times.
Oh, Danny Boy.
I get knocked down, but I get up again. You're never gonna to keep me down.
.danny { display: none; background: red; color: white;}
<p class="danny"> Oh Danny Boy</span>
He sings the songs that remind him of the good times. He sings the songs that remind him of the best times.
I get knocked down, but I get up again. You're never gonna to keep me down.
border: 1px solid turquoise;
border: 1px solid turquoise;
border-width: 1px;border-style: solid;border-color: turquoise;
margin: 1em;
margin-top: 1em;margin-right: 1em;margin-bottom: 1em;margin-left: 1em;
padding: 1em;
padding-top: 1em;padding-right: 1em;padding-bottom: 1em;padding-left: 1em;
margin: 0 1em;
margin-top: 0;margin-right: 1em;margin-bottom: 0;margin-left: 1em;
padding: 0 1em;
padding-top: 0;padding-right: 1em;padding-bottom: 0;padding-left: 1em;
margin: 1em 0;
margin-top: 1em;margin-right: 0;margin-bottom: 1em;margin-left: 0;
padding: 1em 0;
padding-top: 1em;padding-right: 0;padding-bottom: 1em;padding-left: 0;
margin: 1px 2px 3px 4px;
margin-top: 1px;margin-right: 2px;margin-bottom: 3px;margin-left: 4px;
padding: 1px 2px 3px 4px;
padding-top: 1px;padding-right: 2px;padding-bottom: 3px;padding-left: 4px;
<p style="text-align: center"> <img src="http://placekitten.com/200/200" /></p>
<p style="text-align: center"> <img src="http://placekitten.com/200/200" /></p>
Is <img>
inline or block?
<p style="text-align: center"> <img style="display:block;" src="http://placekitten.com/200/200" /></p>
What will happen?
<p style="text-align: center"> <img style="display:block;" src="http://placekitten.com/200/200" /></p>
<p style="text-align: center"> <img style="display:block;" src="http://placekitten.com/200/200" /></p>
#out-kitten-block-img :hover { background: var(--washed-red); outline: 1px solid var(--red);}
<div class="kitten-container"> <div class="kitten"></div></div>
<div class="kitten-container"> <div class="kitten"></div></div>
.kitten { margin: 0 auto; height: 200px; width: 200px; background: url('http://placekitten.com/200/200');}
Center Text
.centered { text-align: center}
Center Block
.centered { display: block; width: 33%; margin-left: auto; margin-right: auto;}
Center Block
.centered { display: block; width: 33%; margin: 0 auto;}
Vertical Center
.container-of-item { display: flex; align-items: center;}
All Center
.container-of-item { display: flex; align-items: center; justify-content: center;}
<div class="card card-eyeshadow"> <header> <div class="pan"> <div class="shade almost-there"></div> </div> <h1 id="item">Super Shock Shadow</h1> </header> <p>By <em class="brand">Colourpop</em></p> <div id="cost" class="us-dollar">$8</div></div>
<div class="card card-eyeshadow"> <header> <div class="pan"> <div class="shade almost-there"></div> </div> <h1 id="item">Super Shock Shadow</h1> </header> <p>By <em class="brand">Colourpop</em></p> <div id="cost" class="us-dollar">$8</div></div>
h1, p
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
div#cost.us-dollar
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
header .pan
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
.card-eyeshadow .pan
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
.card .shade
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
.card .shade
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
.card > div
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
p > .brand
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
p > .brand
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
header ~ #cost
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
header + p
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
p ~ div
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
p ~ div
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
p + div
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
p + div
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
Type | Example Selector |
---|---|
Element | p |
Class | .shiny |
IDs | #shiny |
Pseudo-classes | :hover , :active , :empty |
Attributes | [attribute] |
Pseudo-elements | ::before |
Anything | * |
Attribute selectors are awesome and are super helpful in tricky situations where you don't have control over the HTML or the classes (hello shiny!)
div[id]
A <div>
that has an id attribute
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
div[id="cost"]
A <div>
that has an id attribute whose value is cost
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
[class*="brand"]
An element where brand appears in the class attribute
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
[class*="brand"]
An element where brand appears in the class attribute
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
We're usually not creating the CSS from scratch, instead we modify existing CSS to make things look better.
The browser is a jumble of competing CSS rules.
h1 .shiny { color: lightblue;}
#title.shiny { color: red;}
...which one wins?
What type of rule is it?
transition
!important
animation
normal
.shiny { color: lightblue;}
.shiny { color: blue !important;}
Where was the rule defined?
website
user
browser
/* browser default */p { color: black;}
/* shiny.css */p { color: lightblue;}
How specific is the rule?
inline styles style="color: lightblue"
id #shiny
class, attribute, pseudo-class .shiny:hover
element, pseudo-elements strong
.shiny { color: blue;}
#shiny { color: lightblue;}
The most points on the highest level wins
p.shiny { color: blue;}
.shiny:first-child { color: lightblue;}
The most points on the highest level wins
Ties can be broken within specificity by points one level down
#shiny .paragraph { color: blue;}
#shiny p { color: lightblue;}
The most points on the highest level wins
Ties can be broken within specificity by points one level down
How selectors are combined doesn't matter
#shiny ~ p { color: blue;}
#shiny + p { color: lightblue;}
Which rule was defined last?
.shiny { color: blue;}
.shiny { color: red;}
Which type of display doesn't have a width or height?
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
o | Tile View: Overview of Slides |
Esc | Back to slideshow |
Garrick Aden-Buie
rstudio::conf(2020, "JavaScript for Shiny Users")
Which type of display doesn't have a width or height?
Which type of display doesn't have a width or height?
Which type of display is shown on its own line?
Which type of display doesn't have a width or height?
Which type of display is shown on its own line?
What are some examples of inline elements?
Which type of display doesn't have a width or height?
Which type of display is shown on its own line?
What are some examples of inline elements?
Examples of block elements?
.not-down { display: block; background: red; color: white;}
<p class="not-down"> ...never gonna...</p>
He sings the songs that remind him of the good times. He sings the songs that remind him of the best times.
Oh, Danny Boy.
I get knocked down, but I get up again. You're never gonna to keep me down.
.best { display: inline; background: red; color: white;}
<span class="best"> the best times</span>
He sings the songs that remind him of the good times. He sings the songs that remind him of the best times.
Oh, Danny Boy.
I get knocked down, but I get up again. You're never gonna to keep me down.
.danny { display: none; background: red; color: white;}
<p class="danny"> Oh Danny Boy</span>
He sings the songs that remind him of the good times. He sings the songs that remind him of the best times.
I get knocked down, but I get up again. You're never gonna to keep me down.
border: 1px solid turquoise;
border: 1px solid turquoise;
border-width: 1px;border-style: solid;border-color: turquoise;
margin: 1em;
margin-top: 1em;margin-right: 1em;margin-bottom: 1em;margin-left: 1em;
padding: 1em;
padding-top: 1em;padding-right: 1em;padding-bottom: 1em;padding-left: 1em;
margin: 0 1em;
margin-top: 0;margin-right: 1em;margin-bottom: 0;margin-left: 1em;
padding: 0 1em;
padding-top: 0;padding-right: 1em;padding-bottom: 0;padding-left: 1em;
margin: 1em 0;
margin-top: 1em;margin-right: 0;margin-bottom: 1em;margin-left: 0;
padding: 1em 0;
padding-top: 1em;padding-right: 0;padding-bottom: 1em;padding-left: 0;
margin: 1px 2px 3px 4px;
margin-top: 1px;margin-right: 2px;margin-bottom: 3px;margin-left: 4px;
padding: 1px 2px 3px 4px;
padding-top: 1px;padding-right: 2px;padding-bottom: 3px;padding-left: 4px;
<p style="text-align: center"> <img src="http://placekitten.com/200/200" /></p>
<p style="text-align: center"> <img src="http://placekitten.com/200/200" /></p>
Is <img>
inline or block?
<p style="text-align: center"> <img style="display:block;" src="http://placekitten.com/200/200" /></p>
What will happen?
<p style="text-align: center"> <img style="display:block;" src="http://placekitten.com/200/200" /></p>
<p style="text-align: center"> <img style="display:block;" src="http://placekitten.com/200/200" /></p>
#out-kitten-block-img :hover { background: var(--washed-red); outline: 1px solid var(--red);}
<div class="kitten-container"> <div class="kitten"></div></div>
<div class="kitten-container"> <div class="kitten"></div></div>
.kitten { margin: 0 auto; height: 200px; width: 200px; background: url('http://placekitten.com/200/200');}
Center Text
.centered { text-align: center}
Center Block
.centered { display: block; width: 33%; margin-left: auto; margin-right: auto;}
Center Block
.centered { display: block; width: 33%; margin: 0 auto;}
Vertical Center
.container-of-item { display: flex; align-items: center;}
All Center
.container-of-item { display: flex; align-items: center; justify-content: center;}
<div class="card card-eyeshadow"> <header> <div class="pan"> <div class="shade almost-there"></div> </div> <h1 id="item">Super Shock Shadow</h1> </header> <p>By <em class="brand">Colourpop</em></p> <div id="cost" class="us-dollar">$8</div></div>
<div class="card card-eyeshadow"> <header> <div class="pan"> <div class="shade almost-there"></div> </div> <h1 id="item">Super Shock Shadow</h1> </header> <p>By <em class="brand">Colourpop</em></p> <div id="cost" class="us-dollar">$8</div></div>
h1, p
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
div#cost.us-dollar
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
header .pan
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
.card-eyeshadow .pan
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
.card .shade
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
.card .shade
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
.card > div
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
p > .brand
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
p > .brand
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
header ~ #cost
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
header + p
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
</div>
p ~ div
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
p ~ div
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
p + div
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
p + div
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
Type | Example Selector |
---|---|
Element | p |
Class | .shiny |
IDs | #shiny |
Pseudo-classes | :hover , :active , :empty |
Attributes | [attribute] |
Pseudo-elements | ::before |
Anything | * |
Attribute selectors are awesome and are super helpful in tricky situations where you don't have control over the HTML or the classes (hello shiny!)
div[id]
A <div>
that has an id attribute
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
div[id="cost"]
A <div>
that has an id attribute whose value is cost
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
[class*="brand"]
An element where brand appears in the class attribute
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
[class*="brand"]
An element where brand appears in the class attribute
<div class="card card-eyeshadow">
<header>
<div class="pan">
<div class="shade almost-there"></div>
</div>
<h1 id="item">Super Shock Shadow</h1>
</header>
<p>By <em class="brand">Colourpop</em></p>
<div id="cost" class="us-dollar">$8</div>
<div class="brand-image">...</div>
</div>
We're usually not creating the CSS from scratch, instead we modify existing CSS to make things look better.
The browser is a jumble of competing CSS rules.
h1 .shiny { color: lightblue;}
#title.shiny { color: red;}
...which one wins?
What type of rule is it?
transition
!important
animation
normal
.shiny { color: lightblue;}
.shiny { color: blue !important;}
Where was the rule defined?
website
user
browser
/* browser default */p { color: black;}
/* shiny.css */p { color: lightblue;}
How specific is the rule?
inline styles style="color: lightblue"
id #shiny
class, attribute, pseudo-class .shiny:hover
element, pseudo-elements strong
.shiny { color: blue;}
#shiny { color: lightblue;}
The most points on the highest level wins
p.shiny { color: blue;}
.shiny:first-child { color: lightblue;}
The most points on the highest level wins
Ties can be broken within specificity by points one level down
#shiny .paragraph { color: blue;}
#shiny p { color: lightblue;}
The most points on the highest level wins
Ties can be broken within specificity by points one level down
How selectors are combined doesn't matter
#shiny ~ p { color: blue;}
#shiny + p { color: lightblue;}
Which rule was defined last?
.shiny { color: blue;}
.shiny { color: red;}