Opacity and shadow
The final pair of decorative properties that are explored in this section of the course are opacity
and box-shadow
. The first property adds transparency to a container, and the second one adds an outer shadow.
Opacity
The opacity
property defines how opaque the container is on a scale from 0
to 1
, where 0
is fully transparent and 1
is fully opaque:
<div style="opacity: 0.2;">0.2</div>
<div style="opacity: 0.4;">0.4</div>
<div style="opacity: 0.6;">0.6</div>
<div style="opacity: 0.8;">0.8</div>
<div style="opacity: 1;">1</div>
Shadow
The box-shadow
property allows you to add an outer shadow to a container:
<div style="box-shadow: 2px 8px 15px 2px rgba(0, 24, 64, 0.12);">
<!-- container’s content -->
</div>
box-shadow
expects five values in the particular order:
- Horizontal offset
- Vertical offset
- Blur radius
- Spread radius
- Color
You can apply multiple shadows separated by commas, if you want to create a more realistic effect:
<div style="box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
0 4px 6px -2px rgba(0, 0, 0, 0.05);">
<!-- container’s content -->
</div>
Practice
Add a shadow to the card design:
- Fork the starting prototype. It includes the layout and some necessary styles.
- Find an HTML shadow generator online. For example, you can use this one: https://cssgenerator.org/box-shadow-css-generator.html. Create a shadow and copy the
box-shadow
property. - Apply the copied
box-shadow
property to the main container. - Change the opacity of the subtitle, so it’s displayed half-transparent.