Professional Documents
Culture Documents
Creating a LOCATION
Nottingham, UK
CSS WORK
Web dev |
Design
cybersecurity
professional
JOINED
What was
your win this
week?
Figma files referenced
#discuss
are available on #weeklyretro
frontendmentor.io
You can visit my
finished product at
https://designsystemcss
.netlify.app See the
complete source code
https://github.com/crypt
o3p/Design-System ---
We’re going to be
recreating this design
system for a space
travel website.
Setting up
Custom properties for
colours, fonts and font
sizes
:root {
--clr-dark: 230 35% 7%;
--clr-light: 231 77% 90%;
--clr-white: 0 0% 100%;
/* font sizes */
--fs-900: 9.375rem;
--fs-800: 6.25rem;
--fs-700: 3.5rem;
--fs-600: 2rem;
--fs-500: 1.75rem;
--fs-400: 1.125rem;
--fs-300: 1rem;
--fs-200: 0.875rem;
:
/* font families */
--ff-serif: "Bellefair", serif;
--ff-sans-cond: "Barlow Condensed", sans-serif;
--ff-sans-normal: "Barlow", sans-serif;
}
Accessibility
Creating a screen-
reader-only class:
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; /* added line */
border: 0;
}
sr-only vs display:none
prefers-reduced-
motion media query —
meaning people took
the time to turn off
animations, either in
browser settings or OS
level
for people who motion
causes problems i.e.
parallax scrolling, scroll
linked animations etc.
Colour utility
classes
Going on to recreate the
:
following part of the design
system:
.flex {
display: flex;
gap: var(--gap, 1rem);
}
.grid {
display: grid;
gap: var(--gap, 1rem);
}
.text-dark {
color: hsl( var(--clr-dark) );
}
.text-accent {
color: hsl( var(--clr-light) );
}
.text-white {
color: hsl( var(--clr-white) );
}
Typography
.fs-900,
.fs-800,
.fs-700,
.fs-600 {
line-height: 1.1;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: 400;
}
Numbered Titles
Utility classes allow us to
work quickly ,but when we
have something like
numbered titles here, that
is always the same, it’s
good to find a balance —
:
making a utility class2.0
let’s say, just for those
numbered titles
.numbered-title {
font-family: var(--ff-sans-cond);
font-size: var(--fs-500);
text-transform: uppercase;
letter-spacing: 4.72px;
}
.numbered-title span {
margin-right: .5em;
:
margin-right: .5em;
font-weight: 700;
color: hsl( var(--clr-white) /.25 );
}
Spacing
Utilities for spacings are
very common, but don’t
think we need it for this
design. We’ll use a modern
solution, with one utility
class and just one modern
pseudo class that’s
recently been added to
CSS, supported by most
modern browsers.
Going to general utility
classes in our CSS file,
we’ll add the following
code:
:
.flow > * + * {
margin-top: 1rem;
outline: 1px solid red;
}
How it works:
* +* has no extra
specificity to it.
the .flow has
specificity, which is
important because on
our paragraphs and
headings we set a
margin of 0. So we need
the specificity to
:
overwrite that to add a
margin-top on them.
Using *:not(:first-child)
.card h1,
.card h2,
.card h3 {
}
what we can do is
or
.large-button {
position: relative;
z-index: 1;
display: grid;
border-radius: 50%;
place-items: center;
padding: 0 2em;
aspect-ratio: 1;
text-decoration: none;
}
display:grid instead of
inline block so we can
easily place the text in the
middle of the block with
place-items:center
(shorthand for align-items
and justify-items)
:
can do it with flex, but
we’re keeping it shorter,
just in one line we got it
right in the middle
.large-button::after {
content: '';
position: absolute;
background: hsl( var(--clr-white) / .15 );
width: 100%;
height: 100%;
z-index: -1;
border-radius: 50%;
opacity: 0;
transition: opacity 500ms linear, transform 750ms
}
.large-button z-index of
1
.large-button::atfter z-
index of -1
.large-button:hover::after,
.large-button:focus::after {
transform: scale(1.5);
}
Underline
Indicators
.primary-navigation {
--underline-gap: 3rem;
--gap: 4rem;
list-style: none;
padding: 0;
margin: 0;
}
.primary-navigation a {
text-decoration: none;
}
.underline-indicators > * {
padding: var(--underline-gap, 1rem) 0;
border: 0;
cursor: pointer;
border-bottom: .2rem solid hsl( var(--clr-white) /
}
:
You can also make it as a
utility class and place it for
each one of the links,
Though this way, you will
put the class in only one
place instead of multiple,
allowing for grouping and
just a little bit less work.
To accommodate this, we
are going to use a custom
property — underline-gap
and set the default to 1rem
Underline indicators —
tabs
While we’ve already done
most of the heavy lifting
with underline indicators
above, there are a few
things that would need
tweaking. After adding the
utility classes to button
elements to style the text,
adding the underline-
indicators class to the div
element gives this
outcome.
.underline-indicators > * {
padding: var( - underline-gap, 1rem) 0;
border-bottom: .2rem solid hsl( var( - clr-white)
}
.underline-indicators > * {
padding: var( - underline-gap, 1rem) 0;
border: 0;
cursor: pointer;
:
border-bottom: .2rem solid hsl( var( - clr-white)
}
aria-selected =
accessible rich internet
applications
Something we can
use to give extra
context to assistive
technologies. And
since we’re going
to be turning this
area into a tabs
:
system, it’s a way
to let them know
that this is a
selected tab
It’s different than links,
since with links we are
going to a different html
page and with tabs, we
are staying on the same
page but essentially
moving the content
around
Dot indicators
Very similar to tab
indicators.
Now we will use the sr-
only class created at the
beginning by wrapping the
title in a span and adding
the sr-only class to it.
:
<div class="dot-indicators flex">
<button aria-selected="true" class=""><span class=
<button aria-selected="false" class=""><span class
<button aria-selected="false" class=""><span class
</div>
Number indicators
Following the example of
previous indicators, finish
up the design system with
number indicators.
.number-indicators > *{
margin: 1.7rem;
padding: 0;
cursor: pointer;
color: hsl( var( - clr-white) );
border: 3px solid hsl( var( - clr-white) /.5 );
border-radius: 50%;
aspect-ratio: 1;
border-color: hsl( var( - clr-white) /.25 );
}
.number-indicators > *:hover,
.number-indicators > *:focus {
border-color: hsl( var( - clr-white) / 1 );
}
.number-indicators > [aria-selected="true"] {
:
background-color: hsl( var( - clr-white) / 1);
color: hsl( var( - clr-dark) );
}
Discussion (0)