トップ  »  CSS  »  外部リンクだけにアイコンをつける

2009年1月 5日

外部リンクだけにアイコンをつける

ヨモツネットのアッキーに、力をかりて、
外部リンクだけにアイコンをつけるdemo
注意するべきところは、<a href="***"><img src="*" alt="*" /></a>のように画像にリンクがある場合にもアイコンがつくので#main aのように絞り込んで具体的にCSSを設定するなど、工夫が必要


a[href$=".pdf"]{background:url(common/images/ico_conductor_pdf.gif) no-repeat 100% 50%;}
* html a.pdf{ background:url(common/images/ico_conductor_pdf.gif) no-repeat 100% 50%;}

a[href$=".doc"]{background:url(common/images/ico_conductor_doc.gif) no-repeat 100% 50%;}
* html a.doc{ background:url(common/images/ico_conductor_doc.gif) no-repeat 100% 50%;}

a[href$=".xls"]{background:url(common/images/ico_conductor_xls.gif) no-repeat 100% 50%;}
* html a.xls{ background:url(common/images/ico_conductor_xls.gif) no-repeat 100% 50%;}

a[href^="http"]{background:url(common/images/ico_conductor_external.gif) no-repeat 100% 50%;}
* html a.external{background:url(common/images/ico_conductor_external.gif) no-repeat 100% 50%;}

a[href^="http://magic-happens.net"],
a[href^="http://www.magic-happens.net"]{
padding:inherit;
background:transparent;
}
* html a{ /* IE-expression (attr-selector) */
behavior: expression(
this.className += this.getAttribute("href").match(/^http.*/) && (!this.getAttribute("href").match("magic-happens.net")) ? " external" : "",
this.className += this.getAttribute("href").match(/\.pdf$/) ? " pdf" : '',
this.className += this.getAttribute("href").match(/\.doc$/) ? " doc" : '',
this.className += this.getAttribute("href").match(/\.xls$/) ? " xls" : '',
this.style.behavior = "none"
);
}

トラックバック(1)

このブログ記事を参照しているブログ一覧: 外部リンクだけにアイコンをつける

このブログ記事に対するトラックバックURL: http://magic-happens.net/mt/mt-tb.cgi/57

PDF、Excel、Word、ZIPや外部リンクなどにアイコンが付けるが付いてるサイトって見かけると思うですがこれを自動でつくようにCSSで指定する事が... 続きを読む

コメントする

Top of Pageページの先頭へ

© Magic Happens