style、 currentStyle、 runtimeStyle介绍

1、用到的基本概念:

内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有效。

eg:<P style="font-size:20pt; color:red">这个Style定义<p></p>里面的文字是20pt字体,字体颜色是红色。</p>

内部样式(internal Style Sheet):是写在HTML的<head></head>里面的,内部样式只对所在的网页有效。

<HTML>
<HEAD>
<STYLE type="text/css">
H1.mylayout {border-width:1; border:solid; text-align:center; color:red}
</STYLE>
</HEAD>
<BODY>
<H1 class="mylayout"> 这个标题使用了Style。</H1>
<H1>这个标题没有使用Style。</H1>
</BODY>
</HTML>

外部样式表(External Style Sheet):如果很多网页需要用到同样的样式(Styles),将样式(Styles)写在一个以.css为后缀的CSS文件里,然后在每个需要用到这些样式(Styles)的网页里引用这个CSS文件。

<HEAD>
<link href="../asdocs/css_tutorials/home.css" rel="stylesheet" type="text/css">
</HEAD>

CSS第一个字母,是Cascading,意为串联。它是指不同来源的样式(Styles)可以合在一起,形成一种样式。


样式(Styles)的优先级依次是内嵌(inline), 内部(internal), 外部(external), 浏览器缺省(browser default)。

假设内嵌(Inline)样式中有font-size:30pt, 而内部(Internal)样式中有font-size:12pt,那么内嵌(Inline)式样式就会覆 盖内部(Internal)样式。

2、currentStyle 代表了在全局样式表、内嵌样式和

this);" target="_blank">HTML 标签属性中指定的对象格式和样式。

Style为内嵌样式。

style 标准的样式!可能是由style属性指定的!
runtimeStyle 运行时的样式!如果与style的属性重叠,将覆盖style的属性!
currentStyle 指 style 和 runtimeStyle 的结合!


当指定了runtimeStyle,那么当前显示的样式以runtimeStyle为准,如果取消了runtimeStyle,那么当前显示样式就恢复到currentStyle的样式。


<script>
function yangshi(){
//alert(document.getElementsByName("a")[0].value);
//alert(document.getElementsByName("b")[0].currentStyle);

alert("The td object currentStyle.width is " + oTd.currentStyle.width +
"\nThe td object style.width is " + oTd.style.width +
"\nThe td object style.textAlign is " + oTd.style.textAlign +
"\nThe td object currentStyle.textAlign is " +oTd.currentStyle.textAlign +
"\nThe td object style.font is " + oTd.style.fontSize +
"\nThe td object currentStyle.font is " + oTd.currentStyle.fontSize);
}

function runStyle(){

p1.style.backgroundColor = "red";
p1.runtimeStyle.color = "blue";
p1.runtimeStyle.backgroundColor = "green";

alert("000style=="+p1.style.backgroundColor);
alert("aaastyle=="+p1.style.color); //没有数据

alert("111runtime=="+p1.runtimeStyle.backgroundColor); //没有数据
alert("222runtime=="+p1.runtimeStyle.color);

alert("333currentStyle=="+p1.currentStyle.backgroundColor); //显示green,说明runtime优先级高
alert("444currentStyle=="+p1.currentStyle.color);
}
</script>
</head>
<body>
<input type="button" name="qq" value="Style" οnclick="yangshi()">
<table border="1">
<tr>
<td width="1100" style="font-size:100px;text-align:right" id="oTd">text</td>
</tr>
</table>

<p id="p1">pppp</p><input type="button" name="ww" value="runtime" οnclick="runStyle()" >

</body>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值