underline lt;agt; tag when hovering(下划线lt;agt;悬停时标记)
问题描述
我希望我的 <a>
标签在悬停时带有下划线.我有以下代码,但它不起作用.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 过渡//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="服务器"><标题></标题><style type="text/css">a.hover:hover {文本装饰:下划线;}</风格></头><身体><form id="form1" runat="server"><a class="hover" style=" text-decoration:none; color:red" href="">站点地图</a></div></表格></身体></html>这个:
a:hover {text-decoration: underline;}<a style=" text-decoration:none; color:red" href="">站点地图</a>
也不行.
我该怎么办?有什么问题?
解决方案style
属性更多比任何选择器都特定,所以它总是在级联中最后应用(可怕的 !important
规则无法承受).将 CSS 移至样式表.
a.hover {红色;文字装饰:无;}a.hover:悬停{文字装饰:下划线;}
(我还建议为该类命名更具语义化的名称).
I want my <a>
tag gets underlined when hovered. I have the following code, but it doesn't work.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
a.hover:hover {text-decoration: underline;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<a class="hover" style=" text-decoration:none; color:red" href="">Site Map</a>
</div>
</form>
</body>
</html>
This:
a:hover {text-decoration: underline;}
<a style=" text-decoration:none; color:red" href="">Site Map</a>
doesn't work either.
What should I do? What is the problem?
解决方案 The style
attribute is more specific than any selector, so it will always be applied last in the cascade (horrible !important
rules not withstanding). Move the CSS to the stylesheet.
a.hover {
color: red;
text-decoration: none;
}
a.hover:hover {
text-decoration: underline;
}
(I also suggest a more semantic name for the class).
这篇关于下划线<a>悬停时标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:下划线<a>悬停时标记


基础教程推荐
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01