I am trying to vertically center the three child-divs <div class="section">
as 3 rows in one column inside <div class="container_page_2">
.
By vertically align I understand having the same distance between the top of the page and the first <div class="section">
and between the bottom of the page and the last/third <div class="section">
.
I thought that by adding them inside a wrapper (<div class="center-container">
) and center that wrapper inside the main container <div class="container_page_2">
will fix my issue, but I couldn't do it.
I would like to avoid using display: table;
because, as I understand, it's quite old and rusty.
<div id="parent-container">
<div id=child-container>
<!-- #page2 -->
<div class="container_page_2">
<div class="center-container">
<div class="section">
<div class="left-half s1">
</div>
<div class="right-half s1">
</div>
</div>
<div class="section">
<div class="left-half s2">
</div>
<div class="right-half s2">
</div>
</div>
<div class="section">
<div class="left-half s3">
</div>
<div class="right-half s3">
</div>
</div>
</div>
</div>
</div>
</div>
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* *** index.html - START *** */
body, html {
height: 100%;
width: 100%;
overflow: hidden;
}
#parent-container {
height: 100%;
width: 100%;
overflow: hidden;
position: relative;
}
#child-container {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px; /* exact value is given through JavaScript */
overflow: auto;
scroll-snap-type: both proximity;
}
.container_page_2 {
width: 100%;
height: 100%;
background-color: green;
scroll-snap-align: center;
position: relative;
}
.container_page_2 .center-container {
position: absolute;
height: 100%;
width: 100%;
left: 0;
}
.container_page_2 .center-container .section {
/* position: relative; */
margin: 1% 0;
width: 100%;
height: 30%;
float: left;
border: 2px solid rgba(0, 0, 0, 0.5);
box-sizing: border-box;
/* z-index: 1; */
/* text-align: center; */
}
/* *** index.html - END *** */
Here is the CodePen
for the above code.
This web-page is from a project-website that has 3 pages in total.
The following divs are used for scroll-snap
:
<div id="parent-container">
<div id=child-container>
As to offer some more context, here is the whole project.
What do you think ?