Get the hang of CSS box-shadow.
Introduction⌗
The CSS property box-shadow is used to set a shadow on an element. This can be to add emphasis on an element or to make it stand out from other elements in the document.
Syntax⌗
The box-shadow
CSS property has the following syntax:
box-shadow: [horizontal offset] [vertical offset] [blur radius] [optional spread radius] [color];
Horizontal offset⌗
This is required. When the value is positive, the shadow will appear on the right side of the element. When the value is negative, the shadow will appear on the left side of the element.
Example⌗
box-shadow: 10px 5px 5px red;
box-shadow: -10px 5px 5px red;
Vertical offset⌗
This is required. When the value is positive, the shadow will appear at the bottom of the element. When it is negative, the shadow will appear at the top of the element.
Example⌗
box-shadow: 10px 5px 5px red;
Blur Radius⌗
This is required. It determines how visible (blurred) you want the shadow to be. A blur radius of 0 will be sharp. The higher the value of the blur then the blurrier it becomes. When you set a blur radius of 5px and a horizontal offset of 5px then you end up with 10px of total shadow.
Example⌗
box-shadow: 10px 5px 0px red;
You can see from Fig 4
the total shadow of 10px when you set a blur radius of 5px and a horizontal offset of 5px.
Spread Radius⌗
This is optional. It determines the size of the shadow. A positive value increases the shadow and a negative one decreases it. The default value is 0.
box-shadow: 10px 5px 5px 10px red;
Color⌗
This is required. It takes any color value, like hex, named, rgba or hsla.
Inset⌗
This is optional. It is used to set the shadow inside the element.
Example⌗
box-shadow: inset 10px 5px 5px red;
Conclusion⌗
This article introduces you to the basics of using a box-shadow
and explains what the options of the box-shadow
are available and how to use them. You can now go further and create smoother box shadows or multiple box shadows by manipulating these basics.
You can find the working code used in this article here1.
For further reading:
No comments yet!