introduce
box-shadow
It is an attribute in CSS to add shadow effects to elements. It allows you to control the size, color, blur,Offsetand shadows inside and outside.
grammar
box-shadow: h-shadow v-shadow blur spread color inset;
-
h-shadow
: The horizontal shadow offset. -
v-shadow
: The shadow offset in the vertical direction. -
blur
: The blur radius of the shadow, optional parameters. -
spread
: Extended size of shadow, optional parameters. -
color
: The color of the shadow. -
inset
: Optional parameter to create inner shadow effects.
Example
-
.shadow {
-
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
-
}
-
-
.inner-shadow {
-
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
-
}
-
-
.multiple-shadows {
-
box-shadow:
-
2px 2px 4px rgba(0, 0, 0, 0.5),
-
-2px -2px 4px rgba(255, 255, 255, 0.3);
-
}
explain
-
.shadow
Elements of the class will have a shadow effect that is offset by 2 pixels to the lower right, with a radius of 4 pixels, a black color and a transparency of 0.5. -
.inner-shadow
Elements of the class will have an internal shadow effect, with a blur radius of 10 pixels, a black color and a transparency of 0.3. -
.multiple-shadows
Elements of the class will have two shadow effects at the same time, one offsets by 2 pixels to the lower right and the other offsets by 2 pixels to the upper left, with different colors and transparency respectively.
Summarize
By usingbox-shadow
Properties, you can easily add shadow effects to elements to enhance their appearance and visual effects. Adjusting the values of different parameters can achieve various shadow effects.
Hope this tutorial helps you understand and use itbox-shadow
property! If you have any other questions, feel free to ask.