CSS3中text-shadow实现文字阴影效果(代码实例 )


本文摘自PHP中文网,作者易达,侵删。

本文目标:

1、掌握text-shadow的用法

问题:

使用纯div+css实现以下效果

实现效果.png

附加说明:

1、文字总共有4个分别是:Belive Yourself You Can

2、文字大小为86px

3、右边文字和左边文字的间距为20px

4、图片大小 宽为:100px

5、阴影的水平平移量为15px,垂直平移量为2,模糊度为20,颜色为#333333

具体操作如下:

1、准备素材,新建images目录,将图片文件存于此目录,方便管理,素材有

youcan.png

2、创建好index.html,写好架构,架构如何分析呢

思路分析:

1、架构分成上下两部分,上面部分显示2个英文单词,一个是Belive一个是Yourself,但是文字带阴影效果

2、架构的下面部分也显示2个英文单词+一个图片,英文单词一个是You一个是Can,文字也是要带阴影效果

根据分析,我们得出以下代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>text-shadow实现文字阴影</title>

 

</head>

<body>

<div class="container">

    <div class="top">

        <strong class="word">Belive</strong>

        <strong class="word rword">Yourself</strong>

    </div>

    <div class="bottom">

        <strong class="word">You</strong>

        <strong class="word rword">Can</strong>

        <img src="images/youcan.png" />

    </div>

</div>

</body>

</html>

3、写样式,创建css目录,里面新建文件index.css,css里面的思路分析如下

思路分析:

1、.container *

思路分析

1、为了设置容器里的所有元素的公共样式,我们可以将这些公共代码写入.container * 样式内

所以index.css中添加代码如下:

1

2

3

4

.container *{

    padding:0;

    margin:0;

}

2、.word 文字

思路分析:

1、根据要求得知,文字大小为86px,且带阴影效果,根据要求的阴影设置,于是转成代码为 text-shadow: 15px 2px 20px #333333;

所以index.css添加代码如下

1

2

3

4

.word{

    font-size: 86px;

    text-shadow: 15px 2px 20px #333333;

}

3、rword 右边文字

思路分析:

1、根据要求得知,右边文字和左边文字的间距为20px,所以 margin-left:20px;

所以index.css添加代码如下

1

2

3

.rword{

     margin-left:20px;

}

4、图片设置

思路分析:

1、根据要求得知,宽=100px,然后它和左边文字的间距为10px

所以index.css添加代码如下

1

2

3

4

.bottom img{

    margin-left:10px;

    width:100px;

}

到此为止,index.css的全部内容如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

.container *{

    padding:0;

    margin:0;

}

 

.word{

    font-size: 86px;

    text-shadow: 15px 2px 20px #333333;

}

 

.rword{

    margin-left:20px;

}

.bottom img{

    margin-left:10px;

    width:100px;

}

接下来,将index.css引入index.html中

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>text-shadow实现文字阴影</title>

<link rel="stylesheet" href="css/index.css" />

</head>

<body>

<div class="container">

    <div class="top">

        <strong class="word">Belive</strong>

        <strong class="word rword">Yourself</strong>

    </div>

    <div class="bottom">

        <strong class="word">You</strong>

        <strong class="word rword">Can</strong>

        <img src="images/youcan.png" />

    </div>

</div>

</body>

</html>

运行结果如下:

1.png

到此为止,我们就实现了全部的需求

总结:

1、学习了text-shadow的用法,主要格式为:text-shadow: 水平偏移量 垂直偏移量 模糊度 颜色

偏移量可正可负,正表示水平向左或者垂直向下,负数则相反

希望本文能给大家带来一定的帮助,谢谢!!!

以上就是CSS3中text-shadow实现文字阴影效果(代码实例 )的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

CSS3有哪些新特性?CSS3新特性详解

flex作用于box容器上的属性介绍

text-emphasis属性有什么用

text-wrap属性怎么使用

CSS3 nav-right属性怎么用?

css与CSS3的区别是什么

html5/CSS3 网页加载进度条的实现,下载进度条等经典案例

利用CSS3进行弹性布局时内容对齐的方法详解

CSS3新特性有哪些

css怎么让图案上下浮动

更多相关阅读请进入《CSS3》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...