Javascript 如何使div可调整大小

Javascript 如何使div可调整大小,javascript,html,css,Javascript,Html,Css,你好,stackoverflow社区,我需要脚本方面的帮助。我正在使用NicEditor,我正在尝试使它像文本区域一样可调整大小。但是,当我设置div:resize:both时,它可以调整高度,但不能调整宽度。 下面是脚本: <div style="width: 147px; border-width: 0px 1px 1px; border-style: none solid solid; border-color: -moz-use-text-color rgb(204, 20

你好,stackoverflow社区,我需要脚本方面的帮助。我正在使用NicEditor,我正在尝试使它像文本区域一样可调整大小。但是,当我设置div:
resize:both
时,它可以调整高度,但不能调整宽度。 下面是脚本:

    <div style="width: 147px; border-width: 0px 1px 1px; border-style: none solid solid; border-color: -moz-use-text-color rgb(204, 204, 204) rgb(204, 204, 204); -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none; -moz-border-left-colors: none; border-image: none; overflow-y: auto; overflow-x: hidden;">
<div class=" nicEdit-main" style="resize:both; width: 139px; margin: 4px; min-height: 45px; overflow: hidden;" contenteditable="true">
<br>
</div>
</div>



如何使此编辑器像文本区域一样可调整大小?这是jsfidle:

嗯,可能是这样的(主div样式:overflow:auto;resize:both)


大众汽车


我首先做的是创建一个名为
editorcontainer
的div,并插入您在html中为NicEditor容器使用的值

通过添加
width:auto
和添加
display:inline block
并删除所有溢出值,div现在将适应子对象的宽度和高度

下面是一个例子:


bkLib.ondomload(nicEditors.allTextAreas)
.nicEdit main{
调整大小:两者;
边框:1px纯灰;
}
.editorcontainer{
宽度:自动;
边框宽度:0px 1px 1px;
边框样式:非实心;
边框颜色:-moz使用文本颜色rgb(204204204)rgb(204204204);
-moz边框顶部颜色:无;
-moz边框右颜色:无;
-moz边框底色:无;
-moz边框左侧颜色:无;
边界图像:无;
显示:内联块;
}



这有点老套,但我就是这么做的:

bkLib.onDomLoaded(function () {
    nicEditors.allTextAreas();
    $("#container").children().css("width", "100%");
    $("#container").resizable();
    $("#textarea1").prev().css("height", "70%");
});

.nicEdit-main {
    height:90%;
    width:98% !important;
}
textarea {
    width:100%;
}
#container {
    overflow:hidden;
}

你试过吗?请在发布答案之前尝试您的解决方案。我可以在js fiddle、chrome mac中以两种方式调整大小
bkLib.onDomLoaded(function () {
    nicEditors.allTextAreas();
    $("#container").children().css("width", "100%");
    $("#container").resizable();
    $("#textarea1").prev().css("height", "70%");
});

.nicEdit-main {
    height:90%;
    width:98% !important;
}
textarea {
    width:100%;
}
#container {
    overflow:hidden;
}