Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 设置`<;字段集>;`到最大包含元素的宽度_Css - Fatal编程技术网

Css 设置`<;字段集>;`到最大包含元素的宽度

Css 设置`<;字段集>;`到最大包含元素的宽度,css,Css,有没有办法将的宽度设为其内部最大字段的宽度?您的意思是: 字段集{ 溢出:隐藏; 浮动:左; 背景色:#eee; } 输入{ 显示:块; } 第一个{宽度:150px;} input.second{width:200px;} input.third{宽度:250px;} 它是一个浮动字段集。如果你想用另一种方式,请让我们知道。请把你的问题放在一般情况下。是块元素,因此其默认行为是展开以填充可用的水平空间。所以你基本上有两个选择: 设置新的显式宽度 将其布局从block更改为其他内容 下面是

有没有办法将
的宽度设为其内部最大字段的宽度?

您的意思是:


字段集{
溢出:隐藏;
浮动:左;
背景色:#eee;
}
输入{
显示:块;
}
第一个{宽度:150px;}
input.second{width:200px;}
input.third{宽度:250px;}

它是一个浮动字段集。如果你想用另一种方式,请让我们知道。

请把你的问题放在一般情况下。
是块元素,因此其默认行为是展开以填充可用的水平空间。所以你基本上有两个选择:

  • 设置新的显式宽度
  • 将其布局从
    block
    更改为其他内容
  • 下面是一个简单的例子:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head><title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css"><!--
    fieldset.explicit-width{
        width: 1%; /* Will expand to fit content */
    }
    fieldset.inline-block{
        display: inline-block;
    }
    --></style>
    </head>
    <body>
    
    <fieldset><legend>Unstyled</legend>
        <p><input type="text" size="2"></p>
        <p><input type="text" size="20"></p>
        <p><input type="text" size="50"></p>
        <p><input type="text" size="30"></p>
    </fieldset>
    
    <fieldset class="explicit-width"><legend>Explicit width</legend>
        <p><input type="text" size="2"></p>
        <p><input type="text" size="20"></p>
        <p><input type="text" size="50"></p>
        <p><input type="text" size="30"></p>
    </fieldset>
    
    <fieldset class="inline-block"><legend>Inline-block</legend>
        <p><input type="text" size="2"></p>
        <p><input type="text" size="20"></p>
        <p><input type="text" size="50"></p>
        <p><input type="text" size="30"></p>
    </fieldset>
    
    </body>
    </html>
    
    
    未定型
    

    显式宽度

    内联块


    更新:我忘了提到浮动块级元素也会改变其布局。

    我能想到的唯一跨浏览器方法是使其行为类似于表,但这对于
    字段集来说并不完美。有兴趣了解结果吗?您能否就以下解决方案是否令人满意给我们一些反馈?@Pekka一如既往:发挥溢出的魔力:隐藏;为你做这件事:)
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head><title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css"><!--
    fieldset.explicit-width{
        width: 1%; /* Will expand to fit content */
    }
    fieldset.inline-block{
        display: inline-block;
    }
    --></style>
    </head>
    <body>
    
    <fieldset><legend>Unstyled</legend>
        <p><input type="text" size="2"></p>
        <p><input type="text" size="20"></p>
        <p><input type="text" size="50"></p>
        <p><input type="text" size="30"></p>
    </fieldset>
    
    <fieldset class="explicit-width"><legend>Explicit width</legend>
        <p><input type="text" size="2"></p>
        <p><input type="text" size="20"></p>
        <p><input type="text" size="50"></p>
        <p><input type="text" size="30"></p>
    </fieldset>
    
    <fieldset class="inline-block"><legend>Inline-block</legend>
        <p><input type="text" size="2"></p>
        <p><input type="text" size="20"></p>
        <p><input type="text" size="50"></p>
        <p><input type="text" size="30"></p>
    </fieldset>
    
    </body>
    </html>