更改/去除 a链接默认样式

本文介绍了一种常见需求的解决方案:如何通过CSS代码让网页中的a链接在被点击时保持原有颜色,避免颜色变化,适用于希望保持页面一致性的前端开发者。

比较常见的一个需求,但是点击a链接的时候又不想让它变色,下面的代码就可以解决

a{ 
    text-decoration:none !important;
    color:#C00017 !important; 
}
<!DOCTYPE html> <html lang=“en”> <head> <meta charset=“UTF-8”> <meta name=“viewport” content=“width=device-width, initial-scale=1.0”> <title>豆瓣列表页</title> <!-- 引入 Bootstrap 样式 --> <link href=“https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css” rel=“stylesheet”> <style> /* 全局样式 / body { margin: 0; / 移除默认外边距 / background-image: url(“/static/6.jpg”); / 设置背景图片 / background-size: cover; / 背景图片自适应屏幕 */ } /* 标题样式 */ h1 { color: rgb(35, 140, 205); /* 设置标题颜色 */ text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5); /* 添加文字阴影效果 */ } /* 导航链接样式 */ a { color: white; /* 链接文字颜色 */ background-color: rgb(35, 140, 205); /* 链接背景颜色 */ text-decoration: none; /* 去除下划线 */ border-radius: 8px; /* 圆角效果 */ padding: 3px 10px; /* 内边距 */ margin: 0 5px; /* 外边距 */ } /* 鼠标悬停时的链接样式 */ a:hover { background-color: rgb(20, 90, 150); /* 悬停时背景颜色加深 */ } /* 表格样式 */ table { width: 90%; /* 表格宽度 */ margin: 20px auto 0; /* 表格外边距,顶部20px,水平居中 */ border-collapse: collapse; /* 合并表格边框 */ } /* 表格单元格样式 */ th, td { border: 2px solid black; /* 单元格边框 */ text-align: center; /* 文本居中 */ padding: 8px; /* 内边距 */ } /* 表头样式 */ th { background-color: rgb(35, 140, 205); /* 表头背景颜色 */ color: white; /* 表头文字颜色 */ font-size: 18px; /* 字体大小 */ } /* 表格数据行样式 */ td { font-size: 16px; /* 字体大小 */ } /* 搜索框样式 */ form { margin-bottom: 20px; /* 搜索框底部外边距 */ } /* 自定义 input-group 的宽度和高度 */ .custom-input-group { margin: 0 auto; /* 移除默认外边距 */ width: 400px; /* 设置宽度 */ height: 50px; /* 设置高度 */ } /* 确保内部的输入框和按钮也适应新的高度 */ .custom-input-group .form-control, .custom-input-group .btn { height: 100%; /* 内部元素的高度与父容器一致 */ } input[type="text"] { padding: 8px; /* 内边距 */ border-radius: 4px; /* 圆角效果 */ border: 1px solid #ccc; /* 边框样式 */ width: 50%; /* 输入框宽度 */ } /* 提交按钮样式 */ input[type="submit"] { padding: 8px 25px; /* 内边距 */ background-color: rgb(35, 140, 205); /* 按钮背景颜色 */ color: white; /* 按钮文字颜色 */ border: none; /* 去除边框 */ border-radius: 4px; /* 圆角效果 */ cursor: pointer; /* 鼠标悬停时显示手型 */ } /* 提交按钮悬停样式 */ input[type="submit"]:hover { background-color: rgb(20, 90, 150); /* 悬停时背景颜色加深 */ } </style> </head> <body> <!-- 页面主体内容 --> <div class=“container text-center py-5”> <!-- 标题 --> <h1 class=“display-4”>欢迎使用豆瓣网</h1> <!-- 导航链接 --> <p> <a href="/">首页</a> <a href="/list">电影类型列表</a> <a href="/add">添加电影类型</a> <a href="/addMovie">添加电影</a> <a href="/zhu" target="_blank">查看柱状图</a> <a href="/bing" target="_blank">查看饼状图</a> <a href="/zhe" target="_blank">查看折线图</a> </p> <!-- 搜索表单 --> <form action="/sousuoSubmit" method="post"> <div class="input-group custom-input-group"> <input type="text" class="form-control" placeholder="请输入电影名称" name="a" required> <button type="submit" class="btn btn-primary">搜索</button> </div> </form> </div> <!-- 数据表格 --> <table> <!-- 表头 --> <tr> <th>编号</th> <th>名称</th> <th>内容</th> <th>创建日期</th> <th>操作</th> </tr> <!-- 动态生成的数据行 --> {% for i in info %} <tr> <td>{{i[0]}}</td> <td>{{i[1]}}</td> <td>{{i[2]}}</td> <td>{{i[3]}}</td> <td> <a href="/update/{{i[0]}}">修改</a> <a href="/delete/{{i[0]}}">删除</a> <a href="/movielist/{{i[0]}}">查看</a> </td> </tr> {% endfor %} </table> </body> </html>使得搜索框下的内容上下仅靠
最新发布
05-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值