当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > CSS教程:legend标签设定宽度

CSS样式表
shtml精简教程让你知道什么是shtml
很不错的 CSS Hack 又学了一招
Default style sheet for HTML 4
资料:Unicode 汉字内码对应表
解决CSS中 display 与 visibility 的区别
制作WEB在线编辑器-插入HTML标签
编写纯 CSS 弹出菜单的原理及实现 By shawl.qiu
关于《精通css》之几个不错的注意事项
position:relative/absolute无法冲破的等级
CSS样式表常用小技巧收藏
收集的web页面html中常用的特殊符号大全
bc1998录制的css视频教程推荐新手看下
dl+ol应用分析
li的简单应用
web打印的另类方法
用CSS实现的一张图完成的按钮效果
文章内容页广告浮于左上角的解决办法
广告放在文章页左上角的解决办法二
iframe的使用用法
FIF互动帮助手册系列-HTML手册 flash版

CSS样式表 中的 CSS教程:legend标签设定宽度


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 179 ::
收藏到网摘: n/a


原文:http://www.planabc.net/2008/07/24/legend_width/
我们在做表单的时候经常会使用到这样的结构:
<fieldset>
<legend>哪些浏览器legend标签设定的宽度有效</legend>
<input type="checkbox" value="ie6" name="width" id="ie6" checked="checked" /><label for="ie6">IE6</label>
<input type="checkbox" value="ie7" name="width" id="ie7"checked="checked" /><label for="firefox">IE7</label>
<input type="checkbox" value="firefox2" name="width" id="firefox2" /><label for="firefox2">Firefox2</label>
<input type="checkbox" value="firefox3" name="width" id="firefox3" /><label for="firefox3">Firefox3</label>
<input type="checkbox" value="opera" name="width" id="opera" checked="checked" /><label for="opera">Opera9.0 </label>
<input type="checkbox" value="safari" name="width" id="safari"checked="checked" /><label for="safari">Safari3.0 </label>

</fieldset> 当我们使用 CSS 给 legend 标签设定固定宽度时:
legend {
background:red;
width:500px;
}

在 IE6、IE7、Opera9.0 、Safari3.0  都正能常显示,而在 Firefox2 和 Firefox3 中宽度却失效。
在这里我们不去深究为什么,只探讨解决的方法:
我们可以通过在 legend 标签内添加一个标签,并给标签设定所需要的宽度,此宽度的单位不可为百分比(%):
HTML 修改为:
<fieldset>
<legend><span>哪些浏览器legend标签设定的宽度有效</span></legend>
<input type="checkbox" value="ie6" name="width" id="ie6" checked="checked" /><label for="ie6">IE6</label>
<input type="checkbox" value="ie7" name="width" id="ie7"checked="checked" /><label for="firefox">IE7</label>
<input type="checkbox" value="firefox2" name="width" id="firefox2" /><label for="firefox2">Firefox2</label>
<input type="checkbox" value="firefox3" name="width" id="firefox3" /><label for="firefox3">Firefox3</label>
<input type="checkbox" value="opera" name="width" id="opera" checked="checked" /><label for="opera">Opera9.0 </label>
<input type="checkbox" value="safari" name="width" id="safari"checked="checked" /><label for="safari">Safari3.0 </label>
</fieldset>

CSS 修改为:
legend span {
background:red;
width:500px;
display:block;
}

可参考:《how to set width of LEGEND tags in FF》
正淳 同时也提供了另外的一种解决方案,无需修改结构,仅修改样式即可:
legend {
background:red;
text-indent:-600px;
padding-left:600px;
/*IE下还原初始方式,只设定宽度*/
*width:600px;
*text-indent:0;
*padding-left:0;
}
题外话:CSS 的兼容其实并不难,多尝试多实践就可以解决,最重要的是自己要去动手,只有动手了才会有更多的收获,才会有更深的印象。