Я пытаюсь добиться определенного flex-direction: column
макета для веб-страницы; Он работает во всех браузерах настольных компьютеров, но в Mobile Safari он выглядит неправильно.
Вот пример макета с необходимым HTML / CSS, чтобы продемонстрировать то, что я ищу:
<!DOCTYPE html>
<html>
<head>
<style>
html,
body {
height: 100vh;
margin: 0;
padding: 0;
}
p {
margin: 0;
padding: 0;
}
.container {
display: flex;
flex-direction: column;
height: 100vh;
}
.header {
background: green;
height: 150px;
}
.content {
background: gray;
flex: 1 0 auto;
min-height: 1px; /* IE11 fix */
}
.contentContainer {
background: blue;
display: flex;
flex-direction: column;
height: 100%;
margin: auto;
width: 600px;
}
.contentHeader {
background: red;
height: 75px;
}
.contentBody {
background: yellow;
flex: 1 0 auto;
height: 0;
overflow-y: auto;
}
.footer {
background: purple;
height: 150px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
</div>
<div class="content">
<div class="contentContainer">
<div class="contentHeader">
</div>
<div class="contentBody">
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
<p>Lots of content here.</p>
</div>
</div>
</div>
<div class="footer">
</div>
</div>
</body>
</html>
Если вы загрузите его в любой браузер (например, Chrome, Firefox, Edge, IE11 и т. Д. c.), Это даст ожидаемый эффект, то есть вертикальную полосу прокрутки для Желтая часть с надписью «Здесь много контента».
Если вы загрузите страницу в Mobile Safari, желтая область не будет видна / не существует. Я подозреваю, что это из-за определения height: 0
, установленного для contentBody
div. Проблема в том, что если я удаляю определение height: 0
, то контент растягивает всю страницу, чего я тоже не хочу.
Я хочу, чтобы верхний / нижний колонтитул и верхний колонтитул отображались постоянно, и для желтой области тела контента, чтобы заполнить любую оставшуюся высоту на странице и добавить вертикальную полосу прокрутки, когда содержание тела контента достаточно длинное, чтобы его понадобиться.
Как мне добиться этого эффекта с Flexbox и сделать это работает во всех настольных и мобильных браузерах? Спасибо.
Редактировать # 1 : Обратите внимание, что хотя я установил фиксированные высоты для верхнего, нижнего колонтитула и т. Д. c. в примере на моей реальной странице нет заданных высот. Все динамично c, поэтому использование чего-то вроде calc(100% - 300px)
не сработает. Спасибо.