1
I currently have the following code:
html, body, .content{
height:100%;
}
nav {
height: 15%;
background-color: red;
}
footer {
position: fixed;
bottom: 0;
width: 100%;
background-color: rgba(0,255,0,0.5);
}
main {
color: white;
background-color: blue;
position: absolute;
width: 100%;
top: 50%;
transform: translateY(-50%);
}
<div class="content">
<nav>
<p>Menu</p>
</nav>
<main>
<p>content</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</main>
<footer>
<p>footer</p>
</footer>
</div>
However, if the content is too large:
html, body, .content{
height:100%;
}
nav {
height: 15%;
background-color: red;
}
footer {
position: fixed;
bottom: 0;
width: 100%;
background-color: rgba(0,255,0,0.5);
}
main {
color: white;
background-color: blue;
position: absolute;
width: 100%;
top: 50%;
transform: translateY(-50%);
}
<div class="content">
<nav>
<p>Menu</p>
</nav>
<main>
<p>content</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse a mattis ante, ut rhoncus lorem. Sed pretium viverra elit, id sollicitudin lacus congue eu. Nam mattis velit at velit vulputate ornare vitae quis metus. Nam tortor elit, dictum id pellentesque id, efficitur sed nulla. Donec justo ipsum, porttitor eget odio a, laoreet dictum sapien. Pellentesque mi elit, facilisis ac suscipit vel, elementum non nisl. Aliquam sit amet felis a eros sagittis semper. Vestibulum maximus tristique diam, scelerisque posuere quam fermentum a. Quisque vitae dolor a sapien pretium luctus. Curabitur consectetur consequat diam id pellentesque. Donec non laoreet ipsum, ac pharetra ex. Etiam a tellus turpis. Aliquam at magna laoreet, consequat massa in, fringilla lorem.</p>
</main>
<footer>
<p>footer</p>
</footer>
</div>
Is there any way I can center the content without using the set position: absolute; top: 50%; transform: translateY(-50%);
?
E There is some way to make the footer align in the footer of the page while the content is small and do not create scroll bar and that this is below the content when you have scroll bar?
And if you use
z-index:1;
on the footer to bring it forward?– Rodrigo Tognin
It is already in front, but with transparency, to show that it has content behind. I would like it to be below, and not in front
– Pilati
I suggest removing the
position:fixed
I have a page here that works like this and does not have the position informed, only thebottom:0
.– Rodrigo Tognin