Создание вертикально прокручиваемого div с неизвестной высоты

#html #css

#HTML #css

Вопрос:

У меня есть всплывающий div, высота которого равна 100%.

 .popup{
height:100%;
}
  

Я пошел дальше и создал верхнюю границу 60%

 .popup{
margin-top:60%;
}
  

и поэтому в нижней части всплывающего окна доступно только 40% пространство.

В 40% нижнем пространстве я хочу иметь прокручиваемый контейнер div, возможно, высотой 500px . Это не работает, доступно только 40% пространство, и полосы прокрутки не отображаются.

Как я могу 500px использовать 40% доступное пространство?.

Комментарии:

1. Любая работа с HTML также

2. Предоставьте свой пробный код

3. Я работаю исключительно с классом popup и нижней половиной div. .popup{margin-top:60%;} .bottomhalfdiv{height:500px;}

Ответ №1:

Проверьте этот фрагмент:

 body,
html,
.outer {
    width: 100%;
    height: 100%;
}
.wrapper-top, .wrapper-bottom {
    position: relative;
    width: 400px;
    top: 0;
    bottom: 0;
    border: 1px solid #555;
}
.wrapper-top {
    height: 60%;
}
.wrapper-bottom {
    height: 40%;
}
.inner {
    position: absolute;
    width: 100%;
    top: 0px;
    bottom: 0px;
    overflow-y: auto;
}  
 <div class="outer">
<div class="wrapper-top">
   <div class="inner">
      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.
   </div>
</div>
<div class="wrapper-bottom">
   <div class="inner">
      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.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.
   </div>
</div>
</div>  

Ответ №2:

 .main{
  width:100%;
  height:350px;
  border:1px solid;
}
.top{
  width:100%;
  height:60%;
  border:1px solid red;
}
.bottom{
  display:inline-block;
  width:100%;
  height:38%;
  border:1px solid #ff6600;
  padding:5px;
  overflow:auto;
}
.content{
  width:100%;
  height:500px;
  border:1px solid blue;
}  
 <div class="main">
<div class="top"></div>
  <div class="bottom">
  <div class="content"></div>
  </div>
</div>  

Комментарии:

1. K Попробуйте это один раз, высота должна составлять 40%, а высота содержимого — 500 пикселей, Ок

Ответ №3:

Пожалуйста, проверьте эту скрипку:https://jsfiddle.net/vadimb/wx2v7pj6 /

 .popup {  
    margin-top: 60%;
    background-color: red;
    height: 250px;
    overflow: hidden;
}

.inner {
   overflow-y: scroll;
   height: 250px;
}
  

И html

 <div class="popup">
 <div class="inner">
 abcd<br/>....
 </div>
</div>