html - 在div容器中输入,不会拉伸(stretch)

标签 html css

我有一个包含输入的 div。我希望输入能够拉伸(stretch)以填充可用空间,这在 Chrome 中有效,但在 IE 和 Firefox 中无效。

<div class="outer">
    <input type="text" />
</div>

.outer{
    width: 100%;
    height: 40px;

    position: relative;
}

input{
    position: absolute;
    top: 7px;
    bottom: 7px;
    left: 7px;
    right: 7px;
}

JSFiddle:http://jsfiddle.net/wwMZg/1/


在 Chrome 中,它看起来像这样: Chrome Screenshot

在 Firefox 和 IE 中,它显示如下: IE Screenshot


  • 在我的实际使用场景中,还有其他 div 包含 Angular 点图像,这就是为什么 topleftright,在此示例中,bottom 值设置为 7px

  • 我想避免直接在输入上设置宽度,我不想在.outer上设置它。

    <

最佳答案

大多数输入元素都有内边距/边框。您需要使用 box-sizing 属性来调整元素尺寸的计算方式。

http://jsfiddle.net/wwMZg/5/

.outer {
    width: 100%;
    height: 40px;
}
.outer input {
    width: 100%;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

http://caniuse.com/#search=box-sizing

关于html - 在div容器中输入,不会拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18721722/

相关文章:

javascript - 推特 Bootstrap 中的链接 <ul <li 不工作

html - CSS Chevron 类似元素,在 li 元素之后带有边框和阴影

javascript - 旋转多边形检测并使直线遵循边界

html - Font Face 不适用于 Internet Explorer 10.. 为什么?

html - 如何防止 IBM Watson Campaign Automation aka Silverpop 在预览行之前插入文本

css - 溢出-x错误?全浏览器宽度条技术

javascript - 仅在元素需要滚动时添加类

javascript - 如果当前选项卡有空字段,则阻止下一个选项卡

javascript - 在仅限客户端的 Web 应用程序上保存和加载文件的正确方法是什么?

html - 空白 : pre-wrap messes up flexbox layout in IE11