+ -
当前位置:首页 → 问答吧 → text-decoration去除下划线的问题

text-decoration去除下划线的问题

时间:2011-07-17

来源:互联网

按CSS优先级规则,第二行应该不会有下划线才是。
请问在不改变.sub的情况下应该如何定义.none才能去除下划线呢?

HTML code
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
.sub{
    text-decoration:underline;
}
.sub .none{
    text-decoration:none;
}
</style>
</head>
<body>
<div class="sub">
  这里有下划线
    <div class="none">正常下这里应该没有下划线</div>
</div>
</body>
</html>

作者: rainzero   发布时间: 2011-07-17

HTML code
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.sub{
    text-decoration:underline;
}
.none {
    text-decoration:none;
    color:red;
}
</style>
</head>
<body>
<div>
    <div class="sub">
      这里有下划线
    </div>
    <div class="none">正常下这里应该没有下划线</div>
</div>
</body>
</html>

作者: T5500   发布时间: 2011-07-17

我知道这样可以,但是就是想知道.none如何才能不承继.sub的样式。

作者: rainzero   发布时间: 2011-07-17

<style>
.sub{
text-decoration: none;
}
.sub .none{
text-decoration:underline;
}
</style>
可以。反之不行。因为text-decoration: underline这个的使用是有默认的“逻辑”规则的,就象下面的作战报告:

四连 {有伤亡}
四连一班 {全部牺牲}
这是可以的。

四连 {全部牺牲}
四连一班 {有伤亡}
这就不可以。

为什么这么比喻呢。因为下划线对象在逻辑上本身代表一个整体的小集体,是不可中断的(那些WORD文档中看起来视觉上中断的下划线内容,是拆分成了两个或多个下划线内容而已,操作的视觉性和实际的逻辑并不一样,作为程序员要懂得内部原理,而不是象一般外行用户那样被表面所蒙蔽)。

作者: theforever   发布时间: 2011-07-17

那些WORD文档中看起来视觉上中断的下划线内容,是拆分成了两个或多个下划线内容而已,操作的视觉性和实际的逻辑并不一样…………这个,去看一下WORD内部的编码就知道了,或者把那样的文档转存成HTML页面,看看里面相应部分的HTML代码就知道了。

作者: theforever   发布时间: 2011-07-17