找回密码
 立即注册
搜索
热搜: 活动 交友
查看: 2318|回复: 0

WordPress首页文章底部添加线条

[复制链接]

32

主题

0

回帖

116

积分

管理员

积分
116
发表于 2024-12-18 11:35:05 | 显示全部楼层 |阅读模式
前言
在某个网站看到鼠标放到首页文章,它的底部会出现线条,于是就突发奇想想给自己网站弄一个
效果
别人的:
教程
请将如下两个代码中的任何一个添加到子主题的CSS文件夹中的main.css 中或在主题设置中添加自定义css代码
1.固定颜色
  1. .post-item {
  2.   position: relative;
  3. }

  4. .post-item::before {
  5.   content: "";
  6.   position: absolute;
  7.   bottom: 0;
  8.   left: 0;
  9.   width: 0;
  10.   height: 3px;
  11.   background: var(--color, #000);
  12.   transition: width 1s, background-color 0.5s; /* 添加了背景颜色的过渡效果 */
  13. }

  14. .post-item:hover::before {
  15.   width: 100%;
  16. }

  17. /* 使用计算来设置颜色 */
  18. .post-item:nth-of-type(1)::before {
  19.   --color: hsl(0, 100%, 50%); /* 设置第一个.post-item的线条颜色 */
  20. }

  21. .post-item:nth-of-type(2)::before {
  22.   --color: hsl(72, 100%, 50%); /* 设置第二个.post-item的线条颜色 */
  23. }

  24. .post-item:nth-of-type(3)::before {
  25.   --color: hsl(144, 100%, 50%); /* 设置第三个.post-item的线条颜色 */
  26. }

  27. .post-item:nth-of-type(4)::before {
  28.   --color: hsl(216, 100%, 50%); /* 设置第四个.post-item的线条颜色 */
  29. }

  30. .post-item:nth-of-type(5)::before {
  31.   --color: hsl(288, 100%, 50%); /* 设置第五个.post-item的线条颜色 */
  32. }

  33. .post-item:nth-of-type(6)::before {
  34.   --color: hsl(324, 100%, 50%); /* 设置第六个.post-item的线条颜色 */
  35. }

  36. .post-item:nth-of-type(7)::before {
  37.   --color: hsl(36, 100%, 50%); /* 设置第七个.post-item的线条颜色 */
  38. }

  39. .post-item:nth-of-type(8)::before {
  40.   --color: hsl(108, 100%, 50%); /* 设置第八个.post-item的线条颜色 */
  41. }

  42. .post-item:nth-of-type(9)::before {
  43.   --color: hsl(180, 100%, 50%); /* 设置第九个.post-item的线条颜色 */
  44. }

  45. .post-item:nth-of-type(10)::before {
  46.   --color: hsl(252, 100%, 50%); /* 设置第十个.post-item的线条颜色 */
  47. }
复制代码
2.动态颜色

  1. .post-item {
  2.   position: relative;
  3. }

  4. .post-item::before {
  5.   content: "";
  6.   position: absolute;
  7.   bottom: 0;
  8.   left: 0;
  9.   width: 0;
  10.   height: 3px;
  11.   background: var(--color, #000);
  12.   transition: width 1s;
  13. }

  14. .post-item:hover::before {
  15.   width: 100%;
  16. }

  17. .post-item:hover::before {
  18.   animation: randomColor 2s infinite;
  19. }

  20. @keyframes randomColor {
  21.   0% {
  22.     background: red;
  23.   }
  24.   25% {
  25.     background: blue;
  26.   }
  27.   50% {
  28.     background: green;
  29.   }
  30.   75% {
  31.     background: yellow;
  32.   }
  33.   100% {
  34.     background: purple;
  35.   }
  36. }
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【赶紧来试试吧】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|奥多也网络 ( 粤ICP备2020119241号 )

GMT+8, 2025-12-9 05:45 , Processed in 0.075573 second(s), 27 queries .

Powered by AODUOYE

©2017-2026

快速回复 返回顶部 返回列表