返回首页当前位置:首页 >> 网站建设 >> 正文

web标准常见问题大集合[4]

文章来自:设计学院 | 发表时间:2007-10-10 22:57:31

10.web标准中定义id与class有什么区别吗

运行代码


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<style type="text/css">

<!--

#aa {

color:red

}

.aa {

color:blue

}

-->

</style>

<div id="aa" class="aa">

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

</div>


一.web标准中是不容许重复ID的,比如 div id="aa" 不容许重复2次,而class 定义的是类,理论上可以无限重复, 这样需要多次引用的定义便可以使用他.

二.属性的优先级问题

ID 的优先级要高于class,看上面的例子

三.方便JS等客户端脚本,如果在页面中要对某个对象进行脚本操作,那么可以给他定义一个ID,否则只能利用遍历页面元素加上指定特定属性来找到它,这是相对浪费时间资源,远远不如一个ID来得简单.

11.如何垂直居中文本

运行代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<style type="text/css">

<!--

div {

height:30px;

line-height:30px;

border:1px solid red

}

-->

</style>

<div>web标准常见问题大全</div>


给容器设置一个与其高度相同的行高就可以了

12.如何对齐文本与文本输入筐

运行代码


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<style type="text/css">

<!--

input {

width:200px;

height:30px;

border:1px solid red;

}

-->

</style>

<input type="text" />aaaaaaaaaaaaaaaaaa

遇到此种问题,设置文本框的

vertical-align:middle
就可以了