简体   繁体   English

如何使2个div的中间尺寸可调整大小以更改大小? (上午使用引导程序4)

[英]How to make the middle of 2 divs resizable to change sizing? (am using bootstrap 4)

I have the following layout: 我有以下布局:

I want to make it so that the user can put their cursor in the middle of content1 and content2 and be able to drag it left and right to resize it (making content1 bigger/content2 smaller. Is there a way to do this with my current code? 我想这样做,以便用户可以将光标置于content1和content2的中间,并可以左右拖动以调整大小(使content1变大/ content2变小。有没有办法用我当前的码? 在此处输入图片说明

CSS 的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 的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>

Well, I don't think you can do this with only pure HTML and CSS properties. 好吧,我认为您不能仅使用纯HTML和CSS属性来做到这一点。 Use the Jquery resizable() that allows you to resize divs by draggin. 使用Jquery resizable()允许您通过draggin调整div的大小。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM