我需要你的帮助,
如何将输入框均匀地放置在fieldset元素中,使其相对于fieldset的宽度为100%。
现在看来,输入框正从字段集中推出,我不确定为什么?
以下是问题的图片(IE10):
以下是标记:

<!DOCTYPE html>

<html>

<head>

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

<style type="text/css">
fieldset {
  padding: 3px;
  width: 300px
}
label {
  float:left;
  font-weight:bold;
}
input {
    width: 100%;
}
</style>

</head>

<body>


<fieldset>
  <legend>Subscription info</legend>
    <input type="text" name="name" id="name" />
</fieldset>


</body>

</html>

最佳答案

您面临的问题是浏览器在input上计算的默认样式。浏览器向<input>元素添加填充和边框。
当您在输入上设置width:100%;时,如果添加默认的填充和边框,它会呈现比容器更宽的范围,因此会溢出。
您可以通过在box-sizing:border-box;上添加:input来解决此问题,因此填充和边框包含在100%宽度中。
FIDDLE
关于box-sizing属性的更多信息。

关于html - 使输入框在fieldset元素内为100%均匀宽度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22867571/

10-11 17:21