html - 拆分 Pane 场景中的内部 DIV 包装(jQueryUI 可调整大小)

标签 html css jquery-ui

受互联网上基于 jQueryUI 可调整大小的示例的启发,我试图更进一步,将一些 DIV 嵌套到拆分 Pane 中,但是,一旦我添加嵌套的 div,右侧就会换行到下一行。

HTML:-

<div id="splitter">
  <div id="one">
    <!--div id="nested" /-->
  </div>
  <div id="two" />
</div>

CSS:-

body, html {
  width: 100%;
  height: 100%;
  margin: 0px;
  border: 0px;
  padding: 0px;
}

#splitter {
  width: calc(100% - 2*10px);
  height: calc(100% - 2*10px);
  margin: 0px;
  border: 0px;
  padding: 10px;
  background: grey;
}

#one, #two {
  width: 50%;
  height: 100%;
  max-width: 90%;
  min-width: 10%;
  margin: 0px;
  border: 0px;
  padding: 0px;
  float: left;
  background: orange;
}

#two {
  background: green;
}

#nested {
  width: calc(100% - 2*3px);
  height: calc(100% - 2*3px);
  margin: 3px;
  border: 0px;
  padding: 0px;
  background: black;
}

JavaScript(加载时):-

$(function () {
  var innerDiv1 = $('#one');
  innerDiv1.resizable({
    handles: 'e',
    resize: function(event, ui) {
      var parent = $('#splitter');
      var child1 = $('#one');
      var child2 = $('#two');
      var parent_width = parent.width();
      var child1_width = child1.outerWidth(true);
      var child2_width = parent_width - child1_width - (child2.outerWidth(true) - child2.width()) - 1;
      child2.outerWidth(child2_width);
    }
  });
});

结果:-

我需要添加/更改什么才能让拆分 Pane 在添加内容时也能正常工作?

最佳答案

通过使用外部 flexbox 而不是内部 float 解决:https://jsfiddle.net/Lgwtn0nk/7/

body,
html {
  width: 100%;
  height: 100%;
}

#splitter {
  width: calc(100% - 6px);
  height: calc(100% - 6px);
  padding:3px;
  background: grey;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
}

#one,
#two {
  width: 50%;
  height: 100%;
  max-width: 90%;
  min-width: 10%;
  background: orange;
}

#two {
  background: green;
}

#nested {
  width: auto;
  height: calc(100% - 6px);
  margin:3px;
  background: black;
}

关于html - 拆分 Pane 场景中的内部 DIV 包装(jQueryUI 可调整大小),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40467484/

相关文章:

Javascript OpenWindow 不加载样式表不工作

css - Firefox 不为较小尺寸的屏幕使用 CSS

jquery - 以编程方式 'unselect' 一个 jQuery UI 可选择的小部件

jquery - 可编辑的 DIV HTML CSS

html - 在 WordPress 标题中垂直居中元素

javascript - 如何更改页面上的文字? (使用 jQuery 查找和替换?)

reactjs - 第二个 flex 元素的背景颜色也适用于第一个元素?

jquery-ui - jQuery Draggable 和溢出问题

html - 这个空白区域是如何进入我的网站的?

css - 重叠的 div 使链接无法点击