今天在#論壇有網(wǎng)友問起"同一頁面如何制作多種鏈接樣式",于是自己就隨手寫了一個:CSS制作多種鏈接樣式代碼,結(jié)果卻寫錯鳥,其實 多種鏈接樣式制作方法 挺簡單的,看看下面這個多種鏈接樣式制作方法的實例,你就明白了如何用CSS制作多種鏈接樣式了
<html>
<head>
<title>CSS制作多種鏈接樣式實例</title>
<style type="text/css">
<!--
a:link { color: #CC3399; text-decoration: none}
a:visited { color: #FF3399; text-decoration: none}
a:hover { color: #800080; text-decoration: underline}
a:active { color: #800080; text-decoration: underline}
a.red:link { color: #FF0000; text-decoration: none}
a.red:visited { color: #FF0000; text-decoration: none}
a.red:hover { color: #606060; text-decoration: underline}
a.red:active { color: #606060; text-decoration: underline}
a.ameth:link { color: #400040; text-decoration: none}
a.ameth:visited { color: #400040; text-decoration: none}
a.ameth:hover { color: #FF3399; text-decoration: underline}
a.ameth:active { color: #FF3399; text-decoration: underline}
div.other a:link { color: #004000; text-decoration: none}
div.other a:visited { color: #004000; text-decoration: none}
div.other a:hover { color: #008000; text-decoration: underline}
div.other a:active { color: #008000; text-decoration: underline}
-->
</style>
<!-- 鏈接樣式表 -->
</head>
<body>
第一種樣式(默認的) <a >個人日志</a> <br>
第二種樣式 <a class="red" >個人日志</a><br>
另外一種實現(xiàn)鏈接樣式的方法 <a class="ameth" >個人日志</a><br>
<div class="other">DIV容器實現(xiàn)鏈接樣式的方法 <a class="other" >個人日志</a></div><br>
</body>
</html>
當然,你完全可以將CSS代碼寫入一個CSS文件,這樣做的好處,不僅是你的網(wǎng)頁HTML代碼簡潔了,而且你會發(fā)現(xiàn)速度也跟著提升了,因為瀏覽器會緩存你的CSS文件,更重要的是你要改變樣式時只需要改變CSS樣式表文件就可以了
這樣寫
css樣式文件 default.css
a:link { color: #CC3399; text-decoration: none}
a:visited { color: #FF3399; text-decoration: none}
a:hover { color: #800080; text-decoration: underline}
a:active { color: #800080; text-decoration: underline}
a.red:link { color: #FF0000; text-decoration: none}
a.red:visited { color: #FF0000; text-decoration: none}
a.red:hover { color: #606060; text-decoration: underline}
a.red:active { color: #606060; text-decoration: underline}
a.ameth:link { color: #400040; text-decoration: none}
a.ameth:visited { color: #400040; text-decoration: none}
a.ameth:hover { color: #FF3399; text-decoration: underline}
a.ameth:active { color: #FF3399; text-decoration: underline}
div.other a:link { color: #004000; text-decoration: none}
div.other a:visited { color: #004000; text-decoration: none}
div.other a:hover { color: #008000; text-decoration: underline}
div.other a:active { color: #008000; text-decoration: underline}
現(xiàn)在,你只需要將CSS包含進你的HTML文件就可以了
index.htm
<html>
<head>
<title>CSS制作多種鏈接樣式實例</title>
<link rel="stylesheet" type="text/css" href="default.css">
<!-- 鏈接樣式表 -->
</head>
<body>
第一種樣式(默認的) <a >個人日志</a> <br>
第二種樣式 <a class="red" >個人日志</a><br>
另外一種實現(xiàn)鏈接樣式的方法 <a class="ameth" >個人日志</a><br>
<div class="other">DIV容器實現(xiàn)鏈接樣式的方法 <a class="other" >個人日志</a></div><br>
</body>
</html>
本站原創(chuàng),歡迎轉(zhuǎn)載,請注明出處: http://www.dayanmei.com/blog.php/ID_274.htm