使用 CSS(样式表)的 class

class 是类,用来定义 style 属性。
在使用 CSS(样式表)时用 class 可以更方便。
举例:
文件1:C1.CSS
.Bar
{
border-right: 2px outset;
border-top: 2px outset;
overflow: auto;
border-left: 2px outset;
border-bottom: 2px outset;
}
.BCap
{
color: graytext;
}

.BDroper
{
border-right: 2px outset;
border-top: 2px outset;
border-left: 2px outset;
width: 1px;
cursor: move;
border-bottom: 2px outset;
position: static;
height: 100%;
}

这个文件定义了三个类(class):
Bar 工具栏的样式
BCap 工具栏标题的样式
BDroper 工具栏拖动按钮的样式

文件2:Main.HTM (HTML)
<HTML>
<HEAD>
<LINK href="C1.CSS" type=text/css rel=stylesheet> <!--样式表的路径-->
</HEAD>
<BODY>
<DIV class="Bar">
<a class="BDroper"></a>
<a class="BDroper"></a>
  
<a class="BCap">浏览</a>
<a href="javascript:history.back(1)">返回</a>
<a href="javascript:history.forward(1)">前进</a>
</DIV>
<BODY>
</HTML>

如果不是用样式表,文件2的内容如下:
<HTML>
<HEAD>
<!--没有样式表-->
</HEAD>
<BODY>
<DIV style="border-right: 2px outset; border-top: 2px outset; overflow: auto; border-left: 2px outset; border-bottom: 2px outset;">
<a style="border-right: 2px outset; border-top: 2px outset; border-left: 2px outset; width: 1px; cursor: move; border-bottom: 2px outset; position: static; height: 100%;"></a>
<a style="border-right: 2px outset; border-top: 2px outset; border-left: 2px outset; width: 1px; cursor: move; border-bottom: 2px outset; position: static; height: 100%;"></a>
  
<a style="color: graytext;">浏览</a>
<a href="javascript:history.back(1)">返回</a>
<a href="javascript:history.forward(1)">前进</a>
</DIV>
<BODY>
</HTML>

可见,如果使用样式表以及 class 属性,则对于样式的定义就能简单的多。
<a href="index.jsp" class="atop">
这定义了一个超链接,它的类为 atop。如果你能找到这个网页的样式表,你会找到这个类的定义。也许是这样的:
.atop
{
.....
}

当然,一个网页也可以使用多个样式表:
...
<HEAD>
<LINK href="C1.CSS" type=text/css rel=stylesheet> <!--样式表1的路径-->
<LINK href="../C2.CSS" type=text/css rel=stylesheet> <!--样式表2的路径-->
<LINK href="DD1/S1/Main.CSS" type=text/css rel=stylesheet> <!--样式表3的路径-->
</HEAD>
... 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值