Blog

Challenge

CSS

Walkthrough

Material quotation cards walkthrough

A step-by-step walkthrough on creating beautiful cards with CSS variables

Ragav Kumar V

Ragav Kumar V

Jan 15, 2023 ยท 3 min read

Let's build the above challenge with CSS variables.

Let's start with a semantic blockquote element

index.html
src/styles.css
Copy

_13
<!DOCTYPE html>
_13
<html>
_13
<head>
_13
<title>Parcel Sandbox</title>
_13
<meta charset="UTF-8" />
_13
</head>
_13
<body>
_13
<div class="container">
_13
<blockquote class="quote-card"></blockquote>
_13
</div>
_13
<script src="src/index.js"></script>
_13
</body>
_13
</html>

  • Style the container in center of the screen with responsive width
  • box-sizing to include padding in its width
  • Left side slightly indented
  • Creating nice box for quote card
index.html
src/styles.css
Copy

_20
@charset "UTF-8";
_20
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_20
body {
_20
background: #eee;
_20
font-family: "Source Sans Pro", sans-serif;
_20
font-weight: 300;
_20
}
_20
_20
.container {
_20
max-width: 800px;
_20
margin: 40px auto;
_20
}
_20
_20
.quote-card {
_20
padding: 20px;
_20
padding-left: 50px;
_20
box-sizing: border-box;
_20
overflow: hidden;
_20
min-height: 120px;
_20
}

  • Para content
  • Cite author name
index.html
src/styles.css
Copy

_20
<!DOCTYPE html>
_20
<html>
_20
<head>
_20
<title>Parcel Sandbox</title>
_20
<meta charset="UTF-8" />
_20
</head>
_20
<body>
_20
<div class="container">
_20
<blockquote class="quote-card">
_20
<p>
_20
Dream is not what you see in sleep, dream is something which doesn't
_20
let you sleep.
_20
</p>
_20
_20
<cite> A. P. J. Abdul Kalam </cite>
_20
</blockquote>
_20
</div>
_20
<script src="src/index.js"></script>
_20
</body>
_20
</html>

  • Adding CSS variable for colors & shadow with fallback
  • CSS Variable makes it easier to create variants with different themes
  • CSS Variable gets inherited and can be easily overridden
index.html
src/styles.css
Copy

_23
@charset "UTF-8";
_23
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_23
body {
_23
background: #eee;
_23
font-family: "Source Sans Pro", sans-serif;
_23
font-weight: 300;
_23
}
_23
_23
.container {
_23
max-width: 800px;
_23
margin: 40px auto;
_23
}
_23
_23
.quote-card {
_23
padding: 20px;
_23
padding-left: 50px;
_23
box-sizing: border-box;
_23
overflow: hidden;
_23
min-height: 120px;
_23
background: var(--card-bg, #fff);
_23
color: var(--card-clr, #222222);
_23
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_23
}

Makes the quote wordings larger and limits its width

index.html
src/styles.css
Copy

_30
@charset "UTF-8";
_30
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_30
body {
_30
background: #eee;
_30
font-family: "Source Sans Pro", sans-serif;
_30
font-weight: 300;
_30
}
_30
_30
.container {
_30
max-width: 800px;
_30
margin: 40px auto;
_30
}
_30
_30
.quote-card {
_30
padding: 20px;
_30
padding-left: 50px;
_30
box-sizing: border-box;
_30
overflow: hidden;
_30
min-height: 120px;
_30
background: var(--card-bg, #fff);
_30
color: var(--card-clr, #222222);
_30
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_30
}
_30
_30
.quote-card p {
_30
font-size: 22px;
_30
line-height: 1.5;
_30
margin: 0;
_30
max-width: 80%;
_30
}

Makes the cite wordings slimer & a little transparent

index.html
src/styles.css
Copy

_38
@charset "UTF-8";
_38
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_38
body {
_38
background: #eee;
_38
font-family: "Source Sans Pro", sans-serif;
_38
font-weight: 300;
_38
}
_38
_38
.container {
_38
max-width: 800px;
_38
margin: 40px auto;
_38
}
_38
_38
.quote-card {
_38
padding: 20px;
_38
padding-left: 50px;
_38
box-sizing: border-box;
_38
overflow: hidden;
_38
min-height: 120px;
_38
background: var(--card-bg, #fff);
_38
color: var(--card-clr, #222222);
_38
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_38
}
_38
_38
.quote-card p {
_38
font-size: 22px;
_38
line-height: 1.5;
_38
margin: 0;
_38
max-width: 80%;
_38
}
_38
_38
.quote-card cite {
_38
font-size: 16px;
_38
margin-top: 10px;
_38
display: block;
_38
font-weight: 200;
_38
opacity: 0.8;
_38
}

  • Choosing โ€œ as a decoration character
  • Makes it a nicer & larger font
  • Color blend with background
index.html
src/styles.css
Copy

_46
@charset "UTF-8";
_46
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_46
body {
_46
background: #eee;
_46
font-family: "Source Sans Pro", sans-serif;
_46
font-weight: 300;
_46
}
_46
_46
.container {
_46
max-width: 800px;
_46
margin: 40px auto;
_46
}
_46
_46
.quote-card {
_46
padding: 20px;
_46
padding-left: 50px;
_46
box-sizing: border-box;
_46
overflow: hidden;
_46
min-height: 120px;
_46
background: var(--card-bg, #fff);
_46
color: var(--card-clr, #222222);
_46
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_46
}
_46
_46
.quote-card p {
_46
font-size: 22px;
_46
line-height: 1.5;
_46
margin: 0;
_46
max-width: 80%;
_46
}
_46
_46
.quote-card cite {
_46
font-size: 16px;
_46
margin-top: 10px;
_46
display: block;
_46
font-weight: 200;
_46
opacity: 0.8;
_46
}
_46
_46
.quote-card:before {
_46
content: "โ€œ";
_46
font-size: 5em;
_46
font-family: Georgia, serif;
_46
font-weight: normal;
_46
color: var(--quote-clr, rgba(238, 238, 238, 0.8));
_46
}

  • position the quote the absolute to break the normal flow
  • position the card relative so that quote starts from the card
  • Adjust position slightly to the top-left
index.html
src/styles.css
Copy

_50
@charset "UTF-8";
_50
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_50
body {
_50
background: #eee;
_50
font-family: "Source Sans Pro", sans-serif;
_50
font-weight: 300;
_50
}
_50
_50
.container {
_50
max-width: 800px;
_50
margin: 40px auto;
_50
}
_50
_50
.quote-card {
_50
padding: 20px;
_50
padding-left: 50px;
_50
box-sizing: border-box;
_50
overflow: hidden;
_50
min-height: 120px;
_50
background: var(--card-bg, #fff);
_50
color: var(--card-clr, #222222);
_50
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_50
position: relative;
_50
}
_50
_50
.quote-card p {
_50
font-size: 22px;
_50
line-height: 1.5;
_50
margin: 0;
_50
max-width: 80%;
_50
}
_50
_50
.quote-card cite {
_50
font-size: 16px;
_50
margin-top: 10px;
_50
display: block;
_50
font-weight: 200;
_50
opacity: 0.8;
_50
}
_50
_50
.quote-card:before {
_50
content: "โ€œ";
_50
top: 10px;
_50
left: 10px;
_50
font-size: 5em;
_50
font-family: Georgia, serif;
_50
font-weight: normal;
_50
position: absolute;
_50
color: var(--quote-clr, rgba(238, 238, 238, 0.8));
_50
}

  • Choosing โ€ as a decoration character to close the quote
  • Same as before quote but larger and positioned to the bottom-right
index.html
src/styles.css
Copy

_62
@charset "UTF-8";
_62
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_62
body {
_62
background: #eee;
_62
font-family: "Source Sans Pro", sans-serif;
_62
font-weight: 300;
_62
}
_62
_62
.container {
_62
max-width: 800px;
_62
margin: 40px auto;
_62
}
_62
_62
.quote-card {
_62
padding: 20px;
_62
padding-left: 50px;
_62
box-sizing: border-box;
_62
overflow: hidden;
_62
min-height: 120px;
_62
background: var(--card-bg, #fff);
_62
color: var(--card-clr, #222222);
_62
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_62
position: relative;
_62
}
_62
_62
.quote-card p {
_62
font-size: 22px;
_62
line-height: 1.5;
_62
margin: 0;
_62
max-width: 80%;
_62
}
_62
_62
.quote-card cite {
_62
font-size: 16px;
_62
margin-top: 10px;
_62
display: block;
_62
font-weight: 200;
_62
opacity: 0.8;
_62
}
_62
_62
.quote-card:before {
_62
content: "โ€œ";
_62
top: 10px;
_62
left: 10px;
_62
font-size: 5em;
_62
font-family: Georgia, serif;
_62
font-weight: normal;
_62
position: absolute;
_62
color: var(--quote-clr, rgba(238, 238, 238, 0.8));
_62
}
_62
_62
.quote-card:after {
_62
content: "โ€";
_62
bottom: -110px;
_62
line-height: 100px;
_62
right: -32px;
_62
font-size: 25em;
_62
font-family: Georgia, serif;
_62
font-weight: normal;
_62
position: absolute;
_62
color: var(--quote-clr, rgba(238, 238, 238, 0.8));
_62
}

  • Take common CSS & comma separate it
  • Distribute the difference to :before & :after (position & size)
index.html
src/styles.css
Copy

_62
@charset "UTF-8";
_62
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_62
body {
_62
background: #eee;
_62
font-family: "Source Sans Pro", sans-serif;
_62
font-weight: 300;
_62
}
_62
_62
.container {
_62
max-width: 800px;
_62
margin: 40px auto;
_62
}
_62
_62
.quote-card {
_62
padding: 20px;
_62
padding-left: 50px;
_62
box-sizing: border-box;
_62
overflow: hidden;
_62
min-height: 120px;
_62
background: var(--card-bg, #fff);
_62
color: var(--card-clr, #222222);
_62
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_62
position: relative;
_62
}
_62
_62
.quote-card p {
_62
font-size: 22px;
_62
line-height: 1.5;
_62
margin: 0;
_62
max-width: 80%;
_62
}
_62
_62
.quote-card cite {
_62
font-size: 16px;
_62
margin-top: 10px;
_62
display: block;
_62
font-weight: 200;
_62
opacity: 0.8;
_62
}
_62
_62
.quote-card:before,
_62
.quote-card:after {
_62
font-family: Georgia, serif;
_62
font-weight: normal;
_62
position: absolute;
_62
color: var(--quote-clr, rgba(238, 238, 238, 0.8));
_62
}
_62
_62
.quote-card:before {
_62
content: "โ€œ";
_62
top: 10px;
_62
left: 10px;
_62
font-size: 5em;
_62
}
_62
_62
.quote-card:after {
_62
content: "โ€";
_62
bottom: -110px;
_62
line-height: 100px;
_62
right: -32px;
_62
font-size: 25em;
_62
}

Makes the quote smaller on phone screens

index.html
src/styles.css
Copy

_69
@charset "UTF-8";
_69
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_69
body {
_69
background: #eee;
_69
font-family: "Source Sans Pro", sans-serif;
_69
font-weight: 300;
_69
}
_69
_69
.container {
_69
max-width: 800px;
_69
margin: 40px auto;
_69
}
_69
_69
.quote-card {
_69
padding: 20px;
_69
padding-left: 50px;
_69
box-sizing: border-box;
_69
overflow: hidden;
_69
min-height: 120px;
_69
background: var(--card-bg, #fff);
_69
color: var(--card-clr, #222222);
_69
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_69
position: relative;
_69
}
_69
_69
.quote-card p {
_69
font-size: 22px;
_69
line-height: 1.5;
_69
margin: 0;
_69
max-width: 80%;
_69
}
_69
_69
.quote-card cite {
_69
font-size: 16px;
_69
margin-top: 10px;
_69
display: block;
_69
font-weight: 200;
_69
opacity: 0.8;
_69
}
_69
_69
.quote-card:before,
_69
.quote-card:after {
_69
font-family: Georgia, serif;
_69
font-weight: normal;
_69
position: absolute;
_69
color: var(--quote-clr, rgba(238, 238, 238, 0.8));
_69
}
_69
_69
.quote-card:before {
_69
content: "โ€œ";
_69
top: 10px;
_69
left: 10px;
_69
font-size: 5em;
_69
}
_69
_69
.quote-card:after {
_69
content: "โ€";
_69
bottom: -110px;
_69
line-height: 100px;
_69
right: -32px;
_69
font-size: 25em;
_69
}
_69
_69
@media (max-width: 640px) {
_69
.quote-card:after {
_69
font-size: 22em;
_69
right: -25px;
_69
}
_69
}

Make another quote card to customize it later

index.html
src/styles.css
Copy

_26
<!DOCTYPE html>
_26
<html>
_26
<head>
_26
<title>Parcel Sandbox</title>
_26
<meta charset="UTF-8" />
_26
</head>
_26
<body>
_26
<div class="container">
_26
<blockquote class="quote-card">
_26
<p>
_26
Dream is not what you see in sleep, dream is something which doesn't
_26
let you sleep.
_26
</p>
_26
_26
<cite> A. P. J. Abdul Kalam </cite>
_26
</blockquote>
_26
_26
<blockquote class="quote-card">
_26
<p>Arise! Awake! and stop not until the goal is reached.</p>
_26
_26
<cite> Swami Vivekananda </cite>
_26
</blockquote>
_26
</div>
_26
<script src="src/index.js"></script>
_26
</body>
_26
</html>

Add blue-card class to customize it

index.html
src/styles.css
Copy

_26
<!DOCTYPE html>
_26
<html>
_26
<head>
_26
<title>Parcel Sandbox</title>
_26
<meta charset="UTF-8" />
_26
</head>
_26
<body>
_26
<div class="container">
_26
<blockquote class="quote-card">
_26
<p>
_26
Dream is not what you see in sleep, dream is something which doesn't
_26
let you sleep.
_26
</p>
_26
_26
<cite> A. P. J. Abdul Kalam </cite>
_26
</blockquote>
_26
_26
<blockquote class="quote-card blue-card">
_26
<p>Arise! Awake! and stop not until the goal is reached.</p>
_26
_26
<cite> Swami Vivekananda </cite>
_26
</blockquote>
_26
</div>
_26
<script src="src/index.js"></script>
_26
</body>
_26
</html>

Use CSS variable to create a blue variant, the variable will override the value that we have used in the .quote-card

index.html
src/styles.css
Copy

_77
@charset "UTF-8";
_77
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_77
body {
_77
background: #eee;
_77
font-family: "Source Sans Pro", sans-serif;
_77
font-weight: 300;
_77
}
_77
_77
.container {
_77
max-width: 800px;
_77
margin: 40px auto;
_77
}
_77
_77
.quote-card {
_77
padding: 20px;
_77
padding-left: 50px;
_77
box-sizing: border-box;
_77
overflow: hidden;
_77
min-height: 120px;
_77
background: var(--card-bg, #fff);
_77
color: var(--card-clr, #222222);
_77
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_77
position: relative;
_77
}
_77
_77
.quote-card p {
_77
font-size: 22px;
_77
line-height: 1.5;
_77
margin: 0;
_77
max-width: 80%;
_77
}
_77
_77
.quote-card cite {
_77
font-size: 16px;
_77
margin-top: 10px;
_77
display: block;
_77
font-weight: 200;
_77
opacity: 0.8;
_77
}
_77
_77
.quote-card:before,
_77
.quote-card:after {
_77
font-family: Georgia, serif;
_77
font-weight: normal;
_77
position: absolute;
_77
color: var(--quote-clr, rgba(238, 238, 238, 0.8));
_77
}
_77
_77
.quote-card:before {
_77
content: "โ€œ";
_77
top: 10px;
_77
left: 10px;
_77
font-size: 5em;
_77
}
_77
_77
.quote-card:after {
_77
content: "โ€";
_77
bottom: -110px;
_77
line-height: 100px;
_77
right: -32px;
_77
font-size: 25em;
_77
}
_77
_77
@media (max-width: 640px) {
_77
.quote-card:after {
_77
font-size: 22em;
_77
right: -25px;
_77
}
_77
}
_77
_77
.quote-card.blue-card {
_77
--card-bg: #303f9f;
_77
--card-clr: #ffffff;
_77
--card-shadow: 0 1px 2px rgba(34, 34, 34, 0.12),
_77
0 2px 4px rgba(34, 34, 34, 0.24);
_77
--quote-clr: #3f51b5;
_77
}

Make another quote card with red-card to theme it red

index.html
src/styles.css
Copy

_35
<!DOCTYPE html>
_35
<html>
_35
<head>
_35
<title>Parcel Sandbox</title>
_35
<meta charset="UTF-8" />
_35
</head>
_35
<body>
_35
<div class="container">
_35
<blockquote class="quote-card">
_35
<p>
_35
Dream is not what you see in sleep, dream is something which doesn't
_35
let you sleep.
_35
</p>
_35
_35
<cite> A. P. J. Abdul Kalam </cite>
_35
</blockquote>
_35
_35
<blockquote class="quote-card blue-card">
_35
<p>Arise! Awake! and stop not until the goal is reached.</p>
_35
_35
<cite> Swami Vivekananda </cite>
_35
</blockquote>
_35
_35
<blockquote class="quote-card red-card">
_35
<p>
_35
INSANITY: Doing the same thing over and over again and expecting
_35
different results.
_35
</p>
_35
_35
<cite> Albert Einstein </cite>
_35
</blockquote>
_35
</div>
_35
<script src="src/index.js"></script>
_35
</body>
_35
</html>

Use CSS variable to create a red variant, the variable will override the value that we have used in the .quote-card

index.html
src/styles.css
Copy

_85
@charset "UTF-8";
_85
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_85
body {
_85
background: #eee;
_85
font-family: "Source Sans Pro", sans-serif;
_85
font-weight: 300;
_85
}
_85
_85
.container {
_85
max-width: 800px;
_85
margin: 40px auto;
_85
}
_85
_85
.quote-card {
_85
padding: 20px;
_85
padding-left: 50px;
_85
box-sizing: border-box;
_85
overflow: hidden;
_85
min-height: 120px;
_85
background: var(--card-bg, #fff);
_85
color: var(--card-clr, #222222);
_85
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_85
position: relative;
_85
}
_85
_85
.quote-card p {
_85
font-size: 22px;
_85
line-height: 1.5;
_85
margin: 0;
_85
max-width: 80%;
_85
}
_85
_85
.quote-card cite {
_85
font-size: 16px;
_85
margin-top: 10px;
_85
display: block;
_85
font-weight: 200;
_85
opacity: 0.8;
_85
}
_85
_85
.quote-card:before,
_85
.quote-card:after {
_85
font-family: Georgia, serif;
_85
font-weight: normal;
_85
position: absolute;
_85
color: var(--quote-clr, rgba(238, 238, 238, 0.8));
_85
}
_85
_85
.quote-card:before {
_85
content: "โ€œ";
_85
top: 10px;
_85
left: 10px;
_85
font-size: 5em;
_85
}
_85
_85
.quote-card:after {
_85
content: "โ€";
_85
bottom: -110px;
_85
line-height: 100px;
_85
right: -32px;
_85
font-size: 25em;
_85
}
_85
_85
@media (max-width: 640px) {
_85
.quote-card:after {
_85
font-size: 22em;
_85
right: -25px;
_85
}
_85
}
_85
_85
.quote-card.blue-card {
_85
--card-bg: #303f9f;
_85
--card-clr: #ffffff;
_85
--card-shadow: 0 1px 2px rgba(34, 34, 34, 0.12),
_85
0 2px 4px rgba(34, 34, 34, 0.24);
_85
--quote-clr: #3f51b5;
_85
}
_85
_85
.quote-card.red-card {
_85
--card-bg: #d32f2f;
_85
--card-clr: #ffffff;
_85
--card-shadow: 0 1px 2px rgba(34, 34, 34, 0.12),
_85
0 2px 4px rgba(34, 34, 34, 0.24);
_85
--quote-clr: #f44336;
_85
}

Make another quote card with yellow-card to theme it yellow

index.html
src/styles.css
Copy

_44
<!DOCTYPE html>
_44
<html>
_44
<head>
_44
<title>Parcel Sandbox</title>
_44
<meta charset="UTF-8" />
_44
</head>
_44
<body>
_44
<div class="container">
_44
<blockquote class="quote-card">
_44
<p>
_44
Dream is not what you see in sleep, dream is something which doesn't
_44
let you sleep.
_44
</p>
_44
_44
<cite> A. P. J. Abdul Kalam </cite>
_44
</blockquote>
_44
_44
<blockquote class="quote-card blue-card">
_44
<p>Arise! Awake! and stop not until the goal is reached.</p>
_44
_44
<cite> Swami Vivekananda </cite>
_44
</blockquote>
_44
_44
<blockquote class="quote-card red-card">
_44
<p>
_44
INSANITY: Doing the same thing over and over again and expecting
_44
different results.
_44
</p>
_44
_44
<cite> Albert Einstein </cite>
_44
</blockquote>
_44
_44
<blockquote class="quote-card yellow-card">
_44
<p>
_44
Yesterday is history. Tomorrow is a mystery. Today is a gift. Thatโ€™s
_44
why we call it โ€˜The Presentโ€™
_44
</p>
_44
_44
<cite> Eleanor Roosevelt </cite>
_44
</blockquote>
_44
</div>
_44
<script src="src/index.js"></script>
_44
</body>
_44
</html>

Use CSS variable to create a yellow variant, the variable will override the value that we have used in the .quote-card

index.html
src/styles.css
Copy

_93
@charset "UTF-8";
_93
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,200italic);
_93
body {
_93
background: #eee;
_93
font-family: "Source Sans Pro", sans-serif;
_93
font-weight: 300;
_93
}
_93
_93
.container {
_93
max-width: 800px;
_93
margin: 40px auto;
_93
}
_93
_93
.quote-card {
_93
padding: 20px;
_93
padding-left: 50px;
_93
box-sizing: border-box;
_93
overflow: hidden;
_93
min-height: 120px;
_93
background: var(--card-bg, #fff);
_93
color: var(--card-clr, #222222);
_93
box-shadow: var(--card-shadow, 0 2px 4px rgba(34, 34, 34, 0.12));
_93
position: relative;
_93
}
_93
_93
.quote-card p {
_93
font-size: 22px;
_93
line-height: 1.5;
_93
margin: 0;
_93
max-width: 80%;
_93
}
_93
_93
.quote-card cite {
_93
font-size: 16px;
_93
margin-top: 10px;
_93
display: block;
_93
font-weight: 200;
_93
opacity: 0.8;
_93
}
_93
_93
.quote-card:before,
_93
.quote-card:after {
_93
font-family: Georgia, serif;
_93
font-weight: normal;
_93
position: absolute;
_93
color: var(--quote-clr, rgba(238, 238, 238, 0.8));
_93
}
_93
_93
.quote-card:before {
_93
content: "โ€œ";
_93
top: 10px;
_93
left: 10px;
_93
font-size: 5em;
_93
}
_93
_93
.quote-card:after {
_93
content: "โ€";
_93
bottom: -110px;
_93
line-height: 100px;
_93
right: -32px;
_93
font-size: 25em;
_93
}
_93
_93
@media (max-width: 640px) {
_93
.quote-card:after {
_93
font-size: 22em;
_93
right: -25px;
_93
}
_93
}
_93
_93
.quote-card.blue-card {
_93
--card-bg: #303f9f;
_93
--card-clr: #ffffff;
_93
--card-shadow: 0 1px 2px rgba(34, 34, 34, 0.12),
_93
0 2px 4px rgba(34, 34, 34, 0.24);
_93
--quote-clr: #3f51b5;
_93
}
_93
_93
.quote-card.red-card {
_93
--card-bg: #d32f2f;
_93
--card-clr: #ffffff;
_93
--card-shadow: 0 1px 2px rgba(34, 34, 34, 0.12),
_93
0 2px 4px rgba(34, 34, 34, 0.24);
_93
--quote-clr: #f44336;
_93
}
_93
_93
.quote-card.yellow-card {
_93
--card-bg: #f9a825;
_93
--card-clr: #222222;
_93
--card-shadow: 0 1px 2px rgba(34, 34, 34, 0.12),
_93
0 2px 4px rgba(34, 34, 34, 0.24);
_93
--quote-clr: #fbc02d;
_93
}

Let's start with a semantic blockquote element

  • Style the container in center of the screen with responsive width
  • box-sizing to include padding in its width
  • Left side slightly indented
  • Creating nice box for quote card
  • Para content
  • Cite author name
  • Adding CSS variable for colors & shadow with fallback
  • CSS Variable makes it easier to create variants with different themes
  • CSS Variable gets inherited and can be easily overridden

Makes the quote wordings larger and limits its width

Makes the cite wordings slimer & a little transparent

  • Choosing โ€œ as a decoration character
  • Makes it a nicer & larger font
  • Color blend with background
  • position the quote the absolute to break the normal flow
  • position the card relative so that quote starts from the card
  • Adjust position slightly to the top-left
  • Choosing โ€ as a decoration character to close the quote
  • Same as before quote but larger and positioned to the bottom-right
  • Take common CSS & comma separate it
  • Distribute the difference to :before & :after (position & size)

Makes the quote smaller on phone screens

Make another quote card to customize it later

Add blue-card class to customize it

Use CSS variable to create a blue variant, the variable will override the value that we have used in the .quote-card

Make another quote card with red-card to theme it red

Use CSS variable to create a red variant, the variable will override the value that we have used in the .quote-card

Make another quote card with yellow-card to theme it yellow

Use CSS variable to create a yellow variant, the variable will override the value that we have used in the .quote-card

index.html
src/styles.css
CopyExpandClose

_13
<!DOCTYPE html>
_13
<html>
_13
<head>
_13
<title>Parcel Sandbox</title>
_13
<meta charset="UTF-8" />
_13
</head>
_13
<body>
_13
<div class="container">
_13
<blockquote class="quote-card"></blockquote>
_13
</div>
_13
<script src="src/index.js"></script>
_13
</body>
_13
</html>

@ragavkumarv
swipe to next โžก๏ธ