javascript - 如何使 2 div 的中间可调整大小以更改大小? (我正在使用 Bootstrap 4)

标签 javascript html css twitter-bootstrap bootstrap-4

我有以下布局:

我想这样做,以便用户可以将光标放在 content1 和 content2 的中间,并能够左右拖动它以调整它的大小(使 content1 变大/content2 变小。有没有办法做到这一点使用我当前的代码? enter image description here

CSS

body{
  height: 100%;
  width: 100%;
}
.main-wrapper{
  background-color: #f5f5f5;
  height: 100%;
  left: 0;
  padding-bottom: 50px;
  padding-top: 50px;
  position: fixed;
  top: 0;
  width: 100%;
}
@media (max-width: 991px){
  .main-wrapper{
    overflow-x: hidden;
    overflow-y: auto;
  }
}
.header-wrapper{
  background-color: #009688;
  color: white;
  height: 50px;
  width: 100%;
}
.footer-wrapper{
  background-color: #121212;
  color: white;
  height: 50px;
  width: 100%;
}
.body-wrapper{
  background-color: #f0f0f0;
  width: 100%;
}
.content-1{
  background-color: #2DC050;
  color: white;
  padding: 30px;
  width: 100%;
}
.content-2{
  background-color: #1FA325;
  color: white;
  padding: 30px;
  width: 100%;
}
@media (min-width: 992px){
  .content-1,
  .content-2{
    overflow-x: hidden;
    overflow-y: auto;
  }
}

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<div class="main-wrapper d-flex flex-row">
  <div class="header-wrapper fixed-top d-flex flex-row align-items-center justify-content-center">
    I'm fixed header. I will be alwase visible on top. I'm fixed height.
  </div>
  <div class="body-wrapper d-flex flex-row flex-wrap">
    <div class="col-12 col-lg-6 d-flex flex-row pl-0 pr-0">
      <div class="content-1 d-flex flex-column text-center">
        <h1>I'm content One. My position is left. I'm alwase fit with any browser window except header and footer height. Also I'm scrollable if content isn't fit.</h1>
        <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
      </div>
    </div>
    <div class="col-12 col-lg-6 d-flex flex-row pl-0 pr-0">
      <div class="content-2 d-flex flex-column">
        <h1>I'm content Two. My position is right. I'm alwase fit with any browser window except header and footer height. Also I'm scrollable if content isn't fit.</h1>
        <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
      </div>
    </div>
  </div>
  <div class="footer-wrapper fixed-bottom d-flex flex-row align-items-center justify-content-center">
    I'm fixed footer. I will be alwase visible on bottom. I'm fixed height.
  </div>
</div>
 Run code snippetExpand snippet
Header and Footer always fixed.
Content 1 and Content 2 will be scroll-able if browser min-width is 992px.
Entire page will be scroll-able if browser max-width is 991px.
Edit for Ronaldo comments. Answer is yes it's possible. Check the bottom snippet.

body{
  height: 100%;
  width: 100%;
}
.main-wrapper{
  background-color: #f5f5f5;
  height: 100%;
  left: 0;
  padding-bottom: 50px;
  padding-top: 50px;
  position: fixed;
  top: 0;
  width: 100%;
}
.header-wrapper{
  background-color: #009688;
  color: white;
  height: 50px;
  width: 100%;
}
.footer-wrapper{
  background-color: #121212;
  color: white;
  height: 50px;
  width: 100%;
}
.body-wrapper{
  background-color: #f0f0f0;
  width: 100%;
}
@media (max-width: 991px){
  .body-wrapper{
    overflow-x: hidden;
    overflow-y: auto;
  }
}
.content-1{
  background-color: #2DC050;
  color: white;
  padding: 30px;
  width: 100%;
}
.content-2{
  background-color: #1FA325;
  color: white;
  min-height: 700px;
  padding: 30px;
  width: 100%;
}
@media (min-width: 992px){
  .content-1{
    overflow-x: hidden;
    overflow-y: auto;
  }
}
.content-2-1{
  background-color: #0D420F;
  padding: 20px;
  width: 100%;
}


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<div class="main-wrapper d-flex flex-row">
  <div class="header-wrapper fixed-top d-flex flex-row align-items-center justify-content-center">
    I'm fixed header. I will be alwase visible on top. I'm fixed height.
  </div>
  <div class="body-wrapper d-flex flex-row flex-wrap">
    <div class="col-12 col-lg-6 d-flex flex-row pl-0 pr-0">
      <div class="content-1 d-flex flex-column text-center">
        <h1>I'm content One. My position is left. I'm alwase fit with any browser window except header and footer height. Also I'm scrollable if content isn't fit.</h1>
        <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
      </div>
    </div>
    <div class="col-12 col-lg-6 d-flex flex-row pl-0 pr-0">
      <div class="content-2 d-flex flex-column">
        <h1>I'm content Two. My position is right. I'm alwase fit with any browser window except header and footer height. Also I'm scrollable if content isn't fit.</h1>
        <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
      </div>
    </div>
  </div>
  <div class="footer-wrapper fixed-bottom d-flex flex-row align-items-center justify-content-center">
    I'm fixed footer. I will be alwase visible on bottom. I'm fixed height.
  </div>
</div>

最佳答案

好吧,我认为您不能仅使用纯 HTML 和 CSS 属性来做到这一点。 使用允许您通过拖动调整 div 大小的 Jquery resizable()。

<script>
   $( function() {
      $( "#divID" ).resizable();
   } );
</script>`

来源:https://jqueryui.com/resizable/

关于javascript - 如何使 2 div 的中间可调整大小以更改大小? (我正在使用 Bootstrap 4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48874875/

相关文章:

html - 编码一个灵活的 HTML 运动支架

javascript - DOM MutationObservers:如何支持DOM3突变事件的这一重要用途?

html - 用图标替换提交按钮——基础知识

javascript - jQuery 从 JSON 数组中获取数据

javascript - 无法让 magnific 弹出窗口工作,两个 javascript 错误

javascript - 通知 : closable "false" not working?

javascript - 如何让comodo弹出窗口覆盖其他元素?

css - 组合框 extjs 6 中显示的超赞字体图标

javascript - 正则表达式:非单词字符前面有空格或位于行首

javascript - Jquery UI 无法与 1.12 版本一起使用