【发布时间】:2018-03-03 09:39:56
【问题描述】:
为什么 word-wrap: break-word CSS 规则不会在 Firefox 中缩小元素,而相应的规则在 Chrome 中有效?
这里的 .form-field 容器被限制为 300px 宽度,其中的 legend 具有 100% 的宽度。里面的长字将legend 拉伸到溢出300px 的宽度。
当我使用(非标准)WebKit word-break 定义将 CSS break-word 规则应用于 Chrome 时,长字被破坏,legend 元素缩小到预期的 300 像素宽度。
在 Firefox 中,相应的word-wrap 规则不会破坏文本并缩小元素,除非我专门将legend 的宽度设置为 300 像素。为什么我必须这样做?为什么 Firefox 不能正确计算“100% of 300px”并调整 legend 的大小?
如果你在 Firefox 上查看这个 sn-p,你会看到 legend 仍然会溢出其容器的 300px 宽度。
.form-field {
border: none;
padding: 0;
max-width: 300px;
margin: 0 auto 10px;
outline: 1px solid purple;
}
.form-field legend {
text-align: left;
width: 100%;
word-wrap: break-word;
word-break: break-word;
}
.form-field input[type=text] {
width: 100%;
font-size: 16px;
padding: 7px 14px;
box-sizing: border-box;
border: 1px solid #c8d7e1;
}
<fieldset class="form-field">
<legend>Betweenthesetwo, InowfeltIhadtochoose. Mytwonatureshadmemoryincommonbutallotherfacultiesweremostunequallysharedbetweenthem.</legend>
<input type="text">
</fieldset>
(在 macOS Chrome 64 和 Firefox 57 中测试)。
【问题讨论】:
标签: css firefox width word-wrap word-break