首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Textarea溢出div,即使设置了框大小:border-box

Textarea溢出div,即使设置了框大小:border-box
EN

Stack Overflow用户
提问于 2013-03-14 08:12:01
回答 1查看 1.6K关注 0票数 0

我正在尝试让一个文本区域扩展到适合其父目录的100%,但我在IE9中遇到了问题。下面是整个页面代码:

代码语言:javascript
复制
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
    #wrap {
        width: 50%;
        height: 100px;
        background:#fee; border:3px double #f99;
    }

    textarea {
        background:#efe;
        width: 100%;
        height: 100%;
        padding: 10px;
        border:0; margin:0;
        box-sizing:border-box;
        overflow: auto;
        display: block;    
    }
    </style>
</head>
<body>
    <div id="wrap"><textarea>hello world</textarea></div>
</body>
</html>

这张图显示了结果。result http://polybemani.net/uploader/files/1/cssboxsizing.png

它在Chrome上显示得很好,但在IE9和IE10上就不行了。我不明白的是,使用完全相同的代码,它在jsfiddle中工作得很好。怎么回事?

EN

回答 1

Stack Overflow用户

发布于 2013-03-15 01:28:29

答案是:

添加

代码语言:javascript
复制
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

到head标签修复了这个问题。显然IE是在怪癖模式下。你学得越多!

希望这能帮助下一个遇到这个问题的人!

完整的源代码:

代码语言:javascript
复制
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title></title>
    <style type="text/css">
        #wrap {
            width: 50%;
            height: 100px;
            background:#fee;
            border: 3px solid red;
        }

        textarea {
            background:#efe;
            padding: 10px;
            border:0; 
            margin:0;
            box-sizing:border-box;
            overflow: auto;
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div id="wrap"><textarea>hello world</textarea></div>
</body>
</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15398913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档