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" onclick="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" onclick="runStyle()" >
</body>
分享到:
相关推荐
style、 currentStyle、 runtimeStyle区别分析,需要的朋友可以参考下。
JavaScript style对象与CurrentStyle对象案例详解 1、Style对象 style对象代表一个单独的样式声明,可以从应用样式的文档元素访问Style对象。style对象获取的是内联样式,即元素标签中style属性的值。 例子: ...
主要介绍了前端学习笔记style,currentStyle,getComputedStyle的用法与区别,需要的朋友可以参考下
样式表有三种方式 内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有效。 内部样式(internal Style Sheet):是写在HTML的<head></head>里面的,内部样式只对所在的网页有效。 ...
大家都知道,用document.getElementById(‘element’).style.xxx可以获取元素的样式信息,可是它获取的只是DOM元素style属性里的样式规则,对于通过class属性引用的外部样式表,就拿不到我们要的信息了。 DOM标准里...
(currentStyle)javascript为何有时用style得不到已设定的CSS的属性
CSS的样式分为三类: 内嵌样式:是写在Tag里面的,内嵌样式只对所有的Tag有效。 ... 外部样式表:如果很多网页需要用到同样的样式(Styles),将样式(Styles...currentStyle是IE浏览器的一个属性,返回的是CSS样式对象 el
我们知道获取元素的实际宽高在IE中可以使用currentStyle属性。但如果没有显示的去设置元素的宽高,那么使用该属性将获取不到,获取的值为auto。如下 代码如下: <div>abcd</div> ...如下 1,通过内联style属性设置 代
可是DOM.style这种写法只能访问...其中 IE中这个对象叫做currentStyle,FF中这个对象叫做document.defaultView。我将这两个类打包了一下,做了一个用于访问 样式信息的函数,如下: 代码如下: //=====================
<style type="text/css" title="currentStyle" media="screen"> /* Paginator */ .paginator { font: 14.8px normal Arial, Helvetica, sans-serif; color: #666666; margin-top: 10px; margin-bottom: 5px; ...
1.事件冒泡: //取消冒泡 if(e.stopPropagation){ e.stopPropagation();//w3c定义的APIbiaozhun }else{ e.cancelBubble=true;... return element.currentStyle[stylename]; }else{ //其他浏览器
useDynamicStyle => [currentStyle,isDarkMode] useStyleBuilder => { /** * Convert tachyons syntax string to react native style * @param styleString String of multi prefix tachyons syntax * @...
//获取元素的真实的,最终的CSS样式属性值的函数 function getStyle(elem,name){ if(elem.style[name]){ return elem.style[name]; }else if(elem.currentStyle){ return elem.currentStyle[name]; }else if...
function getStyle(elem,name){ if(elem.style[name]){ return elem.style[name]; }else if(elem.currentStyle){ return elem.currentStyle[name]; }else if(document.defaultView&&document.defaultView....