网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 在firefox或ie中span无法确定宽度的解决方案
内容
    代码如下:
    <html xmlns=http ://www.w3.org/1999/xhtml >
    <head>
    <title>test span</title>
    <mce:style type=text/css><!--
    span {
    background-color:#ffcc00;
    width:150px ;
    }
    --></mce:style><style type=text/css mce_bogus=1>span {
    background-color:#ffcc00;
    width:150px ;
    }</style>
    </head >
    <body>
    fixed <span >width</span> span
    </body>
    </html>
    通过试验以后发现,无效,无论是在firefox还 是ie中都无效 。
    通过查阅 css2标准中关于width 的定义发现,原来css中的 width 属性并不总是有效的,如果对象是 inline 对象,width 属性就会被忽略。firefox 和 ie 原来是遵循了标准才这样做的。
    修改 span 为 block 类型并设置 float 不是完美解决
    在span的css中增加display属性,将span设置为block类型的element,这样宽度的确有效了,不过也把前后文字隔在不同行里面。这样其实span就完全变成了div。
    代码如下:
    span { background-color:#ffcc00; display:block; width:150px;}
    很多人会建议再增加一个css 属性 float ,这样的确在某种条件下能解决问题。比如我们的例子中,如果span前面没有文字,那的确是可行的。但是如果有了,前后文字就会连在一起,而span跑到了第二行。
    代码如下:
    span { background-color:#ffcc00;
    display:block; float:left; width:150px;}
    设置 span 宽度的完美解决方案
    下面代码的 css定义完美解决了span的宽度设置问题。由于浏览器通常对不支持的css属性采取忽略处理的态度,所以最好将display:inline -block行写在后面,这样在firefox里面,如果到了未来的firefox 3,这一行就能起作用,代码可以同时兼容各种版本。
    代码如下:
    <!doctype html public -//w3c//dtd xhtml 1.0 transitional//en >
    <html xmlns= >
    <head><title>test span</title>
    <mce:style type=text/css><!--
    span { background-color:#ffcc00; display:-moz-inline-box; display:inline-block; width:150px;}
    --></mce:style>
    <style type=text/css mce_bogus=1>span { background-color:#ffcc00; display:-moz-inline-box; display:inline-block; width:150px;}</style>
    </head>
    <body>
    fixed <span>width</span> span
    </body>
    </html>
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/16 0:44:40