I would like the div (home) to be in the middle of the page and that the footer always stays down. The problem however is that when I now shrink the browser window, that the div moves to the top
And I use Bootstrap 5
Excuse my bad English, I hope I could bring it across reasonably understandable
CODE: https://jsfiddle.net/odbefhLy/
.navbar {
background-color: var(--primary-color);
border-top: 2px solid #5f8dd3;
padding-top: 30px;
font-weight: bold;
}
.home {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.logo {
height: 200px;
width: 200px;
border: 5px solid #5f8dd3;
border-radius: 100%;
}
.text h1, h6 {
color: var(--font-color);
text-transform: uppercase;
text-align: center;
}
footer {
height: 55px;
font-size: 12px;
text-decoration: none;
font-weight: bold;
text-transform: uppercase;
color: var(--font-color);
position: absolute;
right: 0;
left: 0;
bottom: 20px;
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
<nav >
<div >
<a href="#">Navbar</a>
<button type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span ></span>
</button>
<div id="navbarNav">
<ul >
<li >
<a aria-current="page" href="#">Home</a>
</li>
</ul>
</div>
</div>
</nav>
<div >
<div >
<div >
<img src="https://duckduckgo.com/assets/common/dax-logo.svg" alt="LOGO">
<div >
<h1>TEST</h1>
<h6>BLABLABLABLABLA</h6>
</div>
</div>
</div>
</div>
<div >
<footer >
<p >© 2021 Company, Inc</p>
<a href="/" >
<svg width="40" height="32"><use xlink:href="#bootstrap"/></svg>
</a>
<ul >
<li ><a href="#" >Home</a></li>
</ul>
</footer>
</div>
CodePudding user response:
try this
.container {
position: relative;
height: 100vh;
}
.container .home {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
CodePudding user response:
.navbar {
background-color: var(--primary-color);
border-top: 2px solid #5f8dd3;
padding-top: 30px;
font-weight: bold;
}
/*CHANGED*/
.home {
}
/*CHANGED*/
body {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.logo {
height: 200px;
width: 200px;
border: 5px solid #5f8dd3;
border-radius: 100%;
}
.text h1, h6 {
color: var(--font-color);
text-transform: uppercase;
text-align: center;
}
/*CHANGED*/
footer {
height: 55px;
font-size: 12px;
text-decoration: none;
font-weight: bold;
text-transform: uppercase;
color: var(--font-color);
margin-top: auto;
}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>
<nav >
<div >
<a href="#">Navbar</a>
<button type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span ></span>
</button>
<div id="navbarNav">
<ul >
<li >
<a aria-current="page" href="#">Home</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- CHANGED -->
<div >
<div >
<div >
<img src="https://duckduckgo.com/assets/common/dax-logo.svg" alt="LOGO">
<div >
<h1>TEST</h1>
<h6>BLABLABLABLABLA</h6>
</div>
</div>
</div>
</div>
<div >
<footer >
<p >© 2021 Company, Inc</p>
<a href="/" >
<svg width="40" height="32"><use xlink:href="#bootstrap"/></svg>
</a>
<ul >
<li ><a href="#" >Home</a></li>
</ul>
</footer>
</div>