我用下面的伪类:我是否需要指定每个链接的颜色状态?
a.recentposttitle:link,a.recentposttitle:visited {color:#000;}
a.recentposttitle:hover {color:#56A49F;}
a.recentposttitle:active {color:#000;}
我需要是明确的或者是有一个更压缩的方式来获得同样的结果?
我用下面的伪类:我是否需要指定每个链接的颜色状态?
a.recentposttitle:link,a.recentposttitle:visited {color:#000;}
a.recentposttitle:hover {color:#56A49F;}
a.recentposttitle:active {color:#000;}
我需要是明确的或者是有一个更压缩的方式来获得同样的结果?
CSS中没有用于锚点/链接伪类的简写选择器。所以你所拥有的就像你所能得到的那样简洁。
a:link{ Declarations }
a:visited{ Declarations }
...
a:hover{ Declarations }
a:active{ Declarations }
我需要找到我以前读证实了这一点参考,但据我所知,在:link
伪选择是只需要如果您使用的旧式页面锚(<a name="..."></a>
) ,所以你应该能够安全地消除这种情况。由于您的:active
和:visited
规则是一样的,你很可能降低您已经证明这是什么:
a.recentposttitle:active, a.recentposttitle:visited {color:#000;}
a.recentposttitle:hover {color:#56A49F;}
但你没有真正节省很多字节,所以很难说,如果这是值得的。
'伪'类的顺序很重要,所以':active'必须在':hover'之后。因此,点击链接时链接不会变黑。选中此[FIDDLE](http://jsfiddle.net/mojtaba/X5kTE/)。 – 2013-05-21 06:14:38
@NOX奇怪 - 您链接的jsFiddle适用于我(单击链接会导致在不悬停时颜色为黑色)。我可能需要创建一个工作演示,以查看真实链接的工作原理。感谢您的输入! –
点击并按住鼠标。该链接当时必须是黑色的;) – 2013-05-21 06:21:14
不,没有简写。但是,你的选择可能是:
a {}
选择所有links
,或:
.recentposttitle {}
让所有.recentposttitle
元素(我们知道他们是链接的话)。
而另一件事,:link
不需要真的,你可以这样写:
a {}
a:visited {}
a:hover {}
a:active {}
当你写a {}
,您将设置申报所有可能的情况,所以:
a {}
完全相同:
a:link, a:visited, a:hover, a:active {}
pseudo classes
顺序是importent:
'a'和'a:link'不完全相同。 'a:link'选择实际上是链接''的所有锚元素,而'a'也选择没有href属性的锚元素。 – knittl
感谢您的有用评论':)'。 – 2013-05-21 06:24:07
我不完全遵循你的例子。您已删除课程.recentposttitle。所以你的代码有一个更大的目标......对吧? – 4thSpace
您可以使用CSS框架来压缩它,如LESS
或SASS
。
从你的例子一样,
的CSS:
a.recentposttitle:link,a.recentposttitle:visited {color:#000;}
a.recentposttitle:hover {color:#56A49F;}
a.recentposttitle:active {color:#000;}
例如,如果您使用SASS可以压缩到..
a.recentposttitle {
color: #000;
&:link{ color: #000; }
&:hover { color: #56A49F; }
&:visited { color: #000; }
&:active{ color: #000; }
}
你也可以使用Emmet
,以前称为Zen coding
用于最大代码压缩秒。
希望这会有所帮助。
为获得稳定的结果,您必须这样做 – edd
显式使用将会很好。所以你可以定位特定的区域@ 4thspace –