小白教程

 找回密码
 立即注册
查看: 6432|回复: 4

[已解决]a标签的使用问题

[复制链接]

1

主题

1

帖子

3

积分

新手上路

Rank: 1

积分
3
发表于 2021-4-14 14:31:20 | 显示全部楼层 |阅读模式
当一个标签要添加悬停时,鼠标悬停不显示悬停样式,只有单击后才显示悬停样式,并且TAB的悬停效果可以切换。我想知道它是如何在不使用js的情况下切换样式的。

最佳答案
2021-5-19 02:29:14
也许a的优先级有问题,我的是好的
  1. <!DOCTYPE html>
  2. <html lang="en">

  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Document</title>
  7.     <style>
  8.         .nav {
  9.             height: 41px;
  10.             border-top: 3px solid #ff8500;
  11.             border-bottom: 1px solid #edeef0;
  12.             background-color: #fcfcfc;
  13.             line-height: 41px;
  14.         }

  15.         .nav a {
  16.             display: inline-block;
  17.             /* 垂直对齐方式 */
  18.             vertical-align: top;
  19.             height: 41px;
  20.             padding: 0 20px;
  21.             font-size: 12px;
  22.             color: #4c4c4c;
  23.             text-decoration: none;
  24.         }

  25.         .nav a:hover {
  26.             color: orangered;
  27.             background-color: slategrey;

  28.         }
  29.     </style>
  30. </head>

  31. <body>
  32.     <div class="nav">
  33.         <a href="#">设为首页</a>
  34.         <a href="#">手机新浪网</a>
  35.         <a href="#">移动客户端</a>
  36.         <a href="#">博客</a>
  37.         <a href="#">微博</a>
  38.         <a href="#">关注我</a>
  39.     </div>
  40. </body>

  41. </html>
复制代码

本帖寻求最佳方案

,目前已有 4 个回复 我要奖励

本帖子中包含更多资源

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

x
回复

使用道具 举报

0

主题

1

帖子

1

积分

新手上路

Rank: 1

积分
1
发表于 2021-4-21 04:26:39 | 显示全部楼层
单击此处可将活动样式添加到a标记的父元素中,并从兄弟节点中删除活动样式。
  1. <li onclick="change(this)"><a>xxxx</a></li>
  2. 点击后
  3. <li class="active" onclick="change(this)"><a>xxxx</a></li>
  4. function change (el) {
  5.   el.className = 'active
  6.   // 清空同级的actvie样式
  7. }
  8. css
  9. li.active a {
  10. color: red;
  11. }
复制代码
回复

使用道具 举报

0

主题

1

帖子

1

积分

新手上路

Rank: 1

积分
1
发表于 2021-4-28 19:59:43 | 显示全部楼层
悬停失败可能是由于pseudo类的优先级造成的
回复

使用道具 举报

1

主题

2

帖子

4

积分

新手上路

Rank: 1

积分
4
发表于 2021-5-13 12:21:01 | 显示全部楼层
HTML + CSS可以做很多事情,包括很酷的旋转图形
其原理是Label标签控制一个单选按钮,然后使用Input:checked+。Box3属性选择器+兄弟选择器来控制样式
写一个简单的表栏开关,代码如下:
  1. <!DOCTYPE html>
  2. <html lang="en">

  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Document</title>
  7.     <style>
  8.         .box {
  9.             width: 400px;
  10.             height: 100px;
  11.             border: 1px solid blue;
  12.             margin: 100px auto 0;
  13.         }
  14.         
  15.         .box2 {
  16.             width: 400px;
  17.             height: 300px;
  18.             border: 1px solid blue;
  19.             margin: 0 auto;
  20.         }
  21.         
  22.         .box1 {
  23.             width: 20%;
  24.             float: left;
  25.             height: 100%;
  26.             box-sizing: border-box;
  27.             border: 1px solid pink;
  28.         }
  29.         
  30.         .box3 {
  31.             display: none;
  32.             width: 100%;
  33.             height: 100%;
  34.         }
  35.         
  36.         input {
  37.             display: none;
  38.         }
  39.         
  40.         input:checked+.box3 {
  41.             display: block;
  42.             background-color: aqua;
  43.         }
  44.     </style>
  45. </head>

  46. <body>
  47.     <div class="box">
  48.         <label for="q1"> <div class="box1">1</div></label>
  49.         <label for="q2"> <div class="box1">2</div></label>
  50.         <label for="q3"> <div class="box1">3</div></label>
  51.         <label for="q4"> <div class="box1">4</div></label>
  52.         <label for="q5"> <div class="box1">5</div></label>
  53.     </div>
  54.     <div class="box2">
  55.         <input type="radio" name="w" id="q1" checked="checked">
  56.         <div class="box3">1</div>
  57.         <input type="radio" name="w" id="q2">
  58.         <div class="box3">2</div>
  59.         <input type="radio" name="w" id="q3">
  60.         <div class="box3">3</div>
  61.         <input type="radio" name="w" id="q4">
  62.         <div class="box3">4</div>
  63.         <input type="radio" name="w" id="q5">
  64.         <div class="box3">5</div>
  65.     </div>
  66. </body>

  67. </html>
复制代码
回复

使用道具 举报

0

主题

2

帖子

3

积分

新手上路

Rank: 1

积分
3
发表于 2021-5-19 02:29:14 | 显示全部楼层 &
也许a的优先级有问题,我的是好的
  1. <!DOCTYPE html>
  2. <html lang="en">

  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Document</title>
  7.     <style>
  8.         .nav {
  9.             height: 41px;
  10.             border-top: 3px solid #ff8500;
  11.             border-bottom: 1px solid #edeef0;
  12.             background-color: #fcfcfc;
  13.             line-height: 41px;
  14.         }

  15.         .nav a {
  16.             display: inline-block;
  17.             /* 垂直对齐方式 */
  18.             vertical-align: top;
  19.             height: 41px;
  20.             padding: 0 20px;
  21.             font-size: 12px;
  22.             color: #4c4c4c;
  23.             text-decoration: none;
  24.         }

  25.         .nav a:hover {
  26.             color: orangered;
  27.             background-color: slategrey;

  28.         }
  29.     </style>
  30. </head>

  31. <body>
  32.     <div class="nav">
  33.         <a href="#">设为首页</a>
  34.         <a href="#">手机新浪网</a>
  35.         <a href="#">移动客户端</a>
  36.         <a href="#">博客</a>
  37.         <a href="#">微博</a>
  38.         <a href="#">关注我</a>
  39.     </div>
  40. </body>

  41. </html>
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|小白教程 ( 粤ICP备20019910号 )

GMT+8, 2024-9-20 15:07 , Processed in 0.029947 second(s), 27 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc. Template By 【未来科技】【 www.wekei.cn 】

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