应无所住,而生其心
排名
1
文章
860
粉丝
112
评论
163
net core webapi post传递参数
庸人 : 确实坑哈,我也是下班好了好几次,发现后台传递对象是可以的,但...
百度编辑器自定义模板
庸人 : 我建议换个编辑器,因为现在百度富文本已经停止维护了,用tinymec...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术

css3 伪类选择器 before和after。实现简单的标题。清楚浮动。红黄蓝效果。实现下方横线((下划线 ,下横线)),Tab菜单效果

3825人阅读 2015/12/9 11:12 总访问:5182858 评论:0 收藏:0 手机
分类: 前端

伪类选择器before和after,实现一个简单的标题效果

代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div class="quote">
  11. <span>亲爱的</span>
  12. </div>
  13. <style>
  14. .quote:before,
  15. .quote:after {
  16. content: "";
  17. display: inline-block;
  18. width: 50px;
  19. margin: 5px 1%;
  20. border-bottom: 1px solid blue;
  21. }
  22. </style>
  23. </body>
  24. </html>

伪类选择器 实现Tab菜单下横线的选中效果

设计图如下:其实就是实现下面那个横杠的选中效果:

html结构如下
是在vue里边写的

  1. <div class="tabmenu">
  2. <span class="item cur" @click="switchData($event, 'cur', true, false)">项目数据</span>
  3. <span class="item " @click="switchData($event, 'cur', false, true)">班级数据</span>
  4. </div>

样式如下,这里还用了相对定位和绝对定位的,要出现在下方

  1. .tabmenu {
  2. .item {
  3. display: inline-block;
  4. margin-right: 20px;
  5. font-size: 17px;
  6. font-family: Microsoft YaHei;
  7. cursor: pointer;
  8. }
  9. .cur {
  10. font-size: 20px;
  11. color: #23FFFC;
  12. position: relative;
  13. }
  14. .cur:after {
  15. content: "";
  16. display: inline-block;
  17. position: absolute;
  18. bottom: -12px;
  19. left: 13px;
  20. width: 59px;
  21. // 宽度也可以写成100%,这样就可以保持和父元素一样宽了
  22. // width: 100%;
  23. border-bottom: 3px solid #23FFFC;
  24. }
  25. }

效果2

如图,和上面那个几乎一样,多贴一个

html:

  1. <div class="feedback-container">
  2. <div class="title-wapper">
  3. <div :class="active == 'noread' ? 'cur' : ''" class="title " @click="switchRead(0, 'noread')">未读({{ noReadCount }})
  4. </div>
  5. <div :class="active == 'all' ? 'cur' : ''" class="title" style="margin-left: 15px;" @click="switchRead('', 'all')">
  6. 全部({{
  7. allCount }})</div>
  8. <div class="readBut" @click="allToRead()">全部已读</div>
  9. </div>
  10. <div class="split-line" />
  11. <div>...下方内容...</div>
  12. </div>

样式:

  1. .feedback-container {
  2. padding: 0 20px;
  3. .title-wapper {
  4. display: flex;
  5. height: 60px;
  6. // background-color: #ffabcd;
  7. line-height: 60px;
  8. align-items: center;
  9. }
  10. .title {
  11. font-family: MicrosoftYaHei-, MicrosoftYaHei;
  12. font-weight: normal;
  13. color: #333339;
  14. font-size: 16px;
  15. cursor: pointer;
  16. }
  17. .cur {
  18. color: #3E91F7;
  19. position: relative;
  20. }
  21. .cur:after {
  22. content: "";
  23. display: inline-block;
  24. position: absolute;
  25. bottom: 0px;
  26. // 这些间距都可以微调实现更好的效果
  27. left: -1px;
  28. // 宽度也可以写成100%,这样就可以保持和父元素一样宽了
  29. width: 100%;
  30. border-bottom: 2px solid #409eff;
  31. }
  32. .readBut {
  33. margin-left: auto;
  34. color: #007EFF;
  35. font-size: 14px;
  36. width: 90px;
  37. height: 31px;
  38. background: #FFFFFF;
  39. border-radius: 4px 4px 4px 4px;
  40. opacity: 1;
  41. border: 1px solid #007EFF;
  42. text-align: center;
  43. line-height: 31px;
  44. cursor: pointer;
  45. }
  46. .split-line {
  47. height: 1px;
  48. background: #EAEEF0;
  49. // width: 100%;
  50. margin-left: -20px;
  51. margin-right: -20px;
  52. }
  53. }

js方法也贴一下吧

  1. switchRead(isRead, readTag) {
  2. this.getMessage(1, isRead)
  3. // 控制菜单选中的标识
  4. this.active = readTag
  5. this.isReadTag = isRead
  6. // 切换过后重新成1开始吧
  7. this.pageIndex = 1
  8. },

伪类选择器 after清楚浮动

就不用在后面添加一个元素清除浮动了,比较方便

  1. .content::after
  2. {
  3. content: "";
  4. display: block;
  5. clear: both;
  6. }

伪类选择器 实现红黄蓝效果

代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div class="widget">
  11. <h3 class="widget-title">文章类别</h3>
  12. </div>
  13. <style>
  14. .widget
  15. {
  16. margin: 20px;
  17. width: 28%;
  18. }
  19. .widget h3.widget-title {
  20. font-size: 16px;
  21. color: #333;
  22. text-transform: uppercase;
  23. padding-bottom: 13px;
  24. margin-top: 5px;
  25. margin-bottom: 15px;
  26. position: relative;
  27. border-bottom: 1px solid #ddd;
  28. }
  29. .widget h3.widget-title:before {
  30. display: inline-block;
  31. z-index: 1;
  32. content: " ";
  33. position: absolute;
  34. -webkit-border-radius: 50%;
  35. border-radius: 50%;
  36. background: #f92900 !important;
  37. width: 10px;
  38. height: 10px;
  39. -webkit-box-shadow: 18px 0 #fbc606, 36px 0 #26c73d;
  40. box-shadow: 18px 0 #fbc606, 36px 0 #26c73d;
  41. /* float: right; */
  42. right: 40px;
  43. top: 5px;
  44. border-color: transparent;
  45. }
  46. .widget h3.widget-title:after {
  47. content: "";
  48. background-color: #666666;
  49. left: 0;
  50. width: 66px;
  51. height: 2px;
  52. bottom: -1px;
  53. position: absolute;
  54. -webkit-transition: 0.5s;
  55. -moz-transition: 0.5s;
  56. -ms-transition: 0.5s;
  57. -o-transition: 0.5s;
  58. transition: 0.5s;
  59. }
  60. .widget h3.widget-title:hover:after {
  61. width: 80px;
  62. }
  63. </style>
  64. </body>
  65. </html>

如果使用的是span的话,稍微变一点样式。贴个完整点的

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div class="widget">
  11. <span class="widget-title">文章类别</span>
  12. </div>
  13. <style>
  14. .widget
  15. {
  16. margin: 20px;
  17. width: 28%;
  18. }
  19. .widget .widget-title {
  20. font-size: 16px;
  21. color: #333;
  22. text-transform: uppercase;
  23. padding-bottom: 13px;
  24. margin-top: 5px;
  25. margin-bottom: 15px;
  26. position: relative;
  27. border-bottom: 1px solid #ddd;
  28. /* 如果是span要给宽度和块元素 */
  29. display: inline-block;
  30. width: 100%;
  31. }
  32. .widget .widget-title:before {
  33. display: inline-block;
  34. z-index: 1;
  35. content: " ";
  36. position: absolute;
  37. -webkit-border-radius: 50%;
  38. border-radius: 50%;
  39. background: #f92900 !important;
  40. width: 11px;
  41. height: 11px;
  42. -webkit-box-shadow: 18px 0 #fbc606, 36px 0 #26c73d;
  43. box-shadow: 18px 0 #fbc606, 36px 0 #26c73d;
  44. /* float: right; */
  45. right: 40px;
  46. top: 5px;
  47. border-color: transparent;
  48. }
  49. .widget .widget-title:after {
  50. content: "";
  51. background-color: #666666;
  52. left: 0;
  53. width: 66px;
  54. height: 2px;
  55. bottom: -1px;
  56. position: absolute;
  57. -webkit-transition: 0.5s;
  58. -moz-transition: 0.5s;
  59. -ms-transition: 0.5s;
  60. -o-transition: 0.5s;
  61. transition: 0.5s;
  62. }
  63. .widget .widget-title:hover:after {
  64. width: 80px;
  65. }
  66. </style>
  67. </body>
  68. </html>

欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)

评价

css3样式学习代码

上代码!上代码!不说了&lt;!DOCTYPEhtml&gt; &lt;htmllang=&quot;en&quot;&gt; &lt;head&gt; &lt;metacharset=&quot;UT...

HTML+css3+js 实现生日快乐代码动态生成效果

&lt;!DOCTYPEhtml&gt; &lt;html&gt; &lt;head&gt; &lt;metacharset=&quot;UTF-8&quot;&gt; &lt;title&gt;生日快乐&lt;/...

css3过渡渐变

code:&lt;!DOCTYPEhtml&gt; &lt;html&gt; &lt;head&gt; &lt;metacharset=&quot;utf-8&quot;&gt; &lt;title&gt;菜鸟教程...

css3 background-size

语法:div { background:url(img_flwr.gif); background-size:80px60px; background-repeat:no-repeat; }可以设置成10...

css3实现边框旋转但内容不动

其实思路就是把文字旋转的角度反向旋转抵消掉div旋转的角度即可 &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; ...

css3印章效果

配合bootstrap4来写的,效果图直接贴代码吧:直接复制运行即可看到效果:&lt;!DOCTYPEhtml&gt; &lt;html&gt; &lt;head&g...

css3 中的 nth-child

:nth-child(n)选择器用来定位某个父元素的一个或多个特定的子元素。其中“n”是其参数,而且可以是整数值(1,2,3,4),也可以...

css3伪类选择器 nth-child 循环变色循环颜色css最后一个元素

选中第一个元素:.container&gt;div:first-child{ background:#abcdff; }选中最后一个可以使用last-child.container&gt;d...

css3 实现ps文字外发光效果实现一串文字背后灯光高亮效果实现文字发光css实现实现文字背景高亮

CSS3 并没有直接设置发光效果的属性,但是利用text-shadow属性实现此效果text-shadow: h-shadow v-shadow blur color; 参...

使用css3实现一个不规则div的布局

要实现不规则的div布局,可以使用CSS3的clip-path属性。该属性可以剪切元素的形状,从而实现不规则的布局。以下是一个示例...

css3 渐变 两边浅中间深由中间向两边 div边框渐变色

设计图是这样的 可以使用线性渐变语法:background: linear-gradient(direction, color-stop1, color-stop2, …)例如从...

css图片文字对齐问题

文字和图片写到一排经常会出现对不齐的问题 这样感觉图片会上来一点没有和文字对齐,如下图 但是如果修改下html结...

微信交易单号订单号的区别

一般第三方在线支付系统中都会有两类订单号transactionId 为支付系统的订单号,由支付系统生成,并在回调时传回给商户,用...

C ?、?? 问号2个问号的用法(类型?、对象?)

C# ?C# ???:单问号1.定义数据类型可为空。可用于对int,double,bool等无法直接赋值为null的数据类型进行null的赋值如这...

C out、ref关键字的用法区别

说说自己对out、ref的认识,面试问到的几率很高哟。out:classProgram { /* *out、ref都是引用传递,传递后使用都会改变...