How to get rid of padding when search bar is open - css

All my code is placed in a header with class 'example'. When 'search' button is pressed, div with class 'search-bar' appears and have its borders identical to those of header. However, I would like to see search-bar bump into the left edge of the screen. How can it be achieved?
const searchBar =
document.querySelector('#search-bar');
const openBtn = document.querySelector('#open-btn');
const closeBtn = document.querySelector('#close-btn');
const brand = document.querySelector('#brand');
openBtn.addEventListener('click', (e) => toggleSlider());
closeBtn.addEventListener('click', (e) => toggleSlider());
function toggleSlider() {
searchBar.classList.toggle('open');
brand.classList.toggle('open');
}
.example {
padding: 0 50px;
display: flex;
align-items: center;
justify-content: space-between;
}
.brand {
z-index: 100;
transition: all 1s ease;
}
.brand.open {
color: #fff;
}
.slide-area {
width: 100%;
padding: 10px;
background-color: #fff;
display: flex;
align-items: center;
justify-content: space-between;
position: relative;
height: 50px;
overflow: hidden;
}
.search-bar {
display: flex;
justify-content: flex-end;
align-items: center;
background-color: purple;
position: absolute;
padding: 10px;
right: 0;
top: 0;
left: 0;
bottom: 0;
transform: translateX(100%);
transition: all 1s ease;
}
.search-bar.open {
transform: translateX(0);
}
<header class="example">
<div class="slide-area">
<div id="brand" class="brand">Menu Stuff
</div>
<button id="open-btn">Search
</button>
<div id="search-bar" class="search-bar">
<button id="close-btn">X</button>
</div>
</div>
<div class="btns">Log in</div>
</header>
Link to the working example in CodePen

Just change overflow: hidden from .slide-area to .example
const searchBar =
document.querySelector('#search-bar');
const openBtn = document.querySelector('#open-btn');
const closeBtn = document.querySelector('#close-btn');
const brand = document.querySelector('#brand');
openBtn.addEventListener('click', (e) => toggleSlider());
closeBtn.addEventListener('click', (e) => toggleSlider());
function toggleSlider() {
searchBar.classList.toggle('open');
brand.classList.toggle('open');
}
body {
margin: 0px;
}
.example {
padding: 0 50px;
display: flex;
align-items: center;
justify-content: space-between;
position: relative;
overflow: hidden;
}
.brand {
z-index: 100;
transition: all 1s ease;
}
.brand.open {
color: #fff;
}
.slide-area {
width: 100%;
padding: 10px;
background-color: #fff;
display: flex;
align-items: center;
justify-content: space-between;
height: 50px;
}
.search-bar {
display: flex;
justify-content: flex-end;
align-items: center;
background-color: purple;
position: absolute;
padding: 10px;
right: 0;
top: 0;
left: 0;
bottom: 0;
transform: translateX(100%);
transition: all 1s ease;
}
.search-bar.open {
transform: translateX(0);
}
<header class="example">
<div class="slide-area">
<div id="brand" class="brand">Menu Stuff
</div>
<button id="open-btn">Search
</button>
<div id="search-bar" class="search-bar">
<button id="close-btn">X</button>
</div>
</div>
<div class="btns">Log in</div>
</header>
Codepen link

Related

How to center a logo in a login form? [duplicate]

This question already has answers here:
Center image using text-align center?
(28 answers)
How to vertically align an image inside a div
(37 answers)
Closed last month.
I have a login form and would like to center the logo the same way the "signin" text is centered.
In fact, the logo always remains at the top left. I don't understand why the logo is not centered? If you have a solution to propose I am very very interested.
I would also like to understand the technique to make this logo responsive, please.
Thank you for your answer.
.parent {
position: absolute;
top: 10%;
left: 15%;
}
.wrapper {
position: relative;
width: 70vw;
height: 80vh;
background: #fff;
border-radius: 15px;
box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.3), 0 6px 20px 0 rgba(0, 0, 0, 0.3);
overflow: hidden;
}
.wrapper::before {
content: "";
position: absolute;
top: 0;
left: -50%;
width: 100%;
height: 100%;
background: linear-gradient(-45deg, #79df4a, #8673A1);
z-index: 6;
transform: translateX(100%);
transition: 1s ease-in-out;
}
.logo img {
position: absolute;
display: flex;
align-items: center;
justify-content: space-around;
height: 75px;
}
.signin {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: space-around;
z-index: 5;
}
form {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: 40%;
min-width: 238px;
padding: 0 10px;
}
form.sign-in-form {
opacity: 1;
transition: 0.5s ease-in-out;
transition-delay: 1s;
}
.title {
font-size: 35px;
color: #8673A1;
margin-bottom: 10px;
}
.panels-wrapper {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: space-around;
}
.panel {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
width: 35%;
min-width: 238px;
padding: 0 10px;
text-align: center;
z-index: 6;
}
.left-panel {
pointer-events: none;
}
.content {
color: #fff;
transition: 1.1s ease-in-out;
transition-delay: 0.5s;
}
.left-panel .content {
transform: translateX(-200%);
}
.right-panel .content {
transform: translateX(0);
}
.signin_item_block {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: 40%;
min-width: 238px;
padding: 0 10px;
}
.signin_item_block.sign-in-block-form {
opacity: 0;
transition: 0.5s ease-in-out;
transition-delay: 1s;
}
/*Responsive*/
#media (max-width:779px) {
.wrapper {
width: 100vw;
height: 100vh;
background-color: red;
}
}
#media (max-width:635px) {
.wrapper::before {
display: none;
}
form {
width: 80%;
}
.signin_item_block.sign-in-block-form {
display: none;
}
.wrapper.sign-up-mode2 form.sign-in-block-form {
display: flex;
opacity: 1;
}
.wrapper.sign-up-mode2 form.sign-in-form {
display: none;
}
.panels-wrapper {
display: none;
}
}
#media (max-width:320px) {
form {
width: 90%;
}
}
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Titre de la page</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
</head>
<body>
<div class="parent">
<div class="wrapper">
<div class="logo">
<img src="https://zupimages.net/up/23/02/0itb.png" alt="image">
</div>
<div class="signin">
<form (ngSubmit)="logon()" class="sign-in-form">
<!-- Signin -->
<h3 class="title">Signin</h3>
</form>
<div class="signin_item_block sign-in-block-form"></div>
</div>
<div class="panels-wrapper">
<div class="panel left-panel"></div>
<div class="panel right-panel">
<div class="content">
...
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Working: https://stackblitz.com/edit/js-ndbzyq?file=style.css
Firstly, The code was a bit untidy and a lot of unnecessary CSS was used example position: absolute.
The major changes involve are:
moving the logo div inside the signin div.
Changing the flex-direction to column to signing div.
using display flex for logo class which allows me to justify-content centre.
<div class="signin">
<div class="logo">
<img src="https://zupimages.net/up/23/02/0itb.png" alt="image" />
</div>
<div>
<form (ngSubmit)="logon()" class="sign-in-form">
<h3 class="title">Signin</h3>
</form>
</div>
<div class="signin_item_block sign-in-block-form"></div>
</div>
.logo {
justify-content: center;
display: flex;
width: 50%;
min-width: 238px;
}
.signin {
width: 100%;
height: 100%;
display: flex;
justify-content: space-around;
z-index: 5;
flex-direction: column;
}
To be fair, I suggest to re-write the whole structure of the HTML. Use Flex or Grid to achieve similarly and avoid position absolute in this case.

CSS selector when placeholder shown in grid element

In a (React/TS) form i need to move the label for the inputfield when;
The input has the focus
When the placeholder is not shown
This works fine for the first objective (with .grid__item--fixedrowcolone), but i am unable to to realise this for the second. The input and the label are grid elements so i can place the input and label on top and vertically center both.
What i unsuccessfully tried is (multiple variants) of the snippet below.
.grid__item--fixedrowcolone {
&:not(~ .form__inputfield:placeholder-shown) {
color: green;
}
}
react form
<div className={styles.form__inputwrapper} data-testid='form-input'>
<div className={styles.form__inputsymbol} data-testid='form-input-icon'>
<img src={lockSvg} alt='lock' width='24' height='24' />
</div>
<div className={styles.grid__container} data-testid='form-input-field'>
<div className={styles['grid__item--fixedrowcolone']}>
<input
className={styles.form__inputfield}
type='text'
pattern='^.*{8,}'
id='pwd1'
name='pwd1'
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
placeholder=' '
required
data-testid='forminput-input'
/>
</div>
<div className={styles['grid__item--fixedrowcoltwo']}>
<label
className={styles.form__inputlabel}
htmlFor='pwd1'
data-testid='forminput-inputlabel'
>
wachtwoord
<span className={styles.form__inputlabelvalmsg}>
+312234
</span>
</label>
</div>
</div>
</div>
css module.scss
.grid {
&__container {
display: grid;
justify-items: stretch;
}
&__item {
&--fixedrowcolone, &--fixedrowcoltwo {
display: flex;
grid-column: 1;
grid-row: 1;
}
}
}
.form {
&__inputwrapper {
display: flex;
margin-bottom: 10px;
position: relative;
background: var(--theme_form_field_bg_color);
border-radius: 4px;
}
&__inputsymbol {
display: flex;
align-self: center;
//align-items: center;
padding-left: 10px;
pointer-events: none;
color: var(--theme_fg_color);
font-size: 1.5em;
transition: all 0.4s;
filter: var(--theme_fg_color_filter)
}
&__inputfield {
align-self: center;
//line-height: 1.2;
font-size: 1.5em;
height: 50px;
color: var(--theme_fg_color);
background: none;
outline: none;
border: none;
max-width: 280px;
min-width: 250px;
overflow: visible;
touch-action: manipulation;
}
&__inputlabel {
align-self: center;
//line-height: 1.2;
font-size: 1.5em;
transition: .3s all ease;
}
&__inputlabelvalmsg {
display: none;
}
}
.grid__item--fixedrowcolone {
&:focus-within ~ .grid__item--fixedrowcoltwo {
top: 5px;
font-size: .5em;
align-self: start;
}
}
Unfortunately it is yet not possible to select elements based on presence of child elements or child element pseudo selectors. So therefore i reverted back to absolute positioning to overlay two elements.
react form
<div className={styles.form__inputwrapper} data-testid='form-input'>
<div className={styles.form__inputsymbol} data-testid='form-input-icon'>
<img src={lockSvg} alt='lock' width='24' height='24' />
</div>
<div
className={styles.form__inputfieldwrapper}
data-testid='form-input-field'
>
<input
className={styles.form__inputfield}
type='text'
pattern='^.*{8,}'
id='pwd1'
name='pwd1'
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
placeholder=' '
required
data-testid='forminput-input'
/>
<label
className={styles.form__inputlabel}
htmlFor='pwd1'
data-testid='forminput-inputlabel'
>
wachtwoord
<span className={styles.form__inputlabelvalmsg}>
+31652693 of 0652786518
</span>
</label>
</div>
</div>
css module.scss
#mixin inputlabel-defaults() {
font-size: 1.5em;
align-self: center;
}
.form {
&__inputwrapper {
display: flex;
margin-bottom: 10px;
position: relative;
background: var(--theme_form_field_bg_color);
border-radius: 4px;
}
&__inputfieldwrapper {
display: flex;
}
&__inputsymbol {
display: flex;
align-self: center;
//align-items: center;
padding-left: 10px;
pointer-events: none;
color: var(--theme_fg_color);
font-size: 1.5em;
transition: all 0.4s;
filter: var(--theme_fg_color_filter)
}
&__inputlabel {
position: absolute;
transition: .3s all ease;
#include inputlabel-defaults();
}
&__inputlabelvalmsg {
display: none;
}
&__inputfield {
align-self: center;
//line-height: 1.2;
font-size: 1.5em;
height: 50px;
color: var(--theme_fg_color);
background: none;
outline: none;
border: none;
max-width: 280px;
min-width: 250px;
overflow: visible;
touch-action: manipulation;
&:focus-within ~ .form__inputlabel {
top: 5px;
font-size: .5em;
align-self: start;
}
&:not(:placeholder-shown) ~ .form__inputlabel {
color: red;
top: 5px;
font-size: .5em;
align-self: start;
}
&:placeholder-shown ~ .form__inputlabel {
top: unset;
#include inputlabel-defaults();
}
}
}

How to change the style of the navbar on scrolling?

I have created a navbar. This navbar should change color when scrolling. I have only managed so far that the background color changes. However, I also want the text colors to change as well as the icons. I would make now with each className the query, whether active or not. But this is very redundant. Is there an option that covers everything? By saying if the user scrolls and the navbar changes color, then the textcolor and everything else should also change? Would it make sense to say if navbar changes then call another new css? Is that possible? If so how do I do that?
Is there an option that makes this easier?
Navbar.js
import React, { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { Button } from '../buttons/Button';
import './Navbar.css';
function Navbar() {
const [click, setClick] = useState(false);
const [button, setButton] = useState(true);
const [navbar, setNavbar ] = useState(false);
const handleClick = () => setClick(!click);
const closeMobileMenu = () => setClick(false);
const showButton = () => {
if(window.innerWidth <= 960) {
setButton(false);
}
else {
setButton(true);
}
};
useEffect(() => {
showButton();
}, []);
window.addEventListener('resize', showButton);
const changeBackground = () => {
if(window.scrollY >= 80) {
setNavbar(true);
}
else {
setNavbar(false);
}
};
window.addEventListener('scroll', changeBackground);
return (
<>
<nav className={navbar ? 'navbar active' : 'navbar'}>
<div className="navbar-container">
<Link to="/" className="navbar-logo" onClick={closeMobileMenu}>
APPNAME<i className="fab fa-typo3"></i>
</Link>
<div className="menu-icon" onClick={handleClick}>
<i className={click ? 'fas fa-times': 'fas fa-bars'} />
</div>
<ul className={click ? 'nav-menu active' : 'nav-menu'}>
<li className='nav-item'>
<Link to="/" className='nav-links' onClick={closeMobileMenu}>
Home
</Link>
</li>
<li className='nav-item'>
<Link to="/services" className='nav-links' onClick={closeMobileMenu}>
Services
</Link>
</li>
<li className='nav-item'>
<Link to="/products" className='nav-links' onClick={closeMobileMenu}>
Products
</Link>
</li>
<li className='nav-item'>
<Link to="/sign-up" className='nav-links-mobile' onClick={closeMobileMenu}>
Sign up
</Link>
</li>
</ul>
{button && <Button buttonStyle='btn--outline'>GET STARTED</Button>}
</div>
</nav>
</>
)
}
export default Navbar
Navbar.css
.navbar {
background: #2b41cb;
height: 80px;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.2rem;
position: sticky;
top: 0;
z-index: 999;
}
/* AS YOU CAN SEE HERE IS THE ACTIVE PART */
.navbar.active {
/*background: linear-gradient(90deg, rgb(66, 2, 194) 0%, rgb(0, 78, 194) 100%)*/
background: #fff;
}
.navbar-container {
display: flex;
justify-content: center;
align-items: center;
height: 80px;
max-width: 1500px;
}
.navbar-logo {
color: #fff;
justify-self: start;
margin-left: 20px;
cursor: pointer;
text-decoration: none;
font-size: 2rem;
display: flex;
align-items: center;
}
.navbar-logo.active {
color: #232323;
}
.fa-typo3 {
margin-left: 0.5rem;
font-size: 1.8rem;
}
.nav-menu {
display: grid;
grid-template-columns: repeat(4, auto);
grid-gap: 10px;
list-style: none;
text-align: center;
width: 60vw;
justify-content: end;
margin-right: 2rem;
}
.nav-item {
height: 80px;
}
.nav-links {
color: #fff;
display: flex;
align-items: center;
text-decoration: none;
padding: 0.5rem 1rem;
height: 100%;
}
.nav-links:hover {
border-bottom: 4px solid #fff;
transition: all 0.2s ease-out;
}
.fa-bars {
color: #fff;
}
.nav-links-mobile {
display: none;
}
.menu-icon {
display: none;
}
#media screen and (max-width: 960px) {
.NavbarItems {
position: relative;
}
.nav-menu {
display: flex;
flex-direction: column;
width: 100%;
height: 90vh;
position: absolute;
top: 80px;
left: -100%;
opacity: 1;
transition: all 0.5s ease;
}
.nav-menu.active {
background: #242222;
left: 0;
opacity: 1;
transition: all 0.5s ease;
z-index: 1;
}
.nav-links {
text-align: center;
padding: 2rem;
width: 100%;
display: table;
}
.nav-links:hover {
background-color: #fff;
color: #242424;
border-radius: 0;
}
.navbar-logo {
position: absolute;
top: 0;
left: 0;
transform: translate(25%, 50%);
}
.menu-icon {
display: block;
position: absolute;
top: 0;
right: 0;
transform: translate(-100%, 60%);
font-size: 1.8rem;
cursor: pointer;
}
.fa-times {
color: #fff;
font-size: 2rem;
}
.nav-links-mobile {
display: block;
text-align: center;
margin: 2rem auto;
border-radius: 4px;
width: 80%;
text-decoration: none;
font-size: 1.5rem;
background-color: transparent;
color: #fff;
padding: 14px 20px;
border: 1px solid #fff;
transition: all 0.3s ease-out;
}
.nav-links-mobile:hover {
background: #fff;
color: #242424;
transition: 250ms;
}
}
What I would like is for the entire navbar to be in white and the text and icons to be in black when scrolled. If not it should stay as it is, blue background and white font color.
But this is very redundant. Is there an option that covers everything?
Yes, just add a new class name for the element state and then use that class to style everything including the child elements. So in your case you can do:
.navbar {
background: #2b41cb;
height: 80px;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.2rem;
position: sticky;
top: 0;
z-index: 999;
}
.navbar-container {
display: flex;
justify-content: center;
align-items: center;
height: 80px;
max-width: 1500px;
}
.navbar-logo {
color: #fff;
justify-self: start;
margin-left: 20px;
cursor: pointer;
text-decoration: none;
font-size: 2rem;
display: flex;
align-items: center;
}
/* Active style overrides */
.navbar.active {
background: #fff;
}
.navbar.active .navbar-logo {
color: #232323;
}
Would it make sense to say if navbar changes then call another new css? Is that possible? If so how do I do that?
I think that is also possible, you can use JS to do that but I think adding a state class name is simpler and easier to reason about.

After adding the pop-up menu, the rest of the content disappear and the overflow-x:hidden does not work

After adding the pop-up menu, the content inside "main" disappear and the overflow-x:hidden of the body does not work. Does anyone know why?
const slide = () => {
const burger = document.querySelector(".burger");
const menu = document.querySelector(".menu");
const links = document.querySelectorAll(".menu div");
//Toggle Menu
burger.addEventListener("click", () => {
menu.classList.toggle("menupop");
})
}
slide();
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: calc(16px + 0.25vw);
overflow: scroll;
font-family: 'Antic Slab', serif;
}
body {
min-height: 100vh;
overflow-x: hidden;
}
main {
display: grid;
width: 100vw;
grid-template-columns: 50% 50%;
grid-template-rows: 50% 50% 50% 50%;
}
header {
grid-column: 1/3;
grid-row: 1/2;
background-color: pink;
}
#rose {
grid-column: 1/2;
grid-row: 2/3;
background-color: hotpink;
}
#rose-img {
grid-column: 2/3;
grid-row: 2/3;
background-color: rgb(134, 184, 204);
}
#tree {
grid-column: 1/3;
grid-row: 3/4;
background-color: lawngreen;
}
#about-us {
grid-column: 1/2;
grid-row: 4/5;
background-color: lightcoral;
}
#contact-us {
grid-column: 2/3;
grid-row: 4/5;
background-color: orange;
}
.burger {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-content: space-around;
width: 50px;
height: 50px;
cursor: pointer;
display: none;
}
.line1,
.line2,
.line3 {
flex: 1 1 1;
width: 80%;
height: 5%;
background: black;
border-radius: 5px;
box-shadow: 1px 1px grey;
transition: all .5s ease-in-out;
}
.a {
transform: translateY(2px);
}
.b {
transform: translateY(-2px);
}
nav {
display: flex;
justify-content: flex-end;
align-items: center;
height: 50px;
background-color: rgb(245, 249, 250, 0.5);
padding: 5px 10px;
position: sticky;
top: 0;
}
ul {
display: flex;
list-style: none;
justify-content: space-around;
width: 40%
}
li a {
text-decoration: none;
color: grey;
}
.logo {
font-family: 'Italianno', cursive;
margin-right: auto;
font-size: 30px;
font-weight: bold;
}
.menu {
display: flex;
flex-direction: column;
justify-content: flex-start;
background-color: rgba(91, 126, 172, 0.5);
height: 100vh;
width: 50vw;
position: absolute;
top: 50px;
right: 0;
transform: translateX(100%);
transition: transform 0.5s ease-in;
}
.menupop {
transform: translateX(0%);
}
.menupop div {
animation-name: menuFade;
animation-duration: 1s;
animation-delay: 2s;
animation-timing-function: ease;
animation-fill-mode: forwards;
}
.menu div {
width: 100%;
height: 20%;
background-color: rgb(245, 249, 250, 0.6);
margin-bottom: 1px;
display: flex;
justify-content: center;
align-items: center;
transform: translateX(100%);
}
.menu div a {
text-decoration: none;
}
#keyframes menuFade {
from {
transform: translateX(100%);
}
to {
transform: translateX(0px);
}
}
#media only screen and (max-width: 600px) {
ul {
width: 60%;
}
}
#media only screen and (max-width: 430px) {
.burger {
display: flex;
}
ul {
display: none;
}
}
<body>
<nav>
<div class="logo">Logo</div>
<ul>
<li>Flower</li>
<li>Tree</li>
<li>About us</li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<div class="menu">
<div class="first">Flower</div>
<div class="second">Tree</div>
<div class="third">About us</div>
</div>
<main>
<header id="jumbotron">
</header>
<section id="rose">
</section>
<section id="rose-img">
</section>
<section id="tree">
<div class="privacy">
</div>
<div class="hedge">
</div>
</section>
<section id="about-us">
</section>
<section id="contact-us">
</section>
</main>
</body>
In your CSS, remove overflow: scroll;.
This should prevent your side menu from staying outside of your viewport width, because with overflow: scroll;, you're allowing the browser to have your side menu out of view, making it only reachable via scrolling.
I'd also like to add that your side menu transition is too long.
If you think about it from a user experience, a user might think that your site is slow.
I've shortened the transition to 200ms and removed the animation-duration and animation-delay. It'll seem more responsive to users now.
EDIT: Also, is anyone else finding it weird how when you use "Run Snippet" on Stackoverflow, use Full Page view, then try to shrink it down to mobile width, the media queries aren't working properly? It works fine when I run the code in VSCode and launch a Live Server, but for some reason, Stackoverflow's Run Snippet is being buggy...
EDIT 2: I've added content to each of your div tags and section tags. So the reason why you couldn't see any content under the main tag was because the height of all of your containers (div, section, main, and header tags) is, by default, auto. If height is auto, then the container will shrink or grow based on the content inside of the container. In your case, you had NO content in ANY of your containers, hence why all of your containers weren't visible, they were essentially at 0px height.
Now that I've added content, you can see your containers.
const slide = () => {
const burger = document.querySelector(".burger");
const menu = document.querySelector(".menu");
const links = document.querySelectorAll(".menu div");
//Toggle Menu
burger.addEventListener("click", () => {
menu.classList.toggle("menupop");
})
}
slide();
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: calc(16px + 0.25vw);
font-family: 'Antic Slab', serif;
}
body {
min-height: 100vh;
overflow-x: hidden;
}
main {
display: grid;
width: 100vw;
grid-template-columns: 50% 50%;
grid-template-rows: 50% 50% 50% 50%;
}
header {
grid-column: 1/3;
grid-row: 1/2;
background-color: pink;
}
#rose {
grid-column: 1/2;
grid-row: 2/3;
background-color: hotpink;
}
#rose-img {
grid-column: 2/3;
grid-row: 2/3;
background-color: rgb(134, 184, 204);
}
#tree {
grid-column: 1/3;
grid-row: 3/4;
background-color: lawngreen;
}
#about-us {
grid-column: 1/2;
grid-row: 4/5;
background-color: lightcoral;
}
#contact-us {
grid-column: 2/3;
grid-row: 4/5;
background-color: orange;
}
.burger {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-content: space-around;
width: 50px;
height: 50px;
cursor: pointer;
display: none;
}
.line1,
.line2,
.line3 {
flex: 1 1 1;
width: 80%;
height: 5%;
background: black;
border-radius: 5px;
box-shadow: 1px 1px grey;
transition: all .5s ease-in-out;
}
.a {
transform: translateY(2px);
}
.b {
transform: translateY(-2px);
}
nav {
display: flex;
justify-content: flex-end;
align-items: center;
height: 50px;
background-color: rgb(245, 249, 250, 0.5);
padding: 5px 10px;
position: sticky;
top: 0;
}
ul {
display: flex;
list-style: none;
justify-content: space-around;
width: 40%
}
li a {
text-decoration: none;
color: grey;
}
.logo {
font-family: 'Italianno', cursive;
margin-right: auto;
font-size: 30px;
font-weight: bold;
}
.menu {
display: flex;
flex-direction: column;
justify-content: flex-start;
background-color: rgba(91, 126, 172, 0.5);
height: 100vh;
width: 50vw;
position: absolute;
top: 50px;
right: 0;
transform: translateX(100%);
transition: transform 200ms ease-in;
}
.menupop {
transform: translateX(0%);
}
.menupop div {
animation-name: menuFade;
animation-timing-function: ease;
animation-fill-mode: forwards;
}
.menu div {
width: 100%;
height: 20%;
background-color: rgb(245, 249, 250, 0.6);
margin-bottom: 1px;
display: flex;
justify-content: center;
align-items: center;
transform: translateX(100%);
}
.menu div a {
text-decoration: none;
}
#keyframes menuFade {
from {
transform: translateX(100%);
}
to {
transform: translateX(0px);
}
}
#media only screen and (max-width: 600px) {
ul {
width: 60%;
}
}
#media only screen and (max-width: 430px) {
.burger {
display: flex;
}
ul {
display: none;
}
}
<body>
<nav>
<div class="logo">Logo</div>
<ul>
<li>Flower</li>
<li>Tree</li>
<li>About us</li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<div class="menu">
<div class="first">Flower</div>
<div class="second">Tree</div>
<div class="third">About us</div>
</div>
<main>
<header id="jumbotron">
This is a header with ID "jumbotron".
</header>
<section id="rose">
This is a section with ID "rose".
</section>
<section id="rose-img">
this is a section with ID "rose-img".
</section>
<section id="tree">
<div class="privacy">
This is a div with class "privacy".
</div>
<div class="hedge">
This is a div with class "hedge".
</div>
</section>
<section id="about-us">
This is a section with ID "about-us".
</section>
<section id="contact-us">
This is a section with ID "contact-us".
</section>
</main>
</body>

Vertically align h1 tag

I'm working on a Meteor app, using StylusGrid (a flexbox grid) for my layout and Transformicons for my menu button.
How can I vertically align this h1?
HTML:
<header class="toolbar">
<section>
<div class="menu-button">
<button type="button" class="tcon tcon-menu--xcross" aria-label="toggle menu">
<span class="tcon-menu__lines" aria-hidden="true"></span>
<span class="tcon-visuallyhidden">toggle menu</span>
</button>
</div>
<h1>MyApp</h1>
</section>
<section class="links">
Help
</section>
</header>
CSS on jsFiddle.
I want the H1 tag to be in line with the button in, vertically centered.
I set the flexbox grid rules so that it would vertically center the contents, which is working fine for the menu button and help link.
But the H1 is out of place. How can I fix it?
Add to h1 CSS:
vertical-align: middle;
Works for me: JSFiddle.
Snippet:
.toolbar {
display: flex;
flex-direction: row;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
background-color: #fff;
}
.toolbar section {
flex-basis: calc(100% * 0.5 - 1.25rem);
-ms-flex-preferred-size: calc(100% * 0.5 - 1.25rem);
margin: 0.625rem;
-ms-flex-item-align: center;
align-self: center;
}
.toolbar .menu-button {
display: inline-block;
}
.toolbar h1 {
display: inline-block;
margin: 0px;
padding: 0px;
vertical-align: middle;
}
.toolbar .links {
text-align: right;
}
.tcon {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: none;
cursor: pointer;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
height: 40px;
transition: 0.3s;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
width: 40px;
background: transparent;
outline: none;
-webkit-tap-highlight-color: transparent;
-webkit-tap-highlight-color: transparent;
}
.tcon > * {
display: block;
}
.tcon:hover,
.tcon:focus {
outline: none;
}
.tcon::-moz-focus-inner {
border: 0;
}
.tcon-menu__lines {
display: inline-block;
height: 5.71429px;
width: 40px;
border-radius: 2.85714px;
transition: 0.3s;
background: black;
position: relative;
}
.tcon-menu__lines::before,
.tcon-menu__lines::after {
display: inline-block;
height: 5.71429px;
width: 40px;
border-radius: 2.85714px;
transition: 0.3s;
background: black;
content: '';
position: absolute;
left: 0;
-webkit-transform-origin: 2.85714px center;
transform-origin: 2.85714px center;
width: 100%;
}
.tcon-menu__lines::before {
top: 10px;
}
.tcon-menu__lines::after {
top: -10px;
}
.tcon-transform .tcon-menu__lines {
-webkit-transform: scale3d(0.8, 0.8, 0.8);
transform: scale3d(0.8, 0.8, 0.8);
}
.tcon-menu--xcross {
width: auto;
}
.tcon-menu--xcross.tcon-transform .tcon-menu__lines {
background: transparent;
}
.tcon-menu--xcross.tcon-transform .tcon-menu__lines::before,
.tcon-menu--xcross.tcon-transform .tcon-menu__lines::after {
-webkit-transform-origin: 50% 50%;
transform-origin: 50% 50%;
top: 0;
width: 40px;
}
.tcon-menu--xcross.tcon-transform .tcon-menu__lines::before {
-webkit-transform: rotate3d(0, 0, 1, 45deg);
transform: rotate3d(0, 0, 1, 45deg);
}
.tcon-menu--xcross.tcon-transform .tcon-menu__lines::after {
-webkit-transform: rotate3d(0, 0, 1, -45deg);
transform: rotate3d(0, 0, 1, -45deg);
}
.tcon-visuallyhidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.tcon-visuallyhidden:active,
.tcon-visuallyhidden:focus {
clip: auto;
height: auto;
margin: 0;
overflow: visible;
position: static;
width: auto;
}
<header class="toolbar">
<section>
<div class="menu-button">
<button type="button" class="tcon tcon-menu--xcross" aria-label="toggle menu">
<span class="tcon-menu__lines" aria-hidden="true"></span>
<span class="tcon-visuallyhidden">toggle menu</span>
</button>
</div>
<h1>MyApp</h1>
</section>
<section class="links">
Help
</section>
</header>

Resources