As we all know, CSS provides us with a wide range of properties and pseudo-classes that enable developers to add desired styles to elements. One of these properties is theBoxShadow property; it allows us to add a shadow-like effect around an element.
Box Shadow is a CSS property used to create an outer or inner shadow effect on an element. It applies one or more shadows to an element, each specified by an X and Y offset from the element, a blur radius, a diffuse radius, a color, and an opacity value.
The box-shadow property can accept multiple values, separated by commas; each value defines a shadow effect. A box shadow without any offset will make it look like a flat shape, just like when printed on paper.
Assuming that the element we want to apply box-shadow to specifies some form of borderradius, the effect of box-shadow will also have a curved border like that element. Multiple box shadows are ordered on the z-axis in the same order as multiple text shadows.
We can use - to specify a box shadow for an element -
Two values- Whenever we use the box-shadow property with two values, they will be used as the values for the X and Y offset.
Three values- The first two values act as X and Y offset values, while the third value is used for the blur radius effect.
Four values- The fourth value is considered as the value of the diffusion radius, and the remaining values are the values of the X offset, Y offset, and blur radius respectively.
Inset- It is an optional value and its presence biases the frame's shadow to one side. If we don't specify this, the shadow will appear to be raised above, like a drop shadow
Color- This is another optional value that sets the color of the shadow. If not specified, the color defaults to the element's current color.
Its initial value is none and applies to all elements. The animation type of the shadow list can be used for animation, but it cannot be inherited.
An example of using the box-shadow property in CSS is given below.
Box Shadow This is an example of box shadow effect on elements
Another temporary line for extra text— Example of Box Shadow
Now that we understand the box Shadow property, we'll look at what "webkit" in CSS is and why we need it. Later we will discuss webkit box Shadow.
WebkitisApple's web browser engineused by nearly all macOS applications. There are many other web browser engines, such as Gecko for Firefox, Blink for edge, and many more. So, the question arises, why do we need them.
The -webkit prefix on a CSS selector indicates properties that are only processed by that engine, similar to the -moz property. By specifying this, we are basically telling the browser to only use it when using a specific browser engine, otherwise leave it as is. It's cumbersome to use; that's why many developers want it discontinued as soon as possible.
Like the box-shadow property, thewebkit-box-shadow propertyalso adds a shadow-like effect to the frame of the element to which it is applied. However, it is important to note that its implementation is specific to browsers such as Chrome or Apple Safari.
Possible values that can be assigned to this attribute are -
X-offset- It specifies the horizontal offset or distance to the element.
Y Offset- This also specifies an offset or distance, but in a vertical direction
Blur- It is a length value, if it is large, the blur effect created will be large, so the shadow effect will be larger, and vice versa.
An example of using web kit-box-shadow in CSS is given below.
Now that we understand these two properties, let's list the differences between them.
The box-shadow property is universally implemented, while "webkitbox-shadow" on the other hand only works in browsers using a specific web browser engine, i.e. Safari or Google Chrome.
The box Shadow property allows us to style the shadow effect in all recent versions, but if we have to work on older versions of browsers, we have to use webkit-box-shadow.
To summarize, the main difference between -webkit-box-shadow and box-shadow in CSS is that -webkit-box-shadow is the vendor prefix for the box-shadow property introduced by Webkit browsers. The box-shadow property allows you to apply a drop shadow effect to an element without using an image or other external resource. The -webkit-box-shadow attribute has been deprecated and replaced with standard box-shadow syntax. Because most modern browsers support it. In summary, both properties are used to create shadows on elements, but only one of them should be used as the other will be deprecated over time.
The above is the detailed content of The difference between -webkit-box-shadow and box-shadow in CSS. For more information, please follow other related articles on the PHP Chinese website!