前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >一些伪元素的小玩意儿

一些伪元素的小玩意儿

作者头像
练小习
发布2017-12-29 14:46:13
5660
发布2017-12-29 14:46:13
举报
文章被收录于专栏:练小习的专栏练小习的专栏

在shadow的处理上,text-shadow本身就能很好的完成投影效果

  1. text-shadow: #666 1px 1px 0;

用伪元素虽然可以完成一模一样的投影,但总归是多了一堆代码。

  1. .after{
  2. position: relative;
  3. display: block;
  4. color: #ff9900;
  5. margin:20px 100px;
  6. }
  7. .after:after{
  8. position: absolute;
  9. display: block;
  10. top:1px;
  11. left: 1px;
  12. font-size:16px;
  13. color: #666;
  14. content: attr(data-text);
  15. z-index: -1;
  16. }

不过,伪元素既然可以多出来可以控制的标签,必然可以实现更多的效果,比如下面这个demo里。。。。。

<!DOCTYPE html>

<html>

<head>

<title></title>

<style type="text/css">

body{

font-size:16px;

line-height: 14px;

color: #333;

}

.after{

position: relative;

display: block;

color: #ff9900;

margin:20px 100px;

}

.after:after{

position: absolute;

display: block;

top:1px;

left: 1px;

font-size:16px;

color: #666;

content: attr(data-text);

z-index: -1;

}

.shadow{

display: block;

color: #ff9900;

margin:20px 100px;

text-shadow: #666 1px 1px 0;

}

.after-2{

position: relative;

display: block;

color: #ff9900;

margin:20px 100px;

overflow: hidden;

height: 14px;

}

.after-2:after{

position: absolute;

display: block;

top: 0px;

left: 0px;

color: #666;

content: attr(data-text);

z-index: 1;

overflow: hidden;

height: 7px;

}

.after-3{

position: relative;

display: block;

color: #ff9900;

margin:20px 100px;

overflow: hidden;

height: 14px;

}

.after-3:after{

position: absolute;

display: block;

top: 0px;

left: 0px;

color: #87CEFA;

content: attr(data-text);

z-index: 2;

overflow: hidden;

height: 4px;

}

.after-3:before{

position: absolute;

display: block;

top: 0px;

left: 0px;

color: #FF00FF;

content: attr(data-text);

z-index: 1;

overflow: hidden;

height: 10px;

}

</style>

</head>

<body>

<p class="shadow">shadow字体投影效果</p>

<p data-text="伪元素字体投影效果" class="after">伪元素字体投影效果</p>

<p data-text="伪元素字体效果" class="after-2">伪元素字体效果</p>

<p data-text="伪元素字体效果" class="after-3">伪元素字体效果</p>

</body>

</body>

</html>

提示:你可以先修改部分代码再运行。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档