By Chen Hui Jing / @hj_chen
People go to conferences to get inspired and to learn about things that exist or maybe an overview of how to use it.
But then, they really learn that thing, that technology, when they go home and practice it themselves.
― Una Kravets, Toolsday #34
My name is Hui Jing.
Self taught designer and developer.
Work at Deep Labs.
Write blog posts from time to time.
The input
and its label
must be linked
Either wrap the input
in the label
<label>
<input type="radio" name="moment" value="block">
<img src="img/block.jpg" srcset="img/block.jpg 2x" alt="The Block">
<span>The Block</span>
</label>
Or use the for="ID_OF_INPUT"
attribute on the label
<input type="radio" name="moment" value="block" id="block">
<label for="block">
<img src="img/block.jpg" srcset="img/block.jpg 2x" alt="The Block">
<span>The Block</span>
</label>
Uses the :checked
pseudo-class and sibling selectors
.o-option__input {
opacity: 0;
position: absolute;
&:checked + .o-option__img {
border-color: #860038;
}
&:checked ~ .o-option__txt {
color: #860038;
}
}
The transform: translateX()
property with nth-child
selectors
.is-active.c-4options {
z-index: -1;
.is-checked.o-option:nth-child(1) {
transform: translateX(100%);
}
.is-checked.o-option:nth-child(3) {
transform: translateX(-100%);
}
.is-checked.o-option:nth-child(4) {
transform: translateX(-200%);
}
}
The transform: scale()
and opacity
property
.c-action,
.c-logo__img,
.is-active .o-option:not(.is-checked) {
transform: scale(0);
opacity: 0;
z-index: 0;
}
.is-active .c-action,
.is-active .c-logo__img {
opacity: 1;
transform: scale(1);
}
The transition
and transition-delay
property
.o-option,
.c-action,
.c-logo__img {
transition: transform 0.4s ease-in-out, opacity 0.4s ease-out;
transition-delay: 0.1s;
}
That 0.1s pause does make a difference ¯\_(ツ)_/¯
l-
js-
o-
<label class="l-option o-option js-option">
<input class="o-option__input" type="radio" name="moment" value="block">
<img src="https://res.cloudinary.com/huijing/image/upload/w_200/block.jpg" srcset="https://res.cloudinary.com/huijing/image/upload/w_400/block.jpg 2x" alt="The Block" class="o-option__img">
<span class="o-option__txt">The Block</span>
</label>
Inspired by Harry Roberts' CSS for Software Engineers for CSS Developers.
Does not play nice with keyboard controls 😔
Make the enhancement a choice that can be toggled
::before
and ::after
.element::before {
content: '';
display: block;
width: 50%;
height: 50%;
}
Must have the content
property to work
At least have empty quotes
Not visible in the page's source, only in CSS
This be a circle
.circle {
width: 30vmin;
height: 30vmin;
background: #f2af29;
border-radius: 50%; /* This is the key line, right here */
margin: 0 auto;
}
This be a triangle
.triangle {
border-top: 18.75vmin solid transparent;
border-bottom: 18.75vmin solid transparent;
border-left: 18.75vmin solid #1e292f;
}
This be a trapezium
.trapezium {
width: 60vmin;
height: 30vmin;
background: #1e292f;
clip-path: polygon(33% 0, 67% 0, 100% 100%, 0% 100%); /* This is the key line, right here */
}
Unfortunately, clip-path
is NOT supported in Edge or IE 😔
Multiple box shadows are a thing
box-shadow: [horizontal offset] [vertical offset] [blur radius] [optional spread radius] [color];
Make use of the offsets for positioning, and the blur radius for sizing
.o-logo-basic {
border-radius: 50%;
height: 1px;
width: 1px;
position: absolute;
bottom: 10%;
left: 50%;
box-shadow: -6vmin 0 0 0.5vmin #47473f, -4vmin 0 0 0.5vmin #47473f,
-2vmin 0 0 0.5vmin #47473f, 0 0 0 0.5vmin #47473f,
4vmin 0 0 0.5vmin #47473f, -6vmin 2vmin 0 0.5vmin #47473f,
-4vmin 2vmin 0 0.5vmin #47473f, 0 2vmin 0 0.5vmin #47473f,
2vmin 2vmin 0 0.5vmin #47473f, 4vmin 2vmin 0 0.5vmin #47473f,
6vmin 2vmin 0 0.5vmin #47473f;
}
Okay fine, it's scroll-jacking ¯\_(ツ)_/¯
Only works on Firefox and Edge 😔
main {
width: 100vw;
height: 85vmin;
white-space: nowrap;
overflow-y: hidden;
overflow: auto;
-webkit-overflow-scrolling: touch;
scroll-snap-type: mandatory; /* this is the key line */
}
section {
display: inline-block;
width: 100%;
height: 100%;
scroll-snap-coordinate: 0 0; /* this is the key line */
}