search
HomeWeb Front-endCSS TutorialHow to add text shadow effect in css3? text-shadow sets the text shadow effect

The shadow effect is a common and very practical effect. I believe that some friends sometimes have some questions when using the shadow effect to make the web page beautiful, such as: how to set the shadow of the font and text, etc. So this chapter will tell you how to set the font text shadow in CSS3. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

In fact, there is a very practical attribute in css3 that can add a shadow effect to font text, that is css3 text-shadow attribute.

So, let’s take a detailed look at the text-shadow attribute first:

Text-shadow is a CSS style attribute word, which is used to set whether the text font of the text in the object has a shadow and blur effect. CSS styles.

text-shadow attribute: In CSS3, you can use the text-shadow attribute to add a shadow effect to the text on the page. You can achieve some required font shadow effects by setting relevant attribute values ​​​​to the text-shadow attribute. ,Reduce the use of pictures.

The syntax of the text-shadow attribute:

text-shadow: h-shadow v-shadow blur color;

It can be seen that the text-shadow attribute can set 4 parameters. Each parameter is separated by spaces. Let’s introduce these four parameters. :

h-shadow: Set the position of the horizontal shadow (x-axis direction), a required parameter; negative values ​​are allowed.
v-shadow: Set the position of the vertical shadow (y-axis direction), required parameters, negative values ​​allowed.
blur: The distance (radius size) of shadow blur, you can choose to set the parameters.
color: The color of the shadow, optional parameters to set.

Note: The text-shadow property can add one or more shadows to text. This property is a comma-separated list of shades, each shade specified with two or three length values ​​and an optional color value. The omitted length is 0.

Let’s take a look at a small example of css3 setting font text shadow to get a concrete understanding of the usage of the text-shadow attribute:

<h1 id="我是一段测试文字">我是一段测试文字</h1>
h1{
   color:powderblue; /*设置文字颜色*/
   text-shadow: 2px 3px 1px pink;/*添加字体文字的阴影*/
}

Rendering:

How to add text shadow effect in css3? text-shadow sets the text shadow effect

Let’s take a look at what will happen if the css3 text shadow effect is not set:

How to add text shadow effect in css3? text-shadow sets the text shadow effect

Description:

1. The horizontal offset of the shadow (h-shadow): it can take a positive value or a negative value. If the value is positive, the shadow is on the right side of the object, and vice versa. When the value is negative, the shadow is to the left of the object.

2. The vertical offset of the shadow (v-shadow): It can take a positive value or a negative value. If it is a positive value, the shadow is at the bottom of the object. Otherwise, when the value is a negative value, the shadow on top of the object.

3. Shadow blur radius: can only be set to positive values. If the value is larger, the shadow will be blurry, otherwise the shadow will be clearer. If its value is 0, it means that the shadow has no blur effect.

4. Shadow color: When no color value is specified, the browser will use the default color, but the default color of each browser is different, especially Safari and Chrome browsers under the webkit kernel will not Color, that is, transparency, it is recommended not to omit this parameter.

Speaking of the different default colors of browsers, let’s take a look at whether the text-shadow attribute is supported in various browsers:

Browser support:

How to add text shadow effect in css3? text-shadow sets the text shadow effect

All major browsers support the text-shadow attribute.

Note: Internet Explorer 9 and earlier browsers do not support the text-shadow attribute.

The above is the detailed content of How to add text shadow effect in css3? text-shadow sets the text shadow effect. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Scroll-Driven Animations Inside a CSS CarouselScroll-Driven Animations Inside a CSS CarouselMay 16, 2025 am 09:50 AM

Hey, isn't there a fairly new CSS feature that works with scroll regions? Oh yes, that's Scroll-Driven Animations. Shouldn't that mean we can trigger an animation while scrolling through the items in a CSS carousel?

CSS Inclusion: Choosing the Right Method for Your ProjectCSS Inclusion: Choosing the Right Method for Your ProjectMay 16, 2025 am 12:02 AM

ThebestmethodforincludingCSSdependsonprojectsizeandcomplexity:1)Forlargerprojects,useexternalCSSforbettermaintainabilityandperformance.2)Forsmallerprojects,internalCSSissuitabletoavoidextraHTTPrequests.Alwaysconsidermaintainabilityandperformancewhenc

This Isn't Supposed to Happen: Troubleshooting the ImpossibleThis Isn't Supposed to Happen: Troubleshooting the ImpossibleMay 15, 2025 am 10:32 AM

What it looks like to troubleshoot one of those impossible issues that turns out to be something totally else you never thought of.

@keyframes vs CSS Transitions: What is the difference?@keyframes vs CSS Transitions: What is the difference?May 14, 2025 am 12:01 AM

@keyframesandCSSTransitionsdifferincomplexity:@keyframesallowsfordetailedanimationsequences,whileCSSTransitionshandlesimplestatechanges.UseCSSTransitionsforhovereffectslikebuttoncolorchanges,and@keyframesforintricateanimationslikerotatingspinners.

Using Pages CMS for Static Site Content ManagementUsing Pages CMS for Static Site Content ManagementMay 13, 2025 am 09:24 AM

I know, I know: there are a ton of content management system options available, and while I've tested several, none have really been the one, y'know? Weird pricing models, difficult customization, some even end up becoming a whole &

The Ultimate Guide to Linking CSS Files in HTMLThe Ultimate Guide to Linking CSS Files in HTMLMay 13, 2025 am 12:02 AM

Linking CSS files to HTML can be achieved by using elements in part of HTML. 1) Use tags to link local CSS files. 2) Multiple CSS files can be implemented by adding multiple tags. 3) External CSS files use absolute URL links, such as. 4) Ensure the correct use of file paths and CSS file loading order, and optimize performance can use CSS preprocessor to merge files.

CSS Flexbox vs Grid: a comprehensive reviewCSS Flexbox vs Grid: a comprehensive reviewMay 12, 2025 am 12:01 AM

Choosing Flexbox or Grid depends on the layout requirements: 1) Flexbox is suitable for one-dimensional layouts, such as navigation bar; 2) Grid is suitable for two-dimensional layouts, such as magazine layouts. The two can be used in the project to improve the layout effect.

How to Include CSS Files: Methods and Best PracticesHow to Include CSS Files: Methods and Best PracticesMay 11, 2025 am 12:02 AM

The best way to include CSS files is to use tags to introduce external CSS files in the HTML part. 1. Use tags to introduce external CSS files, such as. 2. For small adjustments, inline CSS can be used, but should be used with caution. 3. Large projects can use CSS preprocessors such as Sass or Less to import other CSS files through @import. 4. For performance, CSS files should be merged and CDN should be used, and compressed using tools such as CSSNano.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool