zoukankan      html  css  js  c++  java
  • 如何给 legend 标签设定宽度

    我们在做表单的时候经常会使用到这样的结构:

    <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 的兼容其实并不难,多尝试多实践就可以解决,最重要的是自己要去动手,只有动手了才会有更多的收获,才会有更深的印象。

  • 相关阅读:
    主成分分析(PCA)原理详解
    局部敏感哈希(Locality-Sensitive Hashing, LSH)方法介绍
    RSA算法原理(二)
    RSA算法原理(一)
    对倾斜的图像进行修正——基于opencv 透视变换
    GeoHash核心原理解析
    303. Range Sum Query
    325. Maximum Size Subarray Sum Equals k
    30. Substring with Concatenation of All Words
    76. Minimum Window Substring
  • 原文地址:https://www.cnblogs.com/c9log/p/1634494.html
Copyright © 2011-2022 走看看