百虎谷互联网技术博客

关键词博客:搜索引擎探究、搜索技巧、网络技术、网站制作等!

« 初步学习级联式样式表CSS、CSS的优点外部CSS样式表在网页制作中的作用 »

将HTML元素分配给CSS样式CLASS

两种方法,分别如下:
 

 ⑴ 标记。

类名{标志属性:属性值;……标志属性:属性值}

引用方法是:<标记 CLASS=“类名”>

例如,我们打算让某一些段落缩进0.5in,另一些段落缩进 1.0in,我们知道段落采用< P>这个标记。

⑵ 可以直接定义CLASS,应用于HTML页面中的各个标记。

类名{标志属性:属性值;……标志属性:属性值}

引用方法是: <标记 CLASS="类名">

代码书写如下:
< html>
< head>
< title>This is a sample< /title>
< style type="text/css">
< !-- p.first { text-indent: 0.5in} p.second { text-indent: 1.0in} -->
< /style>

< /head>
< body bgcolor="#FFFFFF">
 < p class="first">这个段落将缩进0.5in< /p> < p class="second">这个段落将比上面缩进一倍距离< /p>
< /body>
< /html>

<html>
<head>
<title>无标题文档</title>
<style type="text/css">
.head2 {text-align:center;font-size: 24px;font-style: italic;font-weight: bold;color: red;}
body{font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 15px;background-color: #FbFbFb; }
a:link {color: #0000FF ;text-decoration: none;}
a:visited {color: #00FF00;text-decoration: none;}
a:active {color: #FF0000;text-decoration: none;}
a:hover {text-decoration: underline;}
</style>

</head>
<body >
<span class="head2">This text is centered and red!</span>
<br>This text is centered and black!
<p style="color:#00FF00;font-style:normal;text-decoration:underline; ">This text is centered
and green!</p>

<a href="http://www.qdu.edu.cn" target="_blank">青岛大学</a><p>
<a href="http://www.qd.sd.cn" target="_blank">青岛信息港</a>
</body>
</html>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最近发表

最新评论及回复

百虎谷(鲁ICP备08103840号)

友情提示:请输入关键词