Css parallax doesn't work - css

Hey guys I'm following the W3S tutorials and I want to archive the parallax effect. I've tried many times and I don't know why the picture doesn't show.
I did the exact same thing on another project and it worked just fine. I really don't know what I did wrong. My reputation it's kinda bad here because of my "stupid questions", so I'm sorry if this question offend someone.
Have a look at my code:
* {
margin: 0;
padding: 0;
}
body {
margin: 0;
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
font-size: 19px;
line-height: 1.6;
}
#showcase {
background-image: url('https://picsum.photos/g/1900/1080?random');
height: 100vh;
background-position: center;
background-size: cover;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: top;
}
.button {
background-color: black;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 8px;
}
.Bshadow:hover {
box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
}
.pacifont {
font-family: 'Pacifico', cursive;
font-size: 4.8rem;
color: white;
}
.name {
color: #008c06;
}
.topnav {
overflow: hidden;
/* background-color: #333; */
border-bottom: 3px solid #008c06;
}
.sticky {
position: fixed;
top: 0;
width: 100%
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.active {
background-color: #008c06;
color: white;
}
.topnav .icon {
display: none;
}
#media screen and (max-width: 600px) {
.topnav a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
#media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
.parallax {
/* The image used */
background-image: url("https://picsum.photos/500/1081/?random'");
/* Full height */
height: 100%;
width: 100%;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
<header id="showcase">
<div class="topnav sticky" id="myTopnav">
Home
News
Contact
About
☰
</div>
<h1 class="pacifont">Welcome <a class="name">Felix!</a></h1>
READY?
</header>
<a class="weatherwidget-io" href="https://forecast7.com/en/50d854d35/brussels/" data-label_1="Bruxelles" data-font="Jura" data-icons="Climacons Animated" data-days="3" data-theme="gray">Bruxelles</a>
<h1>wtf</h1>
<div class="parallax"></div>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus odit dolorum sed ut, doloremque consectetur.</p>

Change the height of .parallax class to 100vh instead of 100%.

Related

CSS Background rectangle width won't extend to full device width

I am trying to make a homepage for my portfolio website with a responsive css background rectangle and a side-by-side hero with text on the left and an image on the right, such as the website template here. I can't figure out what I did wrong in my HTML or CSS that's making it so that the background css rectangle isn't extending the full width of the screen. I'm new at this, so I would appreciate the help.
#charset "utf-8";
/* CSS Document */
#import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght#500&display=swap');
/*Variable*/
:root {
--primary-color: #0d081a;
--secondary-blue: #eaf0f9;
--secondary-gray: #48463b;
--body-bg: ffffff;
}
/*Global Styles*/
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
scroll-behavior: smooth;
}
body {
background-color: var(--body-bg);
font-family: Arial, Helvetica, sans-serif;
line-height: 1.6;
margin: 0;
min-height: 100vh;
}
img {
width: 100%;
height: 100%;
}
a {
color: black;
text-decoration: none;
}
section {
display: flex;
align-items: center;
justify-content: center;
}
.background {
border: 0;
padding: 0;
width: max-content;
background-color: var(--secondary-blue);
}
.container {
width: 90%;
height: 100%;
margin: 0 auto;
}
.primary-btn {
display: inline-block;
background-color: var(--primary-color);
color: white;
font-size: 1.8rem;
padding: 0.6em 1.6em;
border-radius: 50px;
}
.buttons {
margin-top: 3rem;
display: flex;
align-items: center;
justify-content: flex-start;
gap: 2rem;
}
/*nav*/
#navigation {
position: fixed;
right: 50px;
height: auto;
top: 20px;
z-index: 100;
}
/*hero section*/
#hero {
height: 100vh;
width: 100%;
padding-top: 10rem;
}
#hero .container {
display: flex;
align-items: center;
justify-content: center;
}
#hero .container .left {
flex: 6;
}
#hero .container .right {
flex: 8;
}
#hero .left .subheading {
font-size: 1.8rem;
font-weight: 500;
text-transform: uppercase;
color: var(--primary-color);
}
#hero .left .heading {
font-size: 6rem;
font-family: 'Times New Roman', Times, serif;
font-weight: 600;
}
#hero .left .desc {
margin-top: 2.5rem;
max-width: 400px;
font-size: 1.5 rem;
color: var(--secondary-blue);
}
#hero .right {
text-align: right;
}
#hero .right img {
width: 100%;
max-width: 450px;
height: 600px;
object-fit: cover;
object-position: 50% 30%;
border-radius: 12px;
}
#media only screen and (max-width: 768px) {
html {
font-size: 9px;
}
#hero .container {
flex-direction: column-reverse;
}
#hero .container .right {
text-align: center;
flex: 1;
margin-bottom: 2rem;
}
#hero .container .left {
text-align: center;
padding-right: 0;
flex: 1;
height: fit-content;
}
#hero .left .buttons {
justify-content: center;
}
#hero .left .heading {
font-size: 4rem;
margin: 0 auto;
}
#hero .container .left .desc {
margin: 0 auto;
margin-top: 2rem;
}
#hero .right img {
width: 100%;
height: 400px;
}
}
#media only screen and (max-width: 1200px) {
#hero .container .right {
flex: 6;
}
}
/* End Hero Section*/
/*Navbar*/
ul {
margin: 0;
padding: 0;
list-style: none;
}
a {
text-decoration: none;
}
.main-nav {
margin-top: 5px;
}
.logo a,
.main-nav a {
padding: 10px 15px;
text-transform: uppercase;
text-align: center;
display: block;
}
.main-nav a {
color: #34495e;
font-size: 1.5em;
}
.main-nav a:hover {
color: #718daa;
}
.header {
padding-top: 1em;
padding-bottom: 1em;
}
/* Nav Media Queries*/
#media (min-width: 769px) {
.header,
.main-nav {
display: flex;
}
.header {
flex-direction: column;
align-items: flex-end;
.header {
width: 80%;
margin: 0 auto;
max-width: 1150px;
}
}
}
#media (min-width: 1025px) {
.header {
flex-direction: row;
justify-content: flex-end;
}
}
<body>
<!--nav section-->
<header class="nav">
<ul class="main-nav">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</header>
<!--end nav section-->
<!--hero section-->
<section id="hero">
<div class="background">
<div class="container">
<div class="left">
<p class="subheading"></p>
<h2 class="heading">
<div class="wrapper"><span>Hello, nice </span></div>
<div class="wrapper"><span>to"meet" you!</span></div>
</h2>
<p class="desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<div class="buttons">
Contact Me
</div>
</div>
<div class="right">
<img src="/linkedinheadshot.png" alt="picture">
</div>
</div>
</div>
</section>
<!--End hero section-->
</body>
I've tried adjusting the padding and margins and the widths in the #mediaquery. Researching solutions on google and stack overflow.
i review your problem and if you use
#hero {
min-width: 100vw;
display: block;
background-color: var(--secondary-blue);
}
html #hero .container {
display: flex;
justify-content: space-between;
}
it will solve you problem
i am also a new web developer and learning now javascript
if it help you like this if you had still any problem post your question

White space on the right side of the page below 400px device screen width. How to make it disappear?

I have two big problems:
The first trouble I have encountered is that when I am testing the responsivity of my website in the contact section I always meet a reappearing problem: There is a white space (.2 rem - 1.2rem width) on the right side of the body when I try to display the whole page under 400px width device.
My second problem is that I have social media icons in the footer. They appear properly in all other sections (multipage website), but only here does something prevent them to be displayed properly. I tried resizing their main divs to 100% width and 100% max-width, but an element is probably still longer than the others, which should obviously cause this kind of problem.
So about the white blank area, I think it is important to know that I have a specially styled scrollbar, which might also cause this little mischief. I am unsure, so I have also tried removing it, but it did not help. In the beginning, I also encountered the same problem with the footer, but somehow I managed to get by and was able to solve it by correcting the width of the .footer-container. Since then the white space appeared and my second problem with social media icons not being displayed properly just arose.
Here is my code:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="contacts.css">
<title>Eckert Művek Galéria</title>
</head>
<body>
<div class="floating-btn show-btn" aria-label="up button" role="button">
<img src="assets/svg_files/chevron-up-solid.svg" alt="up img" />
</div>
<header>
<!--NAVBAR-->
<nav>
<ul class="menu" id="desktop-menu">
<li class="nav-item">Főoldal</li>
<li class="nav-item">Rólunk</li>
<li class="nav-item">Szolgáltatások</li>
<li class="nav-item">Miért mi?</li>
<li class="nav-item">Galéria</li>
<li class="nav-item">Kapcsolat</li>
</ul>
<!--HAMBURGER ICON-->
<div class="header-right-gap">
<button class="hamburger" aria-label="hamburger button">
<div class="line line-1"></div>
<div class="line line-2"></div>
<div class="line line-3"></div>
</button>
</div>
</nav>
<!--MOBILE MENU-->
<div class="mobile-menu">
<ul class="m-menu">
<li class="nav-item">Főoldal</li>
<li class="nav-item">Rólunk</li>
<li class="nav-item">Szolgáltatások</li>
<li class="nav-item">Miért mi?</li>
<li class="nav-item">Galéria</li>
<li class="nav-item">Kapcsolat</li>
</ul>
</div>
</header>
<main>
<!--CONTACT FORM-->
<div class="container">
<form>
<h1>Kapcsolat</h1>
<input type="text" id="firstName" placeholder="Családnév" required>
<input type="text" id="lastName" placeholder="Keresztnév" required>
<input type="email" id="email" placeholder="Email" required>
<input type="text" id="mobile" placeholder="Telefonszám" required>
<h4 class="contactus">Lépjen velünk kapcsolatba!</h4>
<textarea id="texti" required></textarea>
<input type="submit" value="Elküldés" id="button">
</form>
</div>
</main>
<footer>
<div class="footer-container">
<!--COMPANY INFORMATION, CONTATCTS-->
<div class="footer-top">
<div>
<article>
<h2>Elérhetőségeink</h2>
<div class="cellphone">
<img src="assets/png/telephone.png" alt="phone-icon">
<h3><span>Telefonszám:</span> +36709424298</h3>
</div>
<div class="internet">
<img src="assets/png/mail.png" alt="email-icon">
<h3><span>E-mail:</span> eckertmuvek#gmail.com</h3>
</div>
<div class="headquarter">
<img src="assets/png/location.png" alt="company-icon">
<h3><span>Telephely:</span> Budapest, 1182 Török Bálint u. 16/b</h3>
</div>
<div class="opening-hours">
<img src="assets/png/clock.png" alt="op-icon">
<h3><span>Nyitvatartási idő:</span> hétfő - péntek(7:00 - 17:30)</h3>
</div>
</article>
</div>
<!--TEXT-->
<div class="text-container">
<h4>Céginformációk</h4>
<p>
<ol>
<li>
<h5>Cégjegyzékszám: </h5>
<p> 01 09 996342</p>
</li>
<li>
<h5>Adószám: </h5>
<p>24222716243</p>
</li>
<li>
<h5>Számlaszám: </h5>
<p>112131423-43242142-432412421</p>
</li>
<li>
<h5>Cégnév: </h5>
<p>Eckert Művek Korlátolt Felelősségű Társaság</p>
</li>
</ol>
</p>
</div>
<!--
<div class="text-container">
<h4>Ttitle-1</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
Dicta modi laborum quibusdam quis natus debitis qui dolor
voluptatibus ab sit, cum saepe enim unde doloribus veniam
numquam perspiciatis optio impedit.</p>
</div>
-->
<!--POLICIES-->
<div class="policies">
Impresszum
GDPR Tájékoztató
Süti Tájékoztató
</div>
</div>
<!--MAP-->
<div class="map">
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2699.366130757782!2d19.217992451587673!3d47.42430370844346!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x4741c1f21fa88e89%3A0x44673b68b84b51c9!2zQnVkYXBlc3QsIFTDtnLDtmsgQsOhbGludCB1LiAxNmIsIDExODI!5e0!3m2!1shu!2shu!4v1672662477180!5m2!1shu!2shu"
height="400" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
</div>
<!--SOCIAL MEDIA ICONS-->
<div class="social-media-icons">
<div class="sm-container" id="insta">
<div class="sm-icon">
</div>
</div>
<div class="sm-container" id="github">
<div class="sm-icon">
</div>
</div>
<div class="sm-container" id="facebook">
<div class="sm-icon">
</div>
</div>
<div class="sm-container" id="linkedin">
<div class="sm-icon">
</div>
</div>
</div>
<div class="footer-bottom">
<p>© Eckert Művek Kft. Minden jog fenntartva.</p>
</div>
</div>
</footer>
<script src="contacts.js"></script>
</body>
</html>
And here is my CSS code:
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#100;200;300;400;500;600;700;800;900&display=swap');
:root {
--nav-height: 100px; /*80%*/
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
html {
scroll-behavior: smooth;
}
body {
min-height: 100vh;
width: 100%;
font-size: 12px;
font-family: sans-serif;
}
.floating-btn {
position: fixed;
bottom: 3.5vh;
right: 0;
width: 50px;
height: 50px;
z-index: 100;
background-color: yellow;
border-radius: 50%;
padding: 10px;
box-shadow: 0 0 5px hsla(0, 0%, 0%, hsla(0,0%,0%,0.5));
cursor: pointer;
margin-right: 1rem;
border: 1px solid #000;
}
.show-btn {
display: block;
}
header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100px;
z-index: 100;
background-color: #000;
}
/*Srcollbar*/
::-webkit-scrollbar{
width: 15px;
background: #000;
}
::-webkit-scrollbar-thumb {
background: yellow;
border-radius: 10px;
border: 1px solid black;
}
::-webkit-scrollbar-thumb:active {
background: orangered;
}
nav {
display: flex;
width: min(90%, 1200px);
height: inherit;
align-items: center;
justify-content: flex-start;
margin-inline: unset;
display: flex;
justify-content: flex-start;
align-items: center;
font-size: 20px;
left: 2.5rem;
gap: 1rem;
/*margin-top: -2.5rem;*/
}
nav a {
max-height: var(--nav-height);
align-items: center;
margin-inline: auto;
font-size: 20px;
position: relative;
height: 100%;
}
nav ul {
display: flex;
gap: 1rem;
width: 100%;
list-style: none;
margin-top: 3rem;
}
.nav-item a {
color: white;
text-transform: uppercase;
text-decoration: none;
font-weight: bold;
font-size: 20px;
height: 100%;
margin: .5em .8em;
padding: 10px;
}
.nav-item a::before,
.nav-item a::after {
content: '';
height: 14px;
width: 14px;
position: absolute;
transition: all .35s ease;
opacity: 0;
}
nav a::before {
content: '';
right: 0;
top: 0;
border-top: 3px solid #ffed4b;
border-right: 3px solid #fdcd3b;
transform: translate(-100%, 50%); /*-100%, 50%*/
}
.nav-item a:after {
content: '';
left: 0;
bottom: 0;
border-bottom: 3px solid #fdcd3b;
border-left: 3px solid #ffed4b;
transform: translate(100%, -50%); /*100%, -50%*/
}
.nav-item a:hover:before,
.nav-item a:hover:after{
transform: translate(0,0);
opacity: 1;
}
.nav-item a:hover {
text-decoration: underline;
color:yellow;
}
.container{
min-height: 100vh;
width: 99.vw;
background: #08071d;
display: flex;
justify-content: center;
align-items: center;
background: url("assets/images/mainpage/106811484-1608045351058-gettyimages-1126750618-dsc_1540.jpeg") no-repeat center center/cover;
}
.container form{
width: 670px; /*670px*/
height: 450px;
display: flex;
justify-content: center;
box-shadow: 20px 20px 50px rgba(0,0,0,0.5);
border-radius: 15px;
background: rgba(255,255,255,0.1);
backdrop-filter: blur(10px);
flex-wrap: wrap;
overflow-x: hidden;
}
.container form h1{
color: #fff;
font-weight: 500;
margin-top: 20px;
width: 500px;
text-align: center;
}
.container form input{
width: 290px;
height: 40px;
padding-left: 10px;
outline: none;
border: none;
font-size: 25px;
margin-bottom: 10px;
background: none;
border-bottom: 2px solid #fff;
}
.container form input::placeholder{
color: #ddd;
}
.container form #lastName,
.container form #mobile{
margin-left: 20px;
}
.container form h4{
color: #fff;
font-weight: 300;
width: 600px;
margin-top: 20px;
}
.container form textarea{
background: none;
border: none;
border-bottom: 2px solid #fff;
color: #fff;
font-weight: 200;
font-size: 25px;
padding: 10px;
outline: none;
min-width: 600px;
max-width: 600px;
min-height: 80px;
max-height: 80px;
}
.contactus {
font-size: 18px;
}
input[type="text"]:focus, input[type="email"]:focus, #texti:focus {
border-bottom: 3px solid #fdcd3b;
}
textarea::-webkit-scrollbar{
width: 1em;
}
textarea::-webkit-scrollbar-thumb{
background-color: rgba(194,194,194,0.713);
}
.container form #button{
border: 1px solid;
background: transparent;
border-radius: 50px;
margin-top: 20px;
font-weight: 600;
font-size: 20px;
color: #fff;
width: 100px;
padding: 0;
margin-right: 500px;
margin-bottom: 30px;
transition: 0.3s;
}
.container form #button:hover{
opacity: 0.9;
transform: scale(1.2);
background-color: black;
color: yellow;
}
/*FOOTER*/
footer {
width: 100%;
background-color: #000;
padding-block: 4rem;
color: white;
}
.footer-container {
display: flex;
flex-direction: column;
justify-content: space-between;
margin-inline: auto;
width: min(90%, 1200px);
}
.footer-top {
width: 100%;
height: 100%;
color: #fff;
font-size: 10px;
display: flex;
justify-content: space-around;
}
.footer-top h2 {
text-align: center;
justify-content: center;
align-items: center;
}
.footer-top article div {
line-height: 2.5rem;
}
.footer-top article div:first-of-type {
margin-top: 1rem;
}
.footer-top img {
height: 64px;
}
.text-container p {
margin-top: 2rem;
}
.text-container ol li {
line-height: 1.5rem;
}
/*CONTACT ICONS*/
.cellphone img, .internet img, .headquarter img, .opening-hours img{
background-color: yellow;
border-radius: 50px;
transition: all 0.3s linear;
}
footer img:hover {
background-color: orangered;
border-radius: 40px;
transform: rotate(-360deg);
}
.footer-bottom {
text-align: center;
margin-top: 2rem;
}
span {
color: yellow;
}
.text-container {
justify-content: space-between;
width: 20vw;;
font-size: 0.8rem;
}
/*POLICIES LINKS*/
.policies {
display: flex;
flex-direction: column;
font-size: 14px;
text-transform: uppercase;
}
.policies a {
color: yellow;
font-size: 10px;
line-height: 2rem;
}
.policies a:hover {
color: orangered;
}
/*MAP*/
.map {
margin-inline: auto;
}
/*SOCIAL MEDIA ICONS*/
.social-media-icons {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.sm-container {
display: flex;
justify-content: center;
gap: 2rem;
padding:1rem;
border: 1px black;
width: 100%;
height: 100%;
}
.sm-container a:active {
color: yellow;
}
.fa {
border-radius: 50%;
width: 100%;
height: 100%;
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
font-size: 30px;
/**/
}
.fa-instagram {
background: #125688;
color: white;
padding: 1rem;
}
.fa-github {
background: white;
color: black;
padding: 1rem;
}
.fa-facebook {
background: #4267B2;
color: white;
padding: 1rem;
}
.fa-linkedin {
background: #3B5998;
color: white;
padding: 1rem;
}
.sm-icon {
transition: all 0.3s linear;
}
.sm-icon:hover {
transform: scale(1.2);
}
.fa:hover {
background-color: #fdcd3b;
}
/*MOBILE MENU*/
.mobile-menu {
display: none;
}
.mobile-menu {
display: flex;
width: 100%; /*.line a szülő tehát 40px a width*/
height: calc(100vh - 80px);
align-items: center;
justify-content: center;
position: absolute;
top: 80px;
left: 0;
background-color: black;
transform: translate(-100%);
transition: all 0.4s ease;
z-index: 100;
}
.mobile-menu-on {
display: flex; /**/
transform: translate(0);
}
.m-menu {
display: flex;
flex-direction: column;
gap: 2rem;
text-align: center;
font-size: 1.4rem;
}
/*hamburger icon*/
.header-right-gap {
width: 100px;
margin-left: 2rem;
}
.hamburger {
display: none;
position: fixed;
width: 50px;
height: 50px;
border: none;
background-color: transparent;
top: 0;
left: 1;
margin-top: 1.5rem;
}
.hamburger:hover {
border: 6px solid;
border-color: yellow;
width: 43px;
margin-left: 4px;
transform: scale(1.2);
}
.hamburger:hover .line.line-1 {
/*display: none;*/
transform: rotate(45deg) translateY(7.5px);
background-color: yellow;
}
.hamburger:hover .line.line-2 {
display: none;
}
.hamburger:hover .line.line-3 {
/*display: none;*/
transform: rotate(-45deg) translateY(-7.5px);
background-color: yellow;
}
.line {
transition: all .4s ease;
width: 40px;
height: 5px;
background-color: white;
margin-block: 5px;
border-radius: 10px;
}
/*Media query*/
#media (max-width: 1200px) {
.hamburger {
display: block;
}
#desktop-menu {
display: none;
}
}
#media (max-width: 900px) {
footer nav ul {
flex-direction: column;
}
footer nav ul li a {
font-size: 15px;
/*padding: 15px;*/
}
}
#media (max-width: 750px) {
.footer-container {
display: flex;
flex-wrap: wrap;
}
footer nav ul li a {
font-size: 10px;
padding: 15px;
}
.text-container p {
font-size: 10px;
}
}
#media (max-width: 600px) {
.container form {
width: 470px;
}
.container form input {
width: 160px;
}
.container form #button, .container form h4 {
margin-inline: auto;
}
.container form textarea {
min-width: 300px;
max-width: 300px;
}
}
#media (max-width: 400px) {
.container {
max-width: 100%;
height: 100%;
overflow: hidden;
}
.container form {
max-width: 100%;
padding-top: 40px;
padding-bottom: 10px;
}
.container form input, h4 {
text-align: center;
}
.container form input {
width: 160px;
}
.container form #button, .container form h4 {
margin-inline: auto;
}
.container form textarea {
align-items: center;
min-width: 300px;
max-width: 300px;
}
.text-container {
width: 70vw;
}
.container form #button {
display: flex;
flex-direction: column;
}
footer {
width: 400px;
}
.footer-top {
display: flex;
flex-direction: column;
align-items: center;
}
}
I once had a similar problem and it was due to margin of one element being bigger than it should be, and it just made that div bigger and pushed it out of viewport, so you could check your margins, I can see that you have quite a lot of margins, inline and to margin-right as well.

Flex propery does not work when I try to center an object

I want to have a column of identical object center in the midle of the page. the objects id is: total-score and the container id is: results. I try to use flex but I cannot figure it out how to center it in any way. I tryed to use align-content:center and justify-content: center but they seems to dont do anything. why? I attached just the css and the html. SO does not let me attache the entire code.
#import url(https://fonts.googleapis.com/css?family=Work + Sans:300, 600);
body {
font-size: 12px;
font-family: "Work Sans", sans-serif;
color: #333;
font-weight: 300;
text-align: center;
background-color: #f8f6f0;
}
h1 {
font-weight: 300;
margin: 0px;
padding: 10px;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
input[type="radio"] {
height: 1.6em;
width: 1.6em;
}
button {
font-family: "Work Sans", sans-serif;
font-size: 22px;
background-color: #279;
color: #fff;
border: 0px;
border-radius: 3px;
padding: 20px;
cursor: pointer;
margin: 20px 10px;
z-index: 3;
display: block;
font-size: 2em;
}
button:hover {
background-color: #38a;
}
.question {
font-size: 3em;
margin-bottom: 10px;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.answers {
margin-bottom: 20px;
text-align: left;
display: inline-block;
font-size: 3em;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.answers label {
display: block;
margin-bottom: 10px;
}
.slide {
position: static;
left: 0px;
top: 0px;
width: 100%;
z-index: 1;
display: none;
}
.active-slide {
display: block;
z-index: 2;
}
.quiz-container {
position: static;
height: auto;
margin-top: 40px;
}
#results {
display: flex;
flex-direction: column;
justify-content: center;
width: 10%;
}
#total-score {
padding-top: 10px; /* Add top padding */
padding-bottom: 10px; /* Add bottom padding */
width: 100%;
height: 100%;
background: rgb(255, 0, 0);
background: linear-gradient(
90deg,
rgba(255, 0, 0, 1) 0%,
rgba(255, 140, 0, 1) 50%,
rgba(50, 205, 50, 1) 100%
);
}
#media (min-width: 500px) {
body {
font-size: 18px;
}
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="QuizTransition.css">
<meta name="viewport" content="width=device-width" />
</head>
<body>
<div class="container">
<div>
<h1 id="question-numer">
Intrebarea numarul:
</h1>
</div>
<div class="quiz-container">
<div id="quiz"></div>
</div>
<button id="previous">Intrebarea precedenta</button>
<button id="next">Urmatoare intrebare</button>
</div>
<div id="results">
<div id="total-score">
</div>
<div id="total-score">
</div>
<div id="total-score">
</div>
</div>
<script src="QuizLogic.js"></script>
</div>
</body>
</html>
First, you should not use the same id in multiple elements. It should be unique. Instead of making the wrapper #results smaller, you can set it to full width and make the children .total-score smaller. Alternatively, you could wrap the children with another container and center it.
Try changing your code to the following:
body {
font-size: 12px;
font-family: "Work Sans", sans-serif;
color: #333;
font-weight: 300;
text-align: center;
background-color: #f8f6f0;
}
h1 {
font-weight: 300;
margin: 0px;
padding: 10px;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
input[type="radio"] {
height: 1.6em;
width: 1.6em;
}
button {
font-family: "Work Sans", sans-serif;
font-size: 22px;
background-color: #279;
color: #fff;
border: 0px;
border-radius: 3px;
padding: 20px;
cursor: pointer;
margin: 20px 10px;
z-index: 3;
display: block;
font-size: 2em;
}
button:hover {
background-color: #38a;
}
.question {
font-size: 3em;
margin-bottom: 10px;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.answers {
margin-bottom: 20px;
text-align: left;
display: inline-block;
font-size: 3em;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.answers label {
display: block;
margin-bottom: 10px;
}
.slide {
position: static;
left: 0px;
top: 0px;
width: 100%;
z-index: 1;
display: none;
}
.active-slide {
display: block;
z-index: 2;
}
.quiz-container {
position: static;
height: auto;
margin-top: 40px;
}
#results {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
}
.total-score {
padding-top: 10px; /* Add top padding */
padding-bottom: 10px; /* Add bottom padding */
width: 10%;
height: 100%;
background: rgb(255, 0, 0);
background: linear-gradient(
90deg,
rgba(255, 0, 0, 1) 0%,
rgba(255, 140, 0, 1) 50%,
rgba(50, 205, 50, 1) 100%
);
}
#media (min-width: 500px) {
body {
font-size: 18px;
}
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="QuizTransition.css">
<meta name="viewport" content="width=device-width" />
</head>
<body>
<div class="container">
<div>
<h1 id="question-numer">
Intrebarea numarul:
</h1>
</div>
<div class="quiz-container">
<div id="quiz"></div>
</div>
<button id="previous">Intrebarea precedenta</button>
<button id="next">Urmatoare intrebare</button>
</div>
<div id="results">
<div class="total-score">
a
</div>
<div class="total-score">
b
</div>
<div class="total-score">
c
</div>
</div>
<script src="QuizLogic.js"></script>
</div>
</body>
</html>
I think you need to center #result identifier.
#results {
display: flex;
align-items: center;
justify-content: center;
width: 10%;
}
#results div {
width: 100px;
height: 100px;
}
This will fix your problem. Thanks
#results {
display: flex;
flex-direction: column;
justify-content:center;
align-items: center;
width: 100%;
/* background:olive; */
}
#total-score {
padding-top: 10px; /* Add top padding */
padding-bottom: 10px; /* Add bottom padding */
width: 10%;
height: 100%;
background: rgb(255, 0, 0);
background: linear-gradient(
90deg,
rgba(255, 0, 0, 1) 0%,
rgba(255, 140, 0, 1) 50%,
rgba(50, 205, 50, 1) 100%
);
}
An element needs to be assigned position with the value of absolute, relative, fixed, or sticky in order to have z-index to function.
Flex container is the term used to refer to an element that is is assigned display: flex. If you need its descendant elements (referred to as flex items) be centered horizontally, assign the flex container justify-content: center. If you need the flex items to be stacked vertically, assign the flex container flex-direction: column or flex-flow: column {nowrap or wrap}
I revamped ... well everything because as a slider it will be very problematic should you continue with the original code. The solution to your problem (as I can best as I could tell, because the question was vague), can be found reviewing the CSS rulesets dealing with .total-score.
#import url(https://fonts.googleapis.com/css?family=Work + Sans:300, 600);
:root,
body {
width: 100%;
height: 100%;
font: 300 12px/1.5 "Work Sans", sans-serif;
color: #333;
text-align: center;
background-color: #f8f6f0;
user-select: none;
}
body {
overflow-y: scroll;
overflow-x: hidden;
padding: 0;
}
input,
button {
font: inherit;
font-size: 1rem;
}
.container {
display: flex;
flex-flow: column nowrap;
justify-content: center;
width: 100%;
height: 100%;
margin: 10px auto;
}
h1 {
font-weight: 300;
margin-bottom: 20px;
}
.quiz {
position: relative;
display: flex;
flex-flow: row nowrap;
justify-content: spacer-between;
align-items: center;
width: 100%;
height: 100%;
}
.slide {
position: absolute;
left: 0;
top: -20px;
width: 90%;
min-height: max-content;
z-index: -1;
display: none;
}
.slide.active {
display: block;
z-index: 0;
background: #fff;
}
.slide p,
.slide ol,
.slide [type=radio] {
font-size: 1.25rem;
text-align: left;
}
.slide p {
text-indent: 30px;
margin: 0 auto;
}
.slide ol {
margin: 0 auto;
list-style-type: none;
list-style-position: outside;
}
.slide ol label::before {
content: attr(for)'. ';
}
.slide [type=radio] {
width: 1.4rem;
height: 1.4rem;
}
.slide [type=radio],
.slide label {
display: inline-block;
line-height: 18px;
height: 18px;
vertical-align: middle;
}
fieldset {
border: 0;
}
button {
font-size: 1.75rem;
background-color: #279;
color: #fff;
border: 0px;
border-radius: 3px;
padding: 1px 5px;
cursor: pointer;
display: inline-block;
text-align: center;
}
button:hover {
background-color: #38a;
}
.next,
.prev {
position: absolute;
z-index: 1;
top: 4rem
}
.prev {
left: 0;
}
.next {
right: 35px;
}
.total-score {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding-top: 0px;
padding-bottom: 10px;
background: linear-gradient( 90deg, rgba(255, 0, 0, 1) 0%, rgba(255, 140, 0, 1) 50%, rgba(50, 205, 50, 1) 100%);
color: navy;
}
.total-score output,
.total-score b {
display: inline-block;
font-size: 1.5rem;
}
.total-score label {
width: 50%;
margin-bottom: -5px;
}
.total-score b {
width: 8ch;
text-align: left;
}
.total-score output {
width: 4ch;
font-family: Consolas;
text-align: right;
}
#media (min-width: 500px) {
:root,
body {
font-size: 18px;
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
</head>
<body>
<form class="container">
<h1>Quiz Question <output id='number'>1</output></h1>
<fieldset class="quiz">
<button class="prev" type='button'>◀</button>
<fieldset class='slide active' data-num='1'>
<p class='question'>This is a question?</p>
<ol class='choice'>
<li><input id='a' name='pick' type='radio' value='0'> <label for='a'>This is choice A</label></li>
<li><input id='b' name='pick' type='radio' value='0'> <label for='b'>This is choice B</label></li>
<li><input id='c' name='pick' type='radio' value='1'> <label for='c'>This is choice C and is correct (value = '1')</label></li>
<li><input id='d' name='pick' type='radio' value='0'> <label for='d'>This is choice D</label></li>
</ol>
</fieldset>
<button class="next" type='button'>▶</button>
</fieldset>
<fieldset class='total-score'>
<label><b>Correct:</b> <output id="correct">0</output></label>
<label><b>Total:</b> <output id="total">0</output></label>
<label><b>Score:</b> <output id="score">0</output></label>
</fieldset>
</form>
</body>
</html>

How can I turn a row of flex items into two columns?

Hey friends I have a section on my webpage called services. This section contains 4 lists. Each list is wrapped in a div. Each div is a flex-item and has a flex basis of 25%. These 4 divs sit in a row. However when the screen size shrinks to 775px I want to take the last to lists and place them under the first two, creating two columns. I'm not that familiar with flexbox, how can I do this?
.content {
display: flex;
}
.content > .skills {
flex-basis: 25%;
margin-top: 15px;
margin-bottom: 15px;
}
<div class="content">
<ul class="skills">
<li>Flatwork</li>
<li>Paving</li>
<li>Driveways</li>
<li>Sidewalks</li>
</ul>
<ul class="skills">
<li>Foundations</li>
<li>Flooring</li>
<li>Seismic Retrofit</li>
<li>Other Concrete Concerns</li>
</ul>
<ul class="skills">
<li>Commercial</li>
<li>Residential</li>
<li>Decks and Patios</li>
<li>Kitchen Flooring</li>
</ul>
<ul class="skills">
<li>Demolition</li>
<li>Grading/Clean up</li>
<li>Slab Repair</li>
<li>Curb Repair</li>
</ul>
</div>
One solution would be to use responsive styling to apply flex-wrap: wrap; to .content and flex-basis: 50%; to .content > div when the display is less than your break-point of 775px.
This could be done by adding the following to your CSS:
/* Only applies the styling when screen is between 0px and 775px wide */
#media (max-width: 775px) {
.services .content {
/* Tells flex box to allow child elements to "wrap" onto next row if needed */
flex-wrap: wrap;
}
.services .content div {
/* Tells children of .content to occupy half of parents width, resulting in two columns */
flex-basis: 50%;
}
}
For a working demo, see the snippet below:
html,
body {
margin: 0;
padding: 0;
}
nav li a {
text-decoration-line: none;
color: rgba(102, 102, 102, 0.75);
}
.wrapper2 {
width: 100%;
height: 65vh;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.3);
}
header {
background-image: url(../img/pexels.jpg);
background-position: center;
background-size: cover;
height: 65vh;
background-attachment: fixed;
background-repeat: no-repeat;
}
header h1 {
color: white;
margin: 0;
font-size: 5rem;
font-family: 'Montserrat';
font-weight: bolder;
}
nav {
background-color: white;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
position: fixed;
top: 0;
left: 0;
z-index: 2;
box-shadow: 0px 0px 100px grey;
}
nav ul {
margin-right: 0px;
margin-top: 25px;
}
nav li {
display: inline-block;
font-size: 1.55rem;
margin-right: 20px;
font-family: 'Rajdhani';
color: rgba(102, 102, 102, 0.75);
}
nav li a:hover {
cursor: pointer;
color: #1a1a1a;
transition: all 0.7s ease;
}
.after:after {
position: relative;
left: 12px;
top: 2px;
display: inline-block;
content: "";
width: 1px;
height: 20px;
background-color: rgba(102, 102, 102, 0.25);
}
.logo {
color: red;
font-size: 3.7rem;
margin: 10px;
opacity: 1;
margin-left: 30px;
}
/*---ABOUT---*/
.history h2 {
font-family: 'Rajdhani';
color: rgba(102, 102, 102, 0.85);
font-size: 3rem;
text-align: center;
margin-top: 20px;
margin-bottom: 20px;
}
.history h2:after {
content: '';
width: 18px;
height: 2px;
background-color: red;
display: inline-block;
margin-left: 5px;
margin-bottom: 13px;
}
.history h2:before {
content: '';
width: 18px;
height: 2px;
background-color: red;
display: inline-block;
margin-right: 5px;
margin-bottom: 13px;
}
.history p {
color: rgba(102, 102, 102, 0.85);
font-family: 'Rajdhani';
font-size: 1.7rem;
text-align: center;
width: 90%;
margin-right: auto;
margin-left: auto;
margin-top: 35px;
position: relative;
top: -20px;
}
/*---SERVICES---*/
.services {
background-image: url(../img/pour.jpeg);
background-size: cover;
background-attachment: fixed;
}
.services .wrapper {
width: 100%;
height: 250px;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.3);
}
.services {
color: white;
font-family: 'Montserrat';
font-weight: bolder;
font-size: 3rem;
}
.services .content {
display: flex;
background-color: white;
}
.services .content div {
flex-basis: 25%;
margin-top: 15px;
margin-bottom: 15px;
}
.services ul {
color: red;
font-size: 1.8rem;
font-family: 'Rajdhani';
list-style-type: square;
margin-left: 50px;
margin-top: 0;
margin-bottom: 0;
}
.skills p {
margin: 10px;
}
.content .move {
align-self: flex-end;
}
/*---TESTIMONY---*/
.testimony {
background-image: url('../img/wall4.jpg');
display: flex;
justify-content: space-around;
background-attachment: fixed;
background-size: cover;
}
.testimony h1 {
margin-bottom: 20px;
margin-top: 20px;
color: white;
font-family: 'Arvo';
padding: 30px;
display: inline-block;
flex-basis: 40%;
margin-left: 30px;
}
.testimony span {
color: white;
font-size: 2.3rem;
}
.testimony .quote {
font-family: 'Rajdhani';
font-size: 1.2rem;
margin-left: 40px;
}
.testimony .left-quote {
position: relative;
left: 60px;
top: 30px
}
.fa-quote-right {
position: relative;
right: 35px;
top: 30px;
}
.testimony .move {
right: 68px;
}
/*---FOOTER---*/
.footer .wrapper {
display: flex;
}
.footer div {
display: inline-block;
flex-basis: 29%;
font-family: 'Rajdhani';
color: rgba(102, 102, 102, 1);
margin-top: 5px;
justify-content: space-around;
}
.footer h1 {
font-size: 2rem;
margin-top: 15px;
}
.social .inner {
width: 100%;
}
.footer .inner:before {
display: inline-block;
content: '';
width: 29%;
height: 2px;
background-color: rgba(102, 102, 102, 0.6);
position: absolute;
margin-top: 54px;
}
.footer h1 span {
display: inline;
position: relative;
}
.footer h1 span:after {
content: '';
height: 2px;
width: 100%;
background-color: red;
position: absolute;
bottom: 0;
left: 0;
}
.wrap:before {
content: '';
width: 100px;
height: 2px;
background-color: red;
position: absolute;
margin-top: 55px;
}
.links a {
display: block;
text-decoration-line: none;
color: rgba(102, 102, 102, 1);
font-size: 1.1rem;
position: relative;
top: -17px;
transition: color 0.4s ease;
}
.links a:hover {
color: red;
}
.contact p {
position: relative;
top: -10px;
}
.social i {
font-size: 1.7rem;
margin-right: 5px;
position: relative;
top: -20px;
color: rgba(102, 102, 102, 0.7);
transition: all 0.4s ease;
}
.social i:hover {
color: red;
cursor: pointer;
}
#msg {
margin-top: -15px;
}
.footer-textarea {
background-color: rgba(102, 102, 102, 0.2);
padding: 0;
outline: none;
font-size: 1.2rem;
color: rgba(102, 102, 102, 1);
resize: none;
width: 99.5%;
}
.footer button {
float: right;
margin-top: -17px;
border: none;
font-family: 'Rajdhani';
font-size: 1.2rem;
transition: all ease 0.4s;
outline: none;
}
button:hover {
cursor: pointer;
color: red;
}
.dark {
color: red;
}
.copyright {
position: absolute;
background-color: white;
text-align: center;
width: 100%;
margin-bottom: 0;
font-size: 1.2rem;
padding-bottom: 4px;
}
/*-------MEDIA QUERIES-------*/
#media screen and (min-width: 2460px) {
/*---NAV---*/
nav li {
font-size: 3rem;
}
.logo {
font-size: 8rem;
}
.after:after {
width: 3px;
height: 40px;
margin-left: 5px;
margin-right: 5px;
}
/*---MAIN---*/
header h1 {
font-size: 9rem;
}
.history h2 {
font-size: 6rem;
margin-bottom: 30px;
}
.history h2:before,
.history h2:after {
height: 4px;
width: 35px;
margin-bottom: 25px;
}
.history p {
font-size: 3.4rem;
}
.services h1 {
font-size: 8rem;
}
.services .wrapper {
height: 400px;
}
.services h2 {
font-size: 6rem;
}
.services h2:before,
.services h2:after {
height: 4px;
width: 35px;
margin-bottom: 25px;
}
.services li {
font-size: 3.5rem;
}
.services ul {
margin-left: 150px;
}
.testimony i {
font-size: 5rem;
padding-top: 30px;
}
.testimony h1 {
font-size: 2.7rem;
padding-bottom: 60px;
}
.testimony .quote {
font-size: 2.3rem;
}
/*---FOOTER---*/
.footer h1 {
font-size: 4.5rem;
padding-top: 15px;
}
.footer h1 span:after {
height: 4px;
}
.footer .inner:before {
height: 4px;
margin-top: 118.25px;
}
.links a {
font-size: 2.5rem;
top: -20px;
}
.social i {
font-size: 3.5rem;
margin-right: 10px;
top: -40px;
}
.footer button {
font-size: 2.5rem;
margin-right: 14.25%;
padding-left: 10px;
padding-right: 10px;
margin-top: -37px;
}
.footer textarea {
font-size: 2.5rem;
width: 85%;
}
.contact p {
font-size: 2.5rem;
margin-bottom: 35px;
margin-top: 35px;
}
.copyright {
font-size: 2.5rem;
}
}
#media screen and (min-width: 1901px) {
.footer button {
margin-left: 14%;
}
}
/*---LAPTOP-LARGE---*/
#media screen and (max-width: 1593px) {
.skills li {
font-size: 1.65rem;
}
.skills p {
font-size: 1.65rem;
}
}
#media screen and (max-width: 1497px) {
.skills li {
font-size: 1.5rem;
}
.skills p {
font-size: 1.5rem;
}
}
#media screen and (max-width: 1448px) {
.skills li {
font-size: 1.35rem;
}
.skills p {
font-size: 1.35rem;
}
}
#media screen and (max-width: 1440px) {
/*---FOOTER---*/
.footer button {
margin-left: 16.5%;
}
}
#media screen and (max-width: 1332px) {
.history p {
font-size: 1.5rem;
}
}
#media screen and (max-width: 1091px) {
.skills p {
font-size: 1.15rem;
}
}
/*---TABLET-LARGE---*/
#media screen and (max-width: 985px) {
.history h2 {
font-size: 2.5rem;
margin-top: 15px;
margin-bottom: 15px;
}
.history h2:before,
.history h2:after {
width: 15px;
margin-bottom: 11px;
}
.history p {
margin-top: 25px;
font-size: 1.4rem;
}
.services ul {
margin-left: 20px;
}
}
#media screen and (max-width: 924px) {
.logo {
font-size: 3rem;
}
nav li {
font-size: 1.4rem;
}
}
#media screen and (max-width: 829px) {
.footer .contact p {
font-size: 1rem;
margin: 3px;
}
.footer textarea {
font-size: 1rem;
}
}
#media screen and (max-width: 836px) {
.services ul {
margin-left: 5px;
}
}
#media screen and (max-width: 812px) {
/*---MAIN---*/
.history p {
font-size: 1.3rem;
}
.padding {
padding-top: 0px;
}
.testimony h1 {
font-size: 1.25rem;
}
/*---FOOTER---*/
.footer button {
margin-left: 8.5%;
}
.contact .inner {
margin-right: 20px;
}
}
/*---TABLET---*/
#media screen and (max-width: 768px) {
/*---MAIN--*/
header,
.wrapper2 {
height: 65vh;
}
.services ul {
font-size: 1.5rem;
margin-left: 30px;
}
.padding2 {
padding-top: 10px;
}
.testimony h1 {
font-size: 1.1rem;
}
.testimony .fa-quote-right {
display: none;
}
}
/*------LANDSCAPE-MODE-MOBILE------*/
#media screen and (max-width: 715px) {
/*---NAV---*/
nav ul {
padding-left: 0;
margin: 0;
}
nav li {
font-size: 1.4rem;
}
nav .logo {
font-size: 2.5rem;
}
/*---MAIN---*/
.history p {
font-size: 1.5rem;
}
.testimony {
flex-direction: column;
}
.testimony h1 {
margin-left: 30px;
font-size: 1.45rem;
}
.move-quote {
position: relative;
top: -30px;
}
.fa-quote-right {
position: absolute;
display: none;
}
.padding {
top: -35px;
}
}
#media screen and (max-width: 640px) {
header h1 {
font-size: 4rem;
}
.services h1 {
font-size: 3.5rem;
}
/*---FOOTER---*/
.footer h1 {
font-size: 1.5rem;
}
.footer .inner:before {
margin-top: 43px;
}
.links a {
font-size: 1rem;
top: -14px;
}
.social i {
font-size: 1.5rem;
margin-right: 2px;
top: -17px;
}
.footer button {
margin-top: -14px;
font-size: 1rem;
}
.footer textarea {
font
}
#media screen and (max-width: 626px) {
nav li {
font-size: 1.27rem;
}
/*---FOOTER---*/
.footer .wrapper {
display: flex;
flex-direction: column;
}
.footer div {
margin: 0;
}
.footer h1 {
font-size: 2rem;
margin-top: 10px;
}
.footer .inner {
margin: 0;
}
.footer .inner:before {
display: inline-block;
content: '';
width: 100vw;
height: 2px;
background-color: rgba(102, 102, 102, 0.6);
position: absolute;
margin-top: 48px;
}
.footer h1 span:after {
content: '';
height: 2px;
width: 100%;
background-color: red;
position: absolute;
bottom: 1px;
left: 0;
}
.social .inner {
position: relative;
top: -10px;
}
.links a {
margin-left: 5px;
}
.social h1 {
margin-bottom: 10px;
}
#msg {
font-size: 1rem;
margin-bottom: 0;
margin-right: 25.5%;
position: absolute;
right: 5px;
top: 80px;
}
.footer button {
right: 9.25%;
margin-top: 0.2px;
}
.social i {
font-size: 1.8rem;
margin-right: 2px;
position: relative;
top: -5px;
left: 5px;
color: rgba(102, 102, 102, 0.7);
transition: all 0.4s ease;
}
.footer-textarea {
width: 88.5%;
margin-top: 25px;
margin-left: 5px;
}
.contact p {
margin: 5px;
font-size: 1.2rem;
}
.copyright {
background-color: red;
padding-top: 10px;
padding-bottom: 10px;
}
.copyright span {
color: white;
background-color: red;
}
}
#media screen and (max-width: 586px) {
/*---MAIN---*/
header h1 {
font-size: 3.5rem;
}
.services li {
font-size: 1.3rem;
}
.services ul {
padding: 0;
margin-left: 50px;
}
}
#media screen and (max-width: 568px) {
/*---MAIN---*/
header h1,
.services h1 {
font-size: 4rem;
}
.services li {
font-size: 1.1rem;
}
.services ul {
margin-left: 10px;
}
.padding {
padding-top: 10px;
}
/*---FOOTER---*/
.footer .wrapper {
display: flex;
flex-direction: column;
}
.footer div {
margin: 0;
}
.footer h1 {
font-size: 2rem;
margin-top: 10px;
}
.footer .inner {
margin: 0;
}
.footer .inner:before {
display: inline-block;
content: '';
width: 100%;
height: 2px;
background-color: rgba(102, 102, 102, 0.6);
position: absolute;
margin-top: 48px;
}
.footer h1 span:after {
content: '';
height: 2px;
width: 100%;
background-color: red;
position: absolute;
bottom: 1px;
left: 0;
}
.social .inner {
position: relative;
top: -10px;
}
.social .inner:before {
width: 100vw;
}
.links a {
margin-left: 5px;
}
.social h1 {
margin-bottom: 10px;
}
#msg {
font-size: 1rem;
margin-bottom: 0;
margin-right: 25.5%;
position: absolute;
right: 5px;
top: 80px;
}
.footer button {
right: 9.25%;
margin-top: 0.2px;
}
.social i {
font-size: 1.8rem;
margin-right: 2px;
position: relative;
top: -5px;
left: 5px;
color: rgba(102, 102, 102, 0.7);
transition: all 0.4s ease;
}
.footer-textarea {
width: 88.5%;
margin-top: 30px;
margin-left: 5px;
}
.contact p {
margin: 5px;
font-size: 1.2rem;
}
.copyright {
background-color: red;
}
.copyright span {
color: white;
background-color: red;
}
}
#media screen and (max-width: 530px) {
nav li {
font-size: 1.27rem;
margin-right: 7px;
}
.after:after {
left: 5.5px;
top: 4px;
}
.logo {
margin-left: 15px;
}
}
#media screen and (max-width: 517px) {
/*---NAV---*/
nav li {
font-size: 1.1rem;
}
/*---MAIN---*/
header h1 {
font-size: 3rem;
}
/*---FOOTER---*/
.footer .wrapper {
display: flex;
flex-direction: column;
}
.footer div {
margin: 0;
}
.footer h1 {
font-size: 2rem;
margin-top: 10px;
}
.footer .inner {
margin: 0;
}
.footer .inner:before {
display: inline-block;
content: '';
width: 100vw;
height: 2px;
background-color: rgba(102, 102, 102, 0.6);
position: absolute;
margin-top: 48px;
}
.social .inner {
position: relative;
top: -10px;
}
.footer h1 span:after {
content: '';
height: 2px;
width: 100%;
background-color: red;
position: absolute;
bottom: 1px;
left: 0;
}
.links a {
margin-left: 5px;
}
.social h1 {
margin-bottom: 10px;
}
#msg {
font-size: 1.3rem;
margin-bottom: 0;
float: right;
margin-right: 25.5%;
position: relative;
top: 15px;
}
.footer button {
right: 9.25%;
margin-top: 0.2px;
}
.social i {
font-size: 1.8rem;
margin-right: 7px;
position: relative;
top: -5px;
left: 5px;
color: rgba(102, 102, 102, 0.7);
transition: all 0.4s ease;
}
.footer-textarea {
width: 88.5%;
margin-left: 5px;
margin-top: 0px;
position: relative;
top: 10px;
}
.contact p {
margin: 5px;
font-size: 1.2rem;
}
.copyright {
background-color: red;
}
.copyright span {
color: white;
background-color: red;
}
}
#media only screen and (max-width: 775px) {
.content {
flex-wrap: wrap;
}
.services .content div {
flex-basis: 50%;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About | Kane Concrete & Construction</title>
<link rel="stylesheet" href="../css/about.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Arvo|Bitter|Lato|Montserrat|Noto+Sans|Open+Sans|Poppins|Roboto|Sarabun|Ubuntu" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Abel|Asap|Krub|Oxygen|Rajdhani|Staatliches|Varela+Round" rel="stylesheet">
</head>
<body>
<header>
<div class="wrapper2">
<nav>
<div class="logo">
<i class="fab fa-accusoft"></i>
</div>
<div class="nav">
<div class="ham-menu">
<div class="m1" id="m1"></div>
<div class="m2" id="m2"></div>
<div class="m3" id="m3"></div>
</div>
<ul>
<li class="after">Home</li>
<li class="after">About</li>
<li class="after">Services</li>
<li class="after">Careers</li>
<li>Contact</li>
</ul>
</div>
</nav>
<h1>About Us</h1>
</div>
</header>
<section class="history" style="background-color: white;">
<h2>Our History</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat ea magni suscipit modi sapiente. Perferendis odit, incidunt, amet adipisci, quaerat aperiam, impedit nemo excepturi culpa quis libero nostrum molestiae error eveniet ipsa repellat?
Cum quae laudantium totam neque provident fuga rerum quasi dolorum vel obcaecati quidem perspiciatis iure maiores dignissimos, recusandae enim error libero nobis inventore quo adipisci perferendis. Pariatur. Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Possimus, dolor.</p>
</section>
<section class="services" id="services">
<div class="wrapper">
<h1>Services</h1>
</div>
<div class="content">
<div>
<ul class="skills">
<li>
<p style="color: rgba(102,102,102, 0.85);">Flatwork</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Paving</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Driveways</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Sidewalks</p>
</li>
</ul>
</div>
<div class="move">
<ul class="skills">
<li>
<p style="color: rgba(102,102,102, 0.85);">Foundations</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Flooring</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Seismic Retrofit</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Other Concrete Concerns</p>
</li>
</ul>
</div>
<div>
<ul class="skills">
<li>
<p style="color: rgba(102,102,102, 0.85);">Commercial</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Residential</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Decks and Patios</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Kitchen Flooring</p>
</li>
</ul>
</div>
<div>
<ul class="skills">
<li>
<p style="color: rgba(102,102,102, 0.85);">Demolition</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Grading/Clean up</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Slab Repair</p>
</li>
<li>
<p style="color: rgba(102,102,102, 0.85);">Curb Repair</p>
</li>
</ul>
</div>
</div>
</section>
<section class="testimony">
<div class="block">
<span><i class="fas fa-quote-left left-quote"></i></span>
<h1 class="first-quote">Most companys that I searched charged way too much, until I found Kane. They were fast, cheap, and very professional. I'm happy I chose them and will definitely keep them in mind for any other of my future projects.<span class="quote"> -Some Person</span></h1>
</div>
<div class="block">
<span class="move-quote"><i class="fas fa-quote-left left-quote"></i></span>
<h1 class="move-quote">I was very impressed with their work. They were cost effective and efficient and overall a good team. Saw a lot of synergy with their organization and others they worked with. They definitely know what they're doing.<span class="quote">-Some Person</span></h1>
</div>
</section>
<section class="footer">
<div class="wrapper">
<div class="links">
<div class="inner">
<h1><span>Quick Links</span></h1>
Home
About
Services
Careers
Contact
Quote
</div>
</div>
<div class="social">
<div class="inner">
<h1><span>Social</span></h1>
<i class="fab fa-linkedin"></i>
<i class="fab fa-facebook"></i>
<i class="fab fa-twitter-square"></i>
<button name="msg">Send</button>
<textarea name="msg" class="footer-textarea" cols="45" rows="5" placeholder="Send is some feedback..."></textarea>
</div>
</div>
<div class="contact">
<div class="inner" class="wrap">
<h1><span>Contact</span></h1>
<p>(208)546-7827 - <span class="dark">Matt</span></p>
<p>(208)546-7827 - <span class="dark">Keegan</span></p>
<p><span class="dark">Address</span> - P.O. Box 50860 IF, ID 83405</p>
<p><span class="dark">Email</span> - KaneConcrete#fake.com</p>
</div>
</div>
</div>
<div class="copyright"><span>© 2019 - Kane Concrete & Construction | ALL RIGHTS RESERVED</span></div>
</section>
<script src="../script.js"></script>
</body>
</html>

Vertically center one of many div inside a container

A section consists of a navigation group with elements floated to the sides, a center text group, and a background image. The section height was not manually set to fit the background image.
How do I go about vertically centering the text group? It is div.h1-container.
Plunkr: https://plnkr.co/edit/rSWgdfPQEbIeXbPh4wO1?p=preview
body {
font: 15px/1.5 Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
background-color: #f4f4f4;
}
/* Global */
.container {
width: 80%;
margin: auto;
overflow: hidden;
}
.clear {
clear: both;
}
ul {
margin: 0;
padding: 0;
}
section h2 {
line-height: 1.0;
}
.button_1 {
height: 34px;
background: tomato;
border: 0;
padding-left: 20px;
padding-right: 20px;
color: #ffffff;
width: 200px;
}
.showcase-nav a {
color: #ffffff;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
.showcase-nav {
padding-top: 30px;
margin-top: 10px;
float: right;
}
.showcase-nav li.social i {
padding: 0 4px;
}
.showcase-nav li {
display: inline;
padding: 0 20px 0 20px;
}
.showcase-branding {
float: left;
}
.showcase-branding h1 {
font-size: 26px;
margin: 0;
padding-top: 30px;
color: #fff;
}
.showcase-branding .highlight {
color: #e8491d;
font-weight: bold;
}
.showcase-nav a:hover {
color: #cccccc;
font-weight: bold;
}
.h1-container {
width: 70%;
margin: auto;
}
.h1-container h1 {
text-transform: uppercase;
text-align: center;
color: #fff;
}
.h1-container p {
width: 81%;
background: tomato;
margin: auto;
border-radius: 10px;
text-align: center;
color: #fff;
}
/* Showcase */
#showcase {
background: url('http://i68.tinypic.com/2j5jho4.png') no-repeat;
background-size: contain;
width: 100%;
display: inline-block;
position: relative;
margin: 0 auto;
}
#showcase:after {
padding-top: 51.46%;
display: block;
content: '';
}
#showcase .container {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#showcase .h1-container h1 {
font-size: 55px;
margin-bottom: 10px;
}
#showcase p {
font-size: 20px;
padding: 5px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<section id="showcase">
<div class="container">
<div class="showcase-branding">
<h1>Title</h1>
</div>
<nav class="showcase-nav">
<ul>
<li class="current">About</li>
<li>Contact</li>
<li class="social"><i class="fa fa-linkedin-square"></i><i class="fa fa-facebook-official"></i><i class="fa fa-twitter"></i></li>
</ul>
</nav>
<div class="clear"></div>
<div class="h1-container">
<h1>Text on line 1<br>text on line 2</h1>
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum <i class="fa fa-caret-right"></i></p>
</div>
</div>
</section>
Given the current context there are two simple ways to go about this.
One way would be to give .h1-container display: flex, flex-direction: column, and justify-content: center.
Here is a jsfiddle.
However, if you were to do it this way, each element and every new element placed in .h1-container will end up being stacked vertically and centered vertically in relation to .h1-container, so it will appear as if the children elements are not centered if .h1-container is not properly centered.
Also remember that justify-content always positions the children elements relative to the direction of the flex-box. Therefore, if your flex-box direction is not explicitly set, and since the default is flex-direction: row, justify-content would position the children horizontally. align-items will always be the opposite of the flex-box's direction property.
body {
font: 15px/1.5 Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
background-color: #f4f4f4;
}
/* Global */
.container {
width: 80%;
margin: auto;
overflow: hidden;
}
.clear {
clear: both;
}
ul {
margin: 0;
padding: 0;
}
section h2 {
line-height: 1.0;
}
.button_1 {
height: 34px;
background: tomato;
border: 0;
padding-left: 20px;
padding-right: 20px;
color: #ffffff;
width: 200px;
}
.showcase-nav a {
color: #ffffff;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
.showcase-nav {
padding-top: 30px;
margin-top: 10px;
float: right;
}
.showcase-nav li.social i {
padding: 0 4px;
}
.showcase-nav li {
display: inline;
padding: 0 20px 0 20px;
}
.showcase-branding {
float: left;
}
.showcase-branding h1 {
font-size: 26px;
margin: 0;
padding-top: 30px;
color: #fff;
}
.showcase-branding .highlight {
color: #e8491d;
font-weight: bold;
}
.showcase-nav a:hover {
color: #cccccc;
font-weight: bold;
}
.h1-container {
width: 70%;
margin: auto;
display: flex;
flex-direction: column;
justify-content: center;
}
.h1-container h1 {
text-transform: uppercase;
text-align: center;
color: #fff;
}
.h1-container p {
width: 81%;
background: tomato;
margin: auto;
border-radius: 10px;
text-align: center;
color: #fff;
}
/* Showcase */
#showcase {
background: url('http://i68.tinypic.com/2j5jho4.png') no-repeat;
background-size: contain;
width: 100%;
display: inline-block;
position: relative;
margin: 0 auto;
}
#showcase:after {
padding-top: 51.46%;
display: block;
content: '';
}
#showcase .container {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#showcase .h1-container h1 {
font-size: 55px;
margin-bottom: 10px;
}
#showcase p {
font-size: 20px;
padding: 5px;
}
<body>
<section id="showcase">
<div class="container">
<div class="showcase-branding">
<h1>Title</h1>
</div>
<nav class="showcase-nav">
<ul>
<li class="current">About</li>
<li>Contact</li>
<li class="social"><i class="fa fa-linkedin-square"></i><i class="fa fa-facebook-official"></i><i class="fa fa-twitter"></i></li>
</ul>
</nav>
<div class="clear"></div>
<div class="h1-container">
<h1>Text on line 1<br>text on line 2</h1>
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum <i class="fa fa-caret-right"></i></p>
</div>
</div>
</section>
</body>
The other way would be to give .container position: relative, and then give .h1-container position: absolute, top: 50%, and transform: translateY(-50%).
Positioning .container as relative allows you to absolutely position .h1-container in relation to .container as opposed to the entire document.
.container {
position: relative;
}
.h1-container {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
Here is a jsfiddle.
The following is an inline version which won't display properly due to the dimensions of everything, but it has at least centered the .h1-container.
body {
font: 15px/1.5 Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
background-color: #f4f4f4;
}
/* Global */
.container {
width: 80%;
margin: auto;
overflow: hidden;
position: relative;
}
.clear {
clear: both;
}
ul {
margin: 0;
padding: 0;
}
section h2 {
line-height: 1.0;
}
.button_1 {
height: 34px;
background: tomato;
border: 0;
padding-left: 20px;
padding-right: 20px;
color: #ffffff;
width: 200px;
}
.showcase-nav a {
color: #ffffff;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
.showcase-nav {
padding-top: 30px;
margin-top: 10px;
float: right;
}
.showcase-nav li.social i {
padding: 0 4px;
}
.showcase-nav li {
display: inline;
padding: 0 20px 0 20px;
}
.showcase-branding {
float: left;
}
.showcase-branding h1 {
font-size: 26px;
margin: 0;
padding-top: 30px;
color: #fff;
}
.showcase-branding .highlight {
color: #e8491d;
font-weight: bold;
}
.showcase-nav a:hover {
color: #cccccc;
font-weight: bold;
}
.h1-container {
width: 70%;
margin: auto;
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.h1-container h1 {
text-transform: uppercase;
text-align: center;
color: #fff;
}
.h1-container p {
width: 81%;
background: tomato;
margin: auto;
border-radius: 10px;
text-align: center;
color: #fff;
}
/* Showcase */
#showcase {
background: url('http://i68.tinypic.com/2j5jho4.png') no-repeat;
background-size: contain;
width: 100%;
display: inline-block;
position: relative;
margin: 0 auto;
}
#showcase:after {
padding-top: 51.46%;
display: block;
content: '';
}
#showcase .container {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#showcase .h1-container h1 {
font-size: 55px;
margin-bottom: 10px;
}
#showcase p {
font-size: 20px;
padding: 5px;
}
<body>
<section id="showcase">
<div class="container">
<div class="showcase-branding">
<h1>Title</h1>
</div>
<nav class="showcase-nav">
<ul>
<li class="current">About</li>
<li>Contact</li>
<li class="social"><i class="fa fa-linkedin-square"></i><i class="fa fa-facebook-official"></i><i class="fa fa-twitter"></i></li>
</ul>
</nav>
<div class="clear"></div>
<div class="h1-container">
<h1>Text on line 1<br>text on line 2</h1>
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum <i class="fa fa-caret-right"></i></p>
</div>
</div>
</section>
</body>

Resources