I have three ul's added to a footer within bootstrap columns inside a parent row element, and I've used vertical-align:top for a similar footer before, but can't use this here to align each ul to the top of the parent div. (It's added to footer > row > .col > ul)
Any ideas?
Codepen: https://codepen.io/nickwcook/pen/aJPGeJ.
HTML:
<footer>
<row>
<div class="col col-sm-3">
<ul>
<li>Quick Menu</li>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<div class="col col-sm-3">
<ul>
<li>Recent Posts</li>
<li>Post One</li>
<li>Post Two</li>
<li>Post Three</li>
</ul>
</div>
<div class="col col-sm-3">
<ul>
<li>About</li>
<li><a>Lorem ipsum dolor sit amet, vel decore vidisse an, id simul quaerendum usu. Et vis nemore mandamus. Ei pri dicit erroribus splendide. Alterum perfecto reprimique et nec, diam dolorum posidonium qui ei.</a></li>
</ul>
</div>
</row>
<row>
<p>Developed by My Name</p>
</row>
</footer>
CSS
footer {
width: 100%;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
background: #212121;
margin: 0;
z-index: 99;
}
footer>row {
display: flex;
align-items: center;
padding: 30px 5%;
}
footer>row:first-of-type {
justify-content: space-between;
}
footer>row>.col {
text-align: left;
}
footer>row>.col>ul>li:first-of-type {
color: #fff;
font-weight: 600;
font-size: 12px;
}
footer>row>.col>ul {
vertical-align: top;
padding: 0;
}
footer>row>.col>ul {
list-style-type: none;
padding: 0;
margin: 0;
}
footer>row>.col ul>li {
margin: 15px 0;
}
footer>row>.col ul>li>a {
font-family: 'Open Sans', sans-serif;
font-size: 11px;
color: #a5a5a5;
}
footer>row>.col ul>li>a:hover {
text-decoration: none;
color: #fff;
}
footer>row:last-of-type {
background: #1f1f1f;
display: flex;
justify-content: center;
}
footer>row:last-of-type>p,
footer>row:last-of-type>p>a {
font-family: 'Open Sans', sans-serif;
}
footer>row:last-of-type>p {
font-family: 'Open Sans', sans-serif;
padding: 0;
margin: 0;
color: #747475;
font-size: 11px;
}
footer>row:last-of-type>p>a {
color: #a5a5a5;
text-decoration: none;
}
footer>row:last-of-type>p>a:hover {
color: #fff;
text-decoration: none;
}
Since you're overriding the normal Bootstap row with flexbox, use the appropriate flexbox alignment..
footer > row
{
display: flex;
align-items: flex-start;
padding: 30px 5%;
}
https://codepen.io/anon/pen/peqKbj
Related
/* #import url("https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Noto+Serif&family=Roboto:wght#500&display=swap"); */
#import url("https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Kanit&family=Montserrat:ital,wght#1,200&family=Noto+Serif&family=Oswald:wght#300;400&family=Roboto+Mono:ital,wght#0,500;1,400&family=Roboto:ital,wght#1,900&display=swap");
* {
padding: 0;
margin: 0;
font-family: calibri;
box-sizing: border-box;
}
html {
font-size: 62.5%;
height: 100%;
scroll-behavior: smooth !important;
}
body {
line-height: 1.4;
font-weight: 300;
position: relative;
font-size: 1.6rem;
height: fit-content;
}
.container {
max-width: 120rem;
margin: 0 auto;
padding: 0 2rem;
}
header {
background-color: #3498db;
position: sticky;
top: 0;
z-index: 100;
box-shadow: 0.5rem 0.5rem 0.5rem rgba(0, 0, 0, 0.5);
/* width: 100%; */
/* min-height: 100%; */
}
ul {
list-style: none;
}
a {
text-decoration: none;
color: black;
font-weight: 40rem;
font-size: 2ren;
}
nav {
display: flex;
justify-content: space-between;
place-items: center;
/* height: 15vh; */
}
nav ul {
display: flex;
flex-direction: row;
gap: 2.2rem;
}
nav ul li {
border-bottom: 0.2rem solid transparent;
transition: 0.2s ease-in;
}
nav ul li:hover {
border-bottom: 0.2rem solid #1b0058;
transition: 0.2s ease-in;
}
.logo {
font-size: 3rem;
font-family: "Noto Serif", serif;
}
.hero-section {
grid-template-columns: repeat(3, 1fr);
background-image: url(../images/Red\ background.jpg);
background-position: center;
background-size: cover;
min-height: 100vh;
width: 100%;
color: white;
}
.hero-section-data {
padding-left: 7rem;
padding-top: 7.5rem;
padding-right: 5rem;
}
.hero-section .container {
display: flex;
justify-content: space-between;
place-items: center;
flex-direction: row;
padding: 3rem 1rem;
flex-direction: row;
}
.hero-section-data h1 {
font-size: 5rem;
font-weight: 500;
line-height: 1.2;
}
.hero-section-data p {
margin: 2rem 0;
padding-bottom: 2rem;
font-size: 1.8rem;
}
.hero-section button {
padding: 1rem 1rem;
background: orange;
border-radius: 1rem;
}
.hero-section button:hover {
color: white;
transition: 0.3s ease-in;
/* transform: scale(1.2) translateY(10px); */
}
.hero-section .image img {
width: 200rem;
max-width: 100%;
position: relative;
left: 5rem;
}
.features-section {
padding-top: 3rem;
background-color: #9df9ef;
width: 100%;
}
.features-section .container {
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
.features-section h2 {
padding-bottom: 2rem;
}
.features-section h3 {
font-family: "Oswald", sans-serif;
padding-bottom: 2rem;
font-size: 5rem;
}
.features-section h5 {
padding-bottom: 2rem;
}
.features-section button {
padding: 0.5rem 1.5rem;
background-color: crimson;
color: white;
font-size: 20px;
}
.features-section button:hover {
opacity: 0.8;
transition: 0.3s ease-in;
}
.features-watch img {
width: 50rem;
max-width: 100%;
position: relative;
margin-top: -29rem;
top: 29rem;
right: 1rem;
}
.comfortable .container {
display: flex;
flex-direction: column;
padding-top: 30rem;
gap: 3rem;
text-align: center;
place-items: center;
}
.comfortable h3 {
font-size: 3rem;
}
.comfortable button {
margin-top: 1rem;
padding: 0.5rem 1.5rem;
background-color: #3498db;
color: white;
font-size: 2rem;
cursor: pointer;
}
.comfortable button:hover {
opacity: 0.8;
transition: 0.3s ease-in;
}
.comfortable img {
margin-top: 10rem;
max-width: 100%;
}
.fitness {
background-image: url(../images/fitness.jpg);
background-size: cover;
background-position: center;
min-height: 100vh;
margin-top: 7.5rem;
width: 100%;
}
.fitness .container {
flex-direction: column;
display: flex;
color: white;
padding: 10rem 0;
justify-content: center;
align-items: center;
text-align: center;
}
.fitness h3 {
font-size: 6.2rem;
padding-bottom: 1rem;
}
.fitness p {
font-size: 2rem;
}
.last-btn {
padding: 0.5rem 1.5rem;
background-color: #3498db;
color: white;
font-size: 2rem;
}
.last-btn:hover {
opacity: 0.8;
transition: 0.3s ease-in;
}
.stock-section {
display: flex;
justify-content: center;
margin: 5rem 0;
gap: 3rem;
}
.stock img {
width: 40rem;
max-width: 100%;
}
.stock-content {
display: flex;
flex-direction: column;
gap: 2rem;
}
.stock-content h3 {
font-size: 3rem;
}
.stock-content button {
place-self: start;
}
.footer-upper {
background-color: #4169e1;
padding: 2.5rem;
}
.footer-upper .container {
display: flex;
color: black;
justify-content: space-between;
}
.footer-upper h4 {
font-size: 2rem;
/* margin-top: -5px; */
border-bottom: 0.2rem solid #1b0058;
margin-bottom: 1rem;
position: relative;
padding-top: 0.5rem;
top: -1rem;
}
.footer-upper ul {
font-size: 2rem;
}
.footer-lower {
padding: 1rem;
background-color: #000080;
display: flex;
justify-content: center;
font-size: 2rem;
color: white;
}
.menu-bar {
display: none;
}
/* Media Queries */
#media (max-width: 768px) {
html {
font-size: 40%;
}
nav ul {
display: none;
}
.menu-bar i {
font-size: 2.4rem;
}
.menu-bar {
display: block;
}
/* Footer */
.footer-upper .container {
display: flex;
flex-wrap: wrap;
gap: 2rem;
}
.footer-upper .footer-links {
width: 15rem;
}
.hero-section-data p {
font-size: 3rem;
/* font-weight: 500;
line-height: 1.2; */
}
}
#media (max-width: 1024px) {
.hero-section .container {
display: flex;
/* justify-content: space-between;
place-items: center;
flex-direction: row;
padding: 3rem 1rem; */
flex-direction: column;
}
.logo {
padding-left: 2rem;
}
}
/* #media (max-width: 425px) {
.features-watch img {
margin-top: 20rem;
top: 20rem;
}
} */
#media (max-width: 1360px) {
nav ul {
padding-right: 2rem;
}
}
#media (max-width: 1305px) {
nav ul {
padding-right: 3rem;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Watch Website</title>
<link rel="StyleSheet" href="Css/Style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"
/>
<!-- Font awesome link -->
<script
src="https://kit.fontawesome.com/a2e94f730a.js"
crossorigin="anonymous"
></script>
</head>
<body>
<header>
<nav class="container">
<div class="logo">Watch</div>
<div class="menu-bar">
<i class="fa-solid fa-bars"></i>
</div>
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
<!-- menu button -->
</nav>
</header>
<main>
<section class="hero-section" id="hero">
<div class="container">
<div class="hero-section-data">
<h1>
Get your watch <br />
now!
</h1>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Error ex
ullam in, officiis modi sequi adipisci sed inventore molestias
numquam. Lorem ipsum dolor sit amet consectetur adipisicing elit.
Accusantium, ex?
</p>
<button>Order Now</button>
</div>
<div class="image">
<img src="images/smart_watch-removebg-preview.png" alt="" />
</div>
</div>
</section>
<section class="features-section" id="features">
<div class="container">
<div class="features-content">
<h2>Presenting</h2>
<h3>Apple Watch Series 9</h3>
<h5>
Presenting to you the most luxurious watch of the world with
unlimited features, which makes you'r life more easier.Available
in different colors- Features and much more. You can Detects if
you’ve been in a severe car crash, automatically connects you to
emergency services, and notifies your emergency contacts.
</h5>
<button>Visit More</button>
<div class="features-watch">
<img src="images/features watch.png" alt="" />
</div>
</div>
</div>
</section>
<section class="comfortable" id="comfortable">
<div class="container">
<h3>
Makes Your Life More Comfortable And Get Acess To The Wonderfull
Features
</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe earum
ipsum facilis nemo excepturi quaerat blanditiis fugiat atque, eius
quia libero nulla quis repellat, pariatur distinctio illo explicabo
totam dolores.
</p>
<button class="read-more">Read More</button>
<img src="images/threewatch.png" alt="" />
</div>
</section>
<section class="fitness" id="connect">
<div class="container">
<h3>Get your watch today!</h3>
<p>
Connectivity on your terms. The ultimate wearables experience.<br />
Always connected… and it’s beautiful.It’s time to step up your style
with a smartwatch that looks great with every outfit.
</p>
</div>
</section>
<section class="stock-section container" id="fitness">
<div class="stock-img">
<img src="images/stock.png" alt="" />
</div>
<div class="stock-content">
<h3>In Stock!</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Numquam<br />
accusantium temporibus pariatur ab nemo,Lorem ipsum dolor, sit amet
consectetur adipisicing elit. Dolorem, debitis. Blanditiis libero ad
animi nam dolorem provident suscipit labore eligendi.
</p>
<p>
If you have any query about the "Apple Watch Series" so you can
contact our team.
</p>
<hr />
<button class="last-btn">Buy Now</button>
</div>
</section>
</main>
<footer>
<section class="footer-upper">
<div class="container">
<div class="footer-links">
<h4>Shop & Learn</h4>
<ul>
<li>Features</li>
<li>Pricing</li>
<li>Info</li>
<li>Apps</li>
<li>Connection</li>
</ul>
</div>
<div class="footer-links">
<h4>Our Branches</h4>
<ul>
<li>Pakistan</li>
<li>India</li>
<li>Usa</li>
<li>Nepal</li>
<li>Bangladesh</li>
</ul>
</div>
<div class="footer-links">
<h4>Why us?</h4>
<ul>
<li>Genuine Products</li>
<li>Accuracy</li>
<li>Discounts</li>
<li>Delivery</li>
<li>Gift Cards</li>
</ul>
</div>
<div class="footer-links">
<h4>Brands</h4>
<ul>
<li>Apple</li>
<li>Mi</li>
<li>Samsung</li>
<li>Huawei</li>
<li>Honor</li>
</ul>
</div>
</div>
</section>
<section class="footer-lower">
<p>All rights reserved #AnasSiddiqui 2022</p>
</section>
</footer>
</body>
</html>
My header is going up when scrolling. I have already add the position sticky. Its work fine for the desktop but when i switch on the mobile devices by clicking the inspect button when i scroll down the header goes up i am finding the answers since many days.
I want the header to go down with the scroll especially in mobile devices.
I recently started developing my own website and I require some help from people who are more advanced in CSS and HTML. I am struggling with navbar alignment. I want my middle part as in "beginning" "about me" and "statistics" to be exactly in the middle. "Objectives" and "contact" to the right, logo to the left. Main problem is that I can't figure out how to perfectly align everything so the distance between left and right remains the same, as well as the middle part of the navbar. And yes, I am trying to make the website responsive so it looks good on every device. My end goal is to make an awesome portfolio site that also showcases my skill a little. I also haven't used bootstrap but I included it in my code. Sorry for a long text, I am very new to this so it's hard for me to describe the problem. My code is also very messy so if anyone has time to correct/give feedback, I would really really appreciate that.
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/158ff5ced2.js" crossorigin="anonymous"></script>
<meta charset="UTF-8">
<title>Live like legends</title>
<link rel="stylesheet" href="./css/style.css">
<script src="javakood.js"></script>
</head>
<body>
<nav class="navbar">
<!-- <input type="checkbox" id="check">
<label for="check">
<i class="fas fa-bars"></i>
</label>
-->
<div class="logo">
<img src="./veebipilt.png" width="128" height="56">
</div>
<ul class="menu">
<li>Beginning</li>
<li>About me</li>
<li>Statistics</li>
</ul>
<ul class="menu2">
<li>Objectives</li>
<li><a class="special" href="#">Contact</a></li>
</ul>
</nav>
<! Esimene vahemik veebilehes kus on tekst ja pilt korvuti---->
<section class="home">
<div class="rida">
<div class="tekstall">
<h1>Tere tulemast minu lehele!</h1>
<p>siia tuleb veel midagi lahedat veel ei tea</p>
</div>
<div class="piltnext">
<img src="./12345.jpg" width="500" height="300">
</div>
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<section class="about">
<div class="tekstabout">
<h1><mark>Veidi</mark> minust</h1>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</body>
</html>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.navbar{
background: #cbcca3;
position: fixed;
width: 100%;
padding: 15px 0;
display: flex;
}
.home{
background: url("./sigma.gif") no-repeat center;
background-size: cover;
height: 100vh;
}
.logo {
float: left;
line-height: 70px;
margin-left: 30px;
margin-right: 20px;
}
.menu{
text-align: center;
padding: 0;
margin: 0;
justify-content: space-between;
}
.menu2{
padding: 0;
margin: 0px 30px 0px 0px;
list-style-type: none;
text-align: center;
}
.navbar .menu li{
display: inline-block;
list-style-type: none;
margin: 0px 20px 0px 20px;
}
.navbar .menu li a{
font-size: 17px;
line-height: 70px;
text-transform: uppercase;
letter-spacing: 2px;
text-shadow: -1px -1px blue;
color: blueviolet;
text-decoration: initial;
padding: 5px 5px;
border-radius: 3px;
}
.navbar .menu2 li{
display: inline-block;
margin: 0px 20px 0px 20px;
}
.navbar .menu2 li a{
font-size: 17px;
text-transform: uppercase;
line-height: 70px;
letter-spacing: 2px;
text-shadow: -1px -1px blue;
color: blueviolet;
text-decoration: initial;
padding: 5px 5px;
border-radius: 3px;
}
a.special,a:hover{
background-color: paleturquoise;
transition: .5s;
}
p{
color: floralwhite;
}
.rida{
display: flex;
align-items: center;
justify-content: space-between;
}
.tekstall{
flex-basis: auto;
min-width: 300px;
margin-left: 20px;
padding-left: 30px;
}
.piltnext{
max-width: 100%;
padding: 20px;
height: auto;
margin-top: 0px;
}
Currently I'm working in laptop so my screen isn't big. But, I made some adjustments to your code and I think it's what you want.
You just need to define the width values for everything and make sure it all works in mobile to.
Regards
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.navbar {
background: #cbcca3;
position: fixed;
width: 100%;
padding: 15px 0;
display: flex;
justify-content: space-between;
align-items: center;
}
.home {
background: url("./sigma.gif") no-repeat center;
background-size: cover;
height: 100vh;
}
.logo {
line-height: 70px;
margin-left: 30px;
margin-right: 20px;
max-width: 20px;
}
.menu {
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 0 20px;
}
.menu a {
margin: 0 5px;
font-size: 17px;
line-height: 70px;
text-transform: uppercase;
letter-spacing: 2px;
text-shadow: -1px -1px blue;
color: blueviolet;
text-decoration: initial;
padding: 5px 5px;
border-radius: 3px;
}
.menu2{
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 0 20px;
}
.menu2 a {
margin: 0 5px;
font-size: 17px;
text-transform: uppercase;
line-height: 70px;
letter-spacing: 2px;
text-shadow: -1px -1px blue;
color: blueviolet;
text-decoration: initial;
padding: 5px 5px;
}
a.special,a:hover{
background-color: paleturquoise;
transition: .5s;
}
p{
color: floralwhite;
}
.rida{
display: flex;
align-items: center;
justify-content: space-between;
}
<nav class="navbar">
<div class="logo">
<img src="./veebipilt.png" width="128" height="56">
</div>
<div class="menu">
<div>Beginning</div>
<div>About me</div>
<div>Statistics</div>
</div>
<div class="menu2">
<div>Objectives</div>
<div><a class="special" href="#">Contact</a></div>
</div>
</nav>
Welcome to stackoverflow. Your css needs some tweaking. try this (note vertical-align and line-height):
.navbar .menu li a{
font-size: 17px;
line-height: 56px;
text-transform: uppercase;
letter-spacing: 2px;
text-shadow: -1px -1px blue;
color: blueviolet;
text-decoration: initial;
padding: 5px 5px;
border-radius: 3px;
vertical-align: middle;
}
I am not entirely clear what you asking for but to create a truly centered Navbar, with variable-length left and right-aligned items, CSS Flexbox can be used. My Codepen implementation (of the original idea from Keep the middle item centered when side items have different widths) could be modified for a Navbar: https://codepen.io/sam-miller-the-flexboxer/pen/OJQoGGq?editors=1100
The centerline class and div add a central divider to check the alignment of the center div in this example.
CSS:
.centerline {
position: fixed;
top: 0;
left: 50%;
width: 10px;
height: 100%;
background: black;
transform: translateX(-50%);
opacity: 0.5;
z-index: 1
}
.parent {
display: flex;
}
.left,
.right {
background-color: red;
flex: 1 1 0%;
overflow: auto;
}
.right {
text-align: right;
}
.center {
background-color: green;
}
Html:
<div class="centerline"></div>
<div class="parent">
<div class="left">
short text.
</div>
<div class="center">
I'm in the center.
</div>
<div class="right">
Very loooooooong text.
</div>
</div>
For more ideas regarding Bootstrap see:
https://github.com/twbs/bootstrap/discussions/36486
https://github.com/twbs/bootstrap/pull/36523/commits/fca49e8ee6b4d768d0ec144fb3b73ac2c5ff3cc0
Bootstrap Navbar 4 code examples (some of the classes would have to be updated for Boostrap 5):
https://codepen.io/yesiamrocks/pen/MVOWXZ
After changing web size by zooming in or out, my buttons are overfloating and moving up/down. Idk what to do.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Rubik', sans-serif;
}
nav {
display: flex;
height: 6.250vw;
width: 100%;
background: #4D49F8;
align-items: center;
justify-content: space-between;
padding: 0vw 6.458vw 0vw 5.208vw;
}
nav ul {
display: flex;
list-style: none;
}
nav ul li {
margin-top: 0;
margin-bottom: 0;
margin-left: 0.260vw;
margin-right: 0.260vw;
}
nav ul li a {
color: #f2f2f2;
text-decoration: none;
font-size: 1.125vw;
font-weight: 700;
padding: 0.417vw 0.781vw;
border-radius: 0.104vw;
letter-spacing: 0.065vw;
border: 0.104vw solid #ffffff00;
}
.hpl-text {
position: absolute;
height: auto;
left: 6.458vw;
top: 11.979vw;
color: #FFFFFF;
font-family: Rubik;
font-style: normal;
font-weight: bold;
font-size: 3.333vw;
line-height: 3.958vw;
}
.hp-text {
position: absolute;
width: 42.240vw;
height: auto;
left: 6.458vw;
top: 17.708vw;
font-family: Rubik;
font-style: normal;
font-weight: normal;
font-size: 1.563vw;
line-height: 1.875vw;
color: #FFFFFF;
}
.add-btns {
position: absolute;
width: auto;
height: auto;
left: 1.042vw;
top: 28.125vw;
align-items: center;
justify-content: space-between;
padding: 0 6.458vw 0 5.208vw;
}
.add-btns ul {
display: flex;
list-style: none;
}
.add-btns li {
margin-top: 0vw;
margin-bottom: 0vw;
margin-left: 0.260vw;
margin-right: 1.042vw;
}
.add-btns li a {
color: #f2f2f2;
text-decoration: none;
font-size: 1.250vw;
font-weight: 700;
padding: 0.417vw 0.781vw;
border-radius: 0.104vw;
letter-spacing: 0.065vw;
border: 0.104vw solid #ffffff00;
}
#materialy-btn {
border: 0.104vw solid #FFFFFF;
}
#algorytmy-btn {
border: 0.104vw solid #ffffff00;
background: #F13CAF;
}
<nav>
<div class="logo">
<a href="index.html">
<img class="logo-sett" src="logo.png">
</a>
</div>
<ul>
<li>algorithm</li>
<li>schedule</li>
<li>resources</li>
<li>about us</li>
</ul>
</nav>
<div class="spacer layer1">
</div>
<div class="hp-container">
<h1 class="hpl-text">Lorem Ipsum</h1>
<p class="hp-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus et bibendum enim. Vestibulum vitae libero vel ipsum non turpis pulvinar suscipit. In pharetra leo eros, quis blandit turpis dictum id.</p>
<div class="add-btns">
<ul>
<li>algorithm</li>
<li>resources</li>
</ul>
</div>
<img class="unicorn" src="unicorn.png">
<img class="img-programming" src="programming.png">
<img class="img-connection" src="connection.png">
<img class="img-algorithm" src="algorithm.png">
</div>
I know that is not the best idea to put position: absolute; on every element but its my first website.
I would be very grateful if someone could help me.
The problem I see is you use top: 28.125vw for .add-btns.
vw is the unit for view width which is the width of your parent container (body here).
So by zooming in/out, the position for .add-btns will not be the same way
By change it to vh or % (precentage) will make it work.
It is the same idea for nav. Also, I don't think it is always a good idea to use vw for all css style .
My suggestion is to use px instead for things like font and line-height and use css media query
Media queries are useful when you want to modify your site or app depending on a device's general type (such as print vs. screen) or specific characteristics and parameters (such as screen resolution or browser viewport width).
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Rubik', sans-serif;
}
nav{
display: flex;
height: 6.250vw;
width: 100%;
background: #4D49F8;
align-items: center;
justify-content: space-between;
padding: 0vw 6.458vw 0vw 5.208vw;
}
nav ul{
display: flex;
list-style: none;
}
nav ul li{
margin-top: 0;
margin-bottom: 0;
margin-left: 0.260vw;
margin-right: 0.260vw;
}
nav ul li a{
color: #f2f2f2;
text-decoration: none;
font-size: 1.125vw;
font-weight: 700;
padding: 0.417vw 0.781vw;
border-radius: 0.104vw;
letter-spacing: 0.065vw;
border: 0.104vw solid #ffffff00;
}
.hpl-text{
position: absolute;
height: auto;
left: 6.458vw;
top: 11.979vw;
color: #FFFFFF;
font-family: Rubik;
font-style: normal;
font-weight: bold;
font-size: 3.333vw;
line-height: 3.958vw;
}
.hp-text{
position: absolute;
width: 42.240vw;
height: auto;
left: 6.458vw;
top: 17.708vw;
font-family: Rubik;
font-style: normal;
font-weight: normal;
font-size: 1.563vw;
line-height: 1.875vw;
color: #FFFFFF;
}
.add-btns{
position: absolute;
width: auto;
height: auto;
left: 1.042vw;
top: 28.125vh;
align-items: center;
justify-content: space-between;
padding: 0 6.458vw 0 5.208vw;
}
.add-btns ul{
display: flex;
list-style: none;
}
.add-btns li{
margin-top: 0vw;
margin-bottom: 0vw;
margin-left: 0.260vw;
margin-right: 1.042vw;
}
.add-btns li a{
color: #f2f2f2;
text-decoration: none;
font-size: 1.250vw;
font-weight: 700;
padding: 0.417vw 0.781vw;
border-radius: 0.104vw;
letter-spacing: 0.065vw;
border: 0.104vw solid #ffffff00;
}
#materialy-btn{
border: 0.104vw solid #FFFFFF;
}
#algorytmy-btn{
border: 0.104vw solid #ffffff00;
background: #F13CAF;
}
<nav>
<div class="logo">
<a href="index.html">
<img class="logo-sett" src="logo.png">
</a>
</div>
<ul>
<li>algorithm</li>
<li>schedule</li>
<li>resources</li>
<li>about us</li>
</ul>
</nav>
<div class="spacer layer1">
</div>
<div class="hp-container">
<h1 class="hpl-text">Lorem Ipsum</h1>
<p class="hp-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus et bibendum enim.
Vestibulum vitae libero vel ipsum non turpis pulvinar suscipit.
In pharetra leo eros, quis blandit turpis dictum id.</p>
<div class="add-btns">
<ul>
<li>algorithm</li>
<li>resources</li>
</ul>
</div>
<img class ="unicorn" src="unicorn.png">
<img class ="img-programming" src="programming.png">
<img class ="img-connection" src="connection.png">
<img class ="img-algorithm" src="algorithm.png">
</div>
I'm really struggling here trying to figure out what is going on. I have an HTML with a header, a sidebar, and a central content page.
The sidebar and central content are in the same div, which also acts as their clearfix. I floated the sidebar to the left and the content to the right, but instead of aligning themselves to each other neatly, the content div falls down.
HTML
<body>
<header>
<img src="./img/Logo_Color.png" alt="Logo">
<h1>Batch Documentation</h1>
</header>
<div class="clearfix">
<div class="sidebar">
<nav>
<ul>
<li>Overview</li>
<li>Fl Overview</li>
<li>PF2 Overview</li>
<li>Inputs</li>
<li>Outputs</li>
<li>Appendix A</li>
<li>Appendix B</li>
</ul>
</nav>
</div>
<main>
<div class="centerContent">
<h2>Overview</h2>
<p>
Integer in qui primam te ipsa-plenus Crescere Effectum Septembrem. Me quo 700% octavas ad imperium caduca si eros eius orci arcu te mirum consumere, meritos modo diam eros ti, in cras diuturna interpres, semente, securitas sem odio dignitatis reuiescat.
Lius quam charybdium nonullis sem inibunt illum, civibus eius arendom, Indolem te e licentiose te maiestatem molestias typi combinatur sagittis successus nomine, reniam eos te-feroces assueverunt.
Saepe non, Fervore 2000 galliae nibh eu ea ut:
</p>
<code>Hello</code>
</div>
</main>
</div>
</body>
CSS
* {
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
margin: 0;
padding: 0;
list-style-type: none;
}
body {
margin: auto;
width: 1265px;
background-color: #eae0ff;
}
main {
display: inline-block
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
header {
margin: 15px 10px 20px 10px;
}
.sidebar {
width: 25%;
margin: 5px 0px 10px 10px;
padding-right: 20px;
float: left;
background-color: #ccccff;
}
.centerContent {
width: 75%;
margin: auto;
padding-left: 20px;
border: 3px solid #73ad21;
float: right;
}
li {
margin-top: 5px;
margin-bottom: 5px;
}
code {
width: 90%;
font-family: 'Source Code Pro', monospace;
color: #43892a;
background-color: #000;
display: block;
}
I am especially concerned because the box sizing is set to border box, and the display is inline block. The sidebar has 25% width whereas the main content has 75%, yet it seems that the margins and padding are being added to their dimensions rather than being included in the % calculation.
I Dont know why you using floats now, i attached a same with small flexbox layout. hope it helps.
* {
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
margin: 0;
padding: 0;
list-style-type: none;
}
body {
margin: auto;
background-color: #eae0ff;
}
main {
display: inline-block
}
.clearfix{
display:flex;
}
header {
margin: 15px 10px 20px 10px;
}
.sidebar {
width: 25%;
margin: 0px 0px 10px 10px;
padding-right: 20px;
background-color: #ccccff;
flex: 0 0 auto;
}
.centerContent {
width: 75%;
margin: auto;
padding-left: 20px;
border: 3px solid #73ad21;
}
li {
margin-top: 5px;
margin-bottom: 5px;
}
code {
width: 90%;
font-family: 'Source Code Pro', monospace;
color: #43892a;
background-color: #000;
display: block;
}
<body>
<header>
<img src="./img/Logo_Color.png" alt="Logo">
<h1>Batch Documentation</h1>
</header>
<div class="clearfix">
<div class="sidebar">
<nav>
<ul>
<li>Overview</li>
<li>Fl Overview</li>
<li>PF2 Overview</li>
<li>Inputs</li>
<li>Outputs</li>
<li>Appendix A</li>
<li>Appendix B</li>
</ul>
</nav>
</div>
<main>
<div class="centerContent">
<h2>Overview</h2>
<p>
Integer in qui primam te ipsa-plenus Crescere Effectum Septembrem. Me quo 700% octavas ad imperium caduca si eros eius orci arcu te mirum consumere, meritos modo diam eros ti, in cras diuturna interpres, semente, securitas sem odio dignitatis reuiescat.
Lius quam charybdium nonullis sem inibunt illum, civibus eius arendom, Indolem te e licentiose te maiestatem molestias typi combinatur sagittis successus nomine, reniam eos te-feroces assueverunt. Saepe non, Fervore 2000 galliae nibh eu ea ut:
</p>
<code>Hello</code>
</div>
</main>
</div>
</body>
Better to use flex layout, it is going to be responsive and never creates problems.
CSS:
* {
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
margin: 0;
padding: 0;
list-style-type: none;
}
body {
margin: auto;
width: 96vw;
background-color: #eae0ff;
}
main {
width: 70%;
margin: auto;
}
.clearfix {
display: flex;
justify-content: space-between;
flex-direction: row;
margin: 0 20px;
}
header {
margin: 15px 10px 20px 10px;
}
.sidebar {
width: 25%;
background-color: #ccccff;
}
.centerContent {
border: 3px solid #73ad21;
}
li {
margin-top: 5px;
margin-bottom: 5px;
}
code {
font-family: 'Source Code Pro', monospace;
color: #43892a;
background-color: #000;
display: block;
}
I think you have just started learning HTML , CSS.
So whenever you give margins and padding (especially left and right) count each pixels else you'll face such problems like you are facing now.
In future you will learn grid and flexbox in css.
When you use both (grid & flexbox) then I bet you will never use float property.
As you are beginner, you can easily understand my solution -
So in your css you have to remove -
main{
display:inline-block;
}
and add this -
.centerContent {
display: inline-block;
width: 70%; // play by changing the width.
margin: auto;
padding-left: 20px;
border: 3px solid #73ad21;
float: right; // float : left; will also work
}
The margin are not included in the width for the box-sizing: border-box butpaddings and borders are included.
https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
So the margin remains external to side bar and the second content is moving down. You can remove margin to move the content back.
This question already has answers here:
What is a clearfix?
(10 answers)
What methods of ‘clearfix’ can I use?
(29 answers)
Closed 3 years ago.
I'm working on a simple template for a web page. On a large screen, my page looks like this:
![1] https://imgur.com/a/M6ARRoJ
On a small screen it looks like this:
![2] https://imgur.com/a/6kLOSEI
And, as I show in the image, the background of the footer disappears.
Here are my HTML and CSS codes:
body {
background-color: #bccedc;
}
#content {
width: 800px;
margin-left: auto;
margin-right: auto;
}
/* === HEADER === */
#header {
height: 50px;
background-color: #99ccff;
}
#header h1 {
text-align: center;
margin: auto;
padding-top: 10px;
font-size: 25px;
color: #3a3a3a;
text-transform: uppercase;
font-family: 'Century Gothic', 'Futura', sans-serif;
}
#middle {
display: flex;
/* Align sidebar with main */
}
/* === SIDEMENU === */
#sidebar {
float: left;
width: 20%;
background-color: #00cc00;
font-family: 'Century Gothic', 'Futura', sans-serif;
}
#sidebar ul {
list-style-type: none;
margin-left: auto;
margin-right: auto;
}
#sidebar li {
margin-top: 10px;
}
#sidebar a:link,
a:visited {
text-decoration: none;
color: #12366d;
}
#sidebar a:hover {
color: white;
}
#sidebar a:active {
color: yellow;
}
/* === MAIN === */
#main {
min-height: 500px;
float: left;
width: 85%;
background-color: #ffff99;
}
#main h2 {
text-align: center;
font-family: 'Century Gothic', 'Futura', sans-serif;
color: #373737;
}
#main h3 {
font-family: 'Century Gothic', 'Futura', sans-serif;
padding-left: 20px;
font-size: 14px;
text-transform: uppercase;
text-decoration: underline;
}
#main p {
text-align: justify;
margin: 20px;
font-family: 'Calibri', 'Arial', sans-serif;
}
#main ul {
padding-left: 70px;
list-style-image: url(bullet.png);
}
#main ol {
padding-left: 70px;
}
#main dt {
font-family: 'Calibri', 'Arial', sans-serif;
text-align: justify;
font-weight: bold;
padding-left: 40px;
}
#main li,
dd {
font-family: 'Calibri', 'Arial', sans-serif;
text-align: justify;
margin-right: 30px;
}
#main table,
th,
td {
border: 2px solid #003e80;
border-collapse: collapse;
height: 40px;
}
#main table {
text-align: center;
vertical-align: middle;
margin-left: auto;
margin-right: auto;
width: 550px;
font-family: 'Calibri', 'Arial', sans-serif;
caption-side: bottom;
}
#main th {
background-color: #99ccff;
font-size: 20px;
color: #e6f2ff;
}
#main td {
background-color: #e6f2ff;
}
#main td:hover {
background-color: white;
}
#main caption {
font-style: italic;
color: #003e80;
}
/* === FOOTER === */
#footer {
height: 30px;
padding-top: 20px;
background-color: #99ccff;
}
#footer>p {
margin: auto;
text-align: center;
font-family: 'Century Gothic', 'Futura', sans-serif;
font-size: 14px;
}
/* === RESPONSIVE === */
#media only screen and (max-width: 850px) {
#content {
width: 600px;
}
#sidebar {
width: 25%;
}
#main table {
width: 400px;
}
}
#media only screen and (max-width: 650px) {
#content {
width: 450px;
}
#middle {
display: initial;
}
#sidebar {
display: flex;
justify-content: center;
width: 100%;
}
#sidebar ul {
margin-left: 30px;
}
#sidebar li {
float: left;
margin: 10px;
}
#main {
width: 100%;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="content">
<div id="header">
<h1>title</h1>
</div>
<div id="middle">
<div id="sidebar">
<ul>
<li>Home</li>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</div>
<div id="main">
<h2>Main body</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
<div id="footer">
<p>Footer is here</p>
</div>
</div>
</body>
</html>
I searched on the Internet for a solution but nothing helped me.
Can someone please tell me what exactly is the problem and how do I solve it?
That's because your #main element is floated. That way the position of the footer itself "officially" is right under the header, since floated elements are not wrapped by their parent elements by default. (check in the browser tools)
Add clear: both; to the footer's CSS to fix that:
body {
background-color: #bccedc;
}
#content {
width: 800px;
margin-left: auto;
margin-right: auto;
}
/* === HEADER === */
#header {
height: 50px;
background-color: #99ccff;
}
#header h1 {
text-align: center;
margin: auto;
padding-top: 10px;
font-size: 25px;
color: #3a3a3a;
text-transform: uppercase;
font-family: 'Century Gothic', 'Futura', sans-serif;
}
#middle {
display: flex;
/* Align sidebar with main */
}
/* === SIDEMENU === */
#sidebar {
float: left;
width: 20%;
background-color: #00cc00;
font-family: 'Century Gothic', 'Futura', sans-serif;
}
#sidebar ul {
list-style-type: none;
margin-left: auto;
margin-right: auto;
}
#sidebar li {
margin-top: 10px;
}
#sidebar a:link,
a:visited {
text-decoration: none;
color: #12366d;
}
#sidebar a:hover {
color: white;
}
#sidebar a:active {
color: yellow;
}
/* === MAIN === */
#main {
min-height: 500px;
float: left;
width: 85%;
background-color: #ffff99;
}
#main h2 {
text-align: center;
font-family: 'Century Gothic', 'Futura', sans-serif;
color: #373737;
}
#main h3 {
font-family: 'Century Gothic', 'Futura', sans-serif;
padding-left: 20px;
font-size: 14px;
text-transform: uppercase;
text-decoration: underline;
}
#main p {
text-align: justify;
margin: 20px;
font-family: 'Calibri', 'Arial', sans-serif;
}
#main ul {
padding-left: 70px;
list-style-image: url(bullet.png);
}
#main ol {
padding-left: 70px;
}
#main dt {
font-family: 'Calibri', 'Arial', sans-serif;
text-align: justify;
font-weight: bold;
padding-left: 40px;
}
#main li,
dd {
font-family: 'Calibri', 'Arial', sans-serif;
text-align: justify;
margin-right: 30px;
}
#main table,
th,
td {
border: 2px solid #003e80;
border-collapse: collapse;
height: 40px;
}
#main table {
text-align: center;
vertical-align: middle;
margin-left: auto;
margin-right: auto;
width: 550px;
font-family: 'Calibri', 'Arial', sans-serif;
caption-side: bottom;
}
#main th {
background-color: #99ccff;
font-size: 20px;
color: #e6f2ff;
}
#main td {
background-color: #e6f2ff;
}
#main td:hover {
background-color: white;
}
#main caption {
font-style: italic;
color: #003e80;
}
/* === FOOTER === */
#footer {
height: 30px;
padding-top: 20px;
background-color: #99ccff;
clear: both;
}
#footer>p {
margin: auto;
text-align: center;
font-family: 'Century Gothic', 'Futura', sans-serif;
font-size: 14px;
}
/* === RESPONSIVE === */
#media only screen and (max-width: 850px) {
#content {
width: 600px;
}
#sidebar {
width: 25%;
}
#main table {
width: 400px;
}
}
#media only screen and (max-width: 650px) {
#content {
width: 450px;
}
#middle {
display: initial;
}
#sidebar {
display: flex;
justify-content: center;
width: 100%;
}
#sidebar ul {
margin-left: 30px;
}
#sidebar li {
float: left;
margin: 10px;
}
#main {
width: 100%;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="content">
<div id="header">
<h1>title</h1>
</div>
<div id="middle">
<div id="sidebar">
<ul>
<li>Home</li>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</div>
<div id="main">
<h2>Main body</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
<div id="footer">
<p>Footer is here</p>
</div>
</div>
</body>
</html>