Исправлено позиционное переполнение, а не свитки - PullRequest
0 голосов
/ 26 июня 2018

Здесь, в моем html, я не знаю высоту header.так как сделать так, чтобы содержимое стало прокручиваться при переполнении?

.parent{
  border:2px solid red;
  position:fixed;
  top:0;
  left:0;
  width:20%;
  height:50%;
}

header{
  width:100%;
  border:1px solid red;
}

.content{
  flex:1;
  position: relative;
  overflow-y:scroll;
  background:lightgreen;
}
<div class="parent">
  <section>
    <header>
      <h1>Title</h1>  
    </header>
    <div class="content">
      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.

      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).
    </div>
  </section>
</div>  

Ответы [ 2 ]

0 голосов
/ 26 июня 2018

Я вижу, что у вас есть .content div с набором flex:1;, который вам нужен, чтобы установить родительский элемент ваших элементов flex на display:flex, иначе ваши характеристики flexbox не будут работать.Вы также, вероятно, захотите установить для flex-direction значение column.Также, если вы хотите, чтобы flex-элементы заполняли контейнер, ваши flex-элементы должны быть прямыми потомками родителя, к которому прикреплен display:flex.Так что либо удалите <section>, либо установите <section> в качестве flexbox и присвойте ему display:flex.Вот фрагмент кода:

.parent{
  border:2px solid red;
  position:fixed;
  top:0;
  left:0;
  width:20%;
  height:50%;
  display:flex;
  flex-direction:column;
}

header{
  width:100%;
  border:1px solid red;
}

.content{
	position: relative;
  background:lightgreen;
  width:100%;
  flex:1;
  overflow-Y:scroll;
}
<div class="parent">
  <header>
    <h1>Title</h1>  
  </header>
  <div class="content">
        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.

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).
  </div>
</div>  
0 голосов
/ 26 июня 2018

Вам необходимо указать значение высоты для класса .content, иначе переполнение не будет работать.

.parent{
  border:2px solid red;
  position:fixed;
  top:0;
  left:0;
  width:20%;
  height:50%;
}

header{
  width:100%;
  border:1px solid red;
}

.content{
  flex:1;
  position: relative;
  overflow-y:scroll;
  height: 250px;
  background:lightgreen;
}
<div class="parent">
  <section>
    <header>
      <h1>Title</h1>  
    </header>
    <div class="content">
      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.

      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).
    </div>
  </section>
</div>  

Редактировать: Использовать max-height, если используется динамический контент, поэтому статическая высота недопустима.Затем содержимое, полученное из серверной части, будет занимать столько места, сколько ему нужно, пока оно не достигнет максимального значения высоты, а затем не переполнится.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...