站内搜索
分类列表
本类阅读排行
本类推荐文章
网页设计小技巧:用CSS制超级链接样式
作者: 来源:互连网 点击: 日期:2008-7-21 9:44:18
.external
{
background:url(images/external.gif) no-repeat right top;
padding-right:12px;
}
{
background:url(images/external.gif) no-repeat right top;
padding-right:12px;
}
然后给每一个外部的链接应用该CSS,当然,这样做并不是不可以,只是太繁琐。
那有没有好的办法来实现呢?有。可以利用CSS3中的属性选择,但是在IE6及以下版本不支持该方法,在FireFox中已经实现了。
属性选择器的基本语法为:[att^=val]
例如:
a[href^="http://www.webjx.com"]
{
background-image:none;
padding-right:0px;
}
{
background-image:none;
padding-right:0px;
}
会查找所有以http://www.webjx.com开头的链接,并且排除背景图片。有了上面的属性,就好办了。
<style type="text/css">
a
{
background:url(external.gif) no-repeat right top;
padding-right:14px;
font-size:12px;
}
a[href^="http://www.webjx.com"]
{
background-image:none;
padding-right:0px;
}
</style>
先给所有链接加上图标,然后去掉以http://www.webjx.com开头的链接图标,这样就实现了外部链接显示图标,内部链接不显示图标了。a
{
background:url(external.gif) no-repeat right top;
padding-right:14px;
font-size:12px;
}
a[href^="http://www.webjx.com"]
{
background-image:none;
padding-right:0px;
}
</style>
注:firefox中适用,IE就不行了。
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
a
{
background:url(/img/external.gif) no-repeat right top;
padding-right:14px;
font-size:12px;
}
a[href^="http://www.webjx.com"]
{
background-image:none;
padding-right:0px;
}
</style>
</head>
<body>
<a href="http://www.webjx.com">webjx.com</a><br />
<a href="http://www.163.com/">163.com</a><br />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
a
{
background:url(/img/external.gif) no-repeat right top;
padding-right:14px;
font-size:12px;
}
a[href^="http://www.webjx.com"]
{
background-image:none;
padding-right:0px;
}
</style>
</head>
<body>
<a href="http://www.webjx.com">webjx.com</a><br />
<a href="http://www.163.com/">163.com</a><br />
</body>
</html>
网页设计小技巧:用CSS制超级链接样式 评论
