下划线<a>悬停时标记 [英] underline <a> tag when hovering

查看:14
本文介绍了下划线<a>悬停时标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的 <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).

这篇关于下划线&lt;a&gt;悬停时标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆