我正在尝试创建一个包含页眉、正文和页脚的全高 div ( .wrapper ),其中根据内容,页眉/页脚应扩展/收缩,如果溢出,正文应滚动,

或者换句话说

我不希望容器 div 滚动,只有主体应该在溢出时滚动。

.wrapper {
  position: absolute;
  top: 0;
  width: 50%;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  box-shadow: 0 0 10px 1px #7f7f7f;
}

.wrapper .blade-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid #7f7f7f;
  border-bottom: none;
  align-self: strech;
}

.wrapper .blade-container .blade-header {
  display: flex;
  background-color: black;
  color: white;
  justify-content: space-between;
  padding: 5px;
}

.wrapper .blade-container .blade-header .header-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-family: "Segoe UI", "Segoe UI Light", "Segoe WP Light", "Segoe WP", Tahoma, Arial, sans-serif;
}

.wrapper .blade-container .blade-header .header-title .header-title-wrapper {
  width: 100%;
  color: inherit;
}

.wrapper .blade-container .blade-header .header-actions {
  display: flex;
}

.wrapper .blade-container .blade-header .header-actions .action-button {
  display: flex;
  height: 30px;
  width: 30px;
  background-color: transparent;
  justify-content: center;
  align-items: center;
  transition: background-color 0.4s ease-out;
  cursor: pointer;
}

.wrapper .blade-container .blade-header .header-actions .action-button:hover {
  background: rgba(230, 230, 230, 0.3);
}

.wrapper .blade-container .blade-header .header-actions .danger:hover {
  background-color: #aa0000 !important;
}

.wrapper .blade-container .blade-body {
  display: flex;
  padding: 5px;
  height: 100%;
  background-color: white;
}

.wrapper .blade-container .blade-body .blade-body-wrapper {
  width: 100%;
  height: 100%;
  background-color: inherit;
  overflow-y: auto;
}

.wrapper .blade-container .blade-footer {
  display: flex;
  align-self: stretch;
  color: white;
}

.wrapper .blade-container .blade-footer .blade-footer-wrapper {
  padding: 3px;
  width: 100%;
  height: 100%;
  background-color: #323232;
}
<div class="wrapper">
  <div class="blade-container">
    <div class="blade-header">
      <div class="header-title">
        <div class="header-title-wrapper">
          Lorem Ipsum
        </div>
      </div>
      <div class="header-actions">
        <span class="action-button">
          <b>&#x0229f;</b>
        </span>
        <span class="action-button" (click)="onMaximize()">
          <b>&#x0229E;</b>
        </span>
        <span class="action-button danger" id="ngxBladeCloseBtn">
          <b>&times;</b>
        </span>
      </div>
    </div>
    <div class="blade-body">
      <div class="blade-body-wrapper">
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
          It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
          desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

        Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using
        'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their
        infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

        <h3> Where does it come from? </h3>
        <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>

        <p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English
          versions from the 1914 translation by H. Rackham.
        </p>

        <h3> Where can I get some? </h3>
        <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem
          Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It
          uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic
          words etc.</p>
      </div>
    </div>
    <div class="blade-footer">
      <div class="blade-footer-wrapper">
        <h3> Footer </h3>
        "On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal
        blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled
        and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that
        pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."
      </div>
    </div>
  </div>
</div>


现在我也得到了包装器的滚动条,我该如何避免它?

我尝试为 overflow-y: hidden 设置 .wrapper ,但它只是隐藏了页脚。

对于冗长的代码,我很抱歉,它用于使用 ng-content 的 Angular 组件,因此在页眉、正文和页脚中添加了所有其他包装类。

Codepen

最佳答案

如果您希望 .blade-body 滚动,则删除 height: 100%; 并使用 flex:1; + overflow:scroll;

.wrapper {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  right: 0;
  overflow-y: auto;
  box-shadow: 0 0 10px 1px #7f7f7f;
}
.wrapper .blade-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid #7f7f7f;
  border-bottom: none;
  align-self: strech;
}
.wrapper .blade-container .blade-header {
  display: flex;
  background-color: black;
  color: white;
  justify-content: space-between;
  padding: 5px;
}
.wrapper .blade-container .blade-header .header-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-family: "Segoe UI", "Segoe UI Light", "Segoe WP Light", "Segoe WP",
    Tahoma, Arial, sans-serif;
}
.wrapper .blade-container .blade-header .header-title .header-title-wrapper {
  width: 100%;
  color: inherit;
}
.wrapper .blade-container .blade-header .header-actions {
  display: flex;
}
.wrapper .blade-container .blade-header .header-actions .action-button {
  display: flex;
  height: 30px;
  width: 30px;
  background-color: transparent;
  justify-content: center;
  align-items: center;
  transition: background-color 0.4s ease-out;
  cursor: pointer;
}
.wrapper .blade-container .blade-header .header-actions .action-button:hover {
  background: rgba(230, 230, 230, 0.3);
}
.wrapper .blade-container .blade-header .header-actions .danger:hover {
  background-color: #aa0000 !important;
}
.wrapper .blade-container .blade-body {
  display: flex;
  padding: 5px;
  flex: 1;
  overflow: auto;
  background-color: white;
  border: solid red;
}
.wrapper .blade-container .blade-body .blade-body-wrapper {
  width: 100%;
  height: 100%;
  background-color: inherit;
  overflow-y: auto;
}
.wrapper .blade-container .blade-footer {
  display: flex;
  align-self: stretch;
  color: white;
}
.wrapper .blade-container .blade-footer .blade-footer-wrapper {
  padding: 3px;
  width: 100%;
  height: 100%;
  background-color: #323232;
}
<div class="wrapper">
  <div class="blade-container">
    <div class="blade-header">
      <div class="header-title">
        <div class="header-title-wrapper">
          Lorem Ipsum
        </div>
      </div>
      <div class="header-actions">
        <span class="action-button">
          <b>&#x0229f;</b>
        </span>
        <span class="action-button" (click)="onMaximize()">
          <b>&#x0229E;</b>
        </span>
        <span class="action-button danger" id="ngxBladeCloseBtn">
          <b>&times;</b>
        </span>
      </div>
    </div>
    <div class="blade-body">
      <div class="blade-body-wrapper">
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
          It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
          desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

        Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using
        'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their
        infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

        <h3> Where does it come from? </h3>
        <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>

        <p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English
          versions from the 1914 translation by H. Rackham.
        </p>

        <h3> Where can I get some? </h3>
        <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem
          Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It
          uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic
          words etc.</p>
      </div>
    </div>
    <div class="blade-footer">
      <div class="blade-footer-wrapper">
        <h3> Footer </h3>
        "On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal
        blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled
        and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that
        pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."
      </div>
    </div>
  </div>
</div>


此外,设置一些 min-height 可能是明智的,因此内容在较小的屏幕上仍然可见

.wrapper {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  right: 0;
  overflow-y: auto;
  box-shadow: 0 0 10px 1px #7f7f7f;
}
.wrapper .blade-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid #7f7f7f;
  border-bottom: none;
  align-self: strech;
}
.wrapper .blade-container .blade-header {
  display: flex;
  background-color: black;
  color: white;
  justify-content: space-between;
  padding: 5px;
}
.wrapper .blade-container .blade-header .header-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-family: "Segoe UI", "Segoe UI Light", "Segoe WP Light", "Segoe WP",
    Tahoma, Arial, sans-serif;
}
.wrapper .blade-container .blade-header .header-title .header-title-wrapper {
  width: 100%;
  color: inherit;
}
.wrapper .blade-container .blade-header .header-actions {
  display: flex;
}
.wrapper .blade-container .blade-header .header-actions .action-button {
  display: flex;
  height: 30px;
  width: 30px;
  background-color: transparent;
  justify-content: center;
  align-items: center;
  transition: background-color 0.4s ease-out;
  cursor: pointer;
}
.wrapper .blade-container .blade-header .header-actions .action-button:hover {
  background: rgba(230, 230, 230, 0.3);
}
.wrapper .blade-container .blade-header .header-actions .danger:hover {
  background-color: #aa0000 !important;
}
.wrapper .blade-container .blade-body {
  display: flex;
  padding: 5px;
  flex: 1;
  overflow: auto;
  min-height:50vh;
  background-color: white;
  border: solid red;
}
.wrapper .blade-container .blade-body .blade-body-wrapper {
  width: 100%;
  height: 100%;
  background-color: inherit;
  overflow-y: auto;
}
.wrapper .blade-container .blade-footer {
  display: flex;
  align-self: stretch;
  color: white;
}
.wrapper .blade-container .blade-footer .blade-footer-wrapper {
  padding: 3px;
  width: 100%;
  height: 100%;
  background-color: #323232;
}
<div class="wrapper">
  <div class="blade-container">
    <div class="blade-header">
      <div class="header-title">
        <div class="header-title-wrapper">
          Lorem Ipsum
        </div>
      </div>
      <div class="header-actions">
        <span class="action-button">
          <b>&#x0229f;</b>
        </span>
        <span class="action-button" (click)="onMaximize()">
          <b>&#x0229E;</b>
        </span>
        <span class="action-button danger" id="ngxBladeCloseBtn">
          <b>&times;</b>
        </span>
      </div>
    </div>
    <div class="blade-body">
      <div class="blade-body-wrapper">
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
          It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
          desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

        Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using
        'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their
        infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

        <h3> Where does it come from? </h3>
        <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>

        <p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English
          versions from the 1914 translation by H. Rackham.
        </p>

        <h3> Where can I get some? </h3>
        <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem
          Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It
          uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic
          words etc.</p>
      </div>
    </div>
    <div class="blade-footer">
      <div class="blade-footer-wrapper">
        <h3> Footer </h3>
        "On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal
        blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled
        and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that
        pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."
      </div>
    </div>
  </div>
</div>

关于html - 具有可扩展页眉和页脚以及滚动体的 Flexbox,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51449797/

10-12 13:00