Why is my NavBar's background not covering the last menu item? - css

Something on my website is bothering me.
The last menu item of my Navbar is outside it's container's background:
Here is how my CSS looks like:
.nav-menu {
display: flex;
flex-direction: column;
width: 100%;
height: 280px;
position: absolute;
top: 80px;
left: -100%;
opacity: 1;
transition: all 0.5s ease;
align-items: space-evenly;
}
.nav-menu.active {
display: flex;
flex-direction: column;
align-content: flex-start;
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;
}
}
and HTML generated by a React component looks like this:
<>
<nav className='navbar'>
<div className='navbar-container'>
<Link to='/' className='navbar-logo' onClick={closeMobileMenu}>
LOGO
</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'>
<HashLink to='/#wherewefly' onClick={closeMobileMenu} className='nav-links'>
Where we fly
</HashLink>
</li>
<li className='nav-item'>
<Link
to='/services'
className='nav-links'
onClick={closeMobileMenu}
>
Promotions
</Link>
</li>
<li className='nav-item'>
<Link
to='/products'
className='nav-links'
onClick={closeMobileMenu}
>
Contact
</Link>
</li>
</ul>
{button && <Button buttonStyle='btn--outline'>LOGIN</Button>}
</div>
</nav>
</>
How can I make the last menu item (Contact) be covered by the black background too?
I have tried changing the height but the menu items "follow" and are aligned to the bottom. I can't find out how to change it though.
Edited: Picture has been updated

Remove height: 280px;.
You are using flex-box so you shouldn't be setting the height or width attributes. The idea is to allow the box to be flexible to it's contents.
If you want a fixed height you should be using flex-basis attribute.
EXAMPLE
I have had to convert your react to html to demonstrate but as you can see the code you provided works as expected. This would indicate the issue lies elsewhere in code you have not provided.
.nav-menu {
display: flex;
flex-direction: column;
width: 100%;
position: absolute;
top: 80px;
left: -100%;
opacity: 1;
transition: all 0.5s ease;
align-items: space-evenly;
}
.nav-menu.active {
display: flex;
flex-direction: column;
align-content: flex-start;
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;
}
<nav class='navbar'>
<div clas='navbar-container'>
<a class='navbar-logo'> LOGO
</a>
<div class='menu-icon'>
<i class='fas fa-times' />
</div>
<ul class='nav-menu active'>
<li class='nav-item'>
<a class='nav-links'> Home
</a>
</li>
<li class='nav-item'>
<a class='nav-links'>
Where we fly
</a>
</li>
<li class='nav-item'>
<a class='nav-links'> Promotions
</a>
</li>
<li class='nav-item'>
<a class='nav-links'> Contact
</a>
</li>
</ul>
<Button class='btn--outline'>LOGIN</Button>
</div>
</nav>

Well, the height is fixed in the CSS, if you want it to take the height the content has you need to use "fit-content".

Blockquote
The issue could be the height of the nav-menu. please use min-hight instead. This may fix your issue
.nav-menu {
display: flex;
flex-direction: column;
width: 100%;
min-height: 280px;
position: absolute;
top: 80px;
left: -100%;
opacity: 1;
transition: all 0.5s ease;
align-items: space-evenly;
}

Related

SVG not displaying when the sidebar is closed

I have a sidebar that shows and hides content depending on the collapse status.
Here is a LIVE JS FIDDLE
Instead of using icons, I would like to use SVG images but if I use SVG images there is a jumpy effect during the transition and the SVG disappears when the sidebar is closed.
What I've tried:
.sidebar.close .nav-links li a .sidebarSvg{
opacity: 1;
}
I thought changing the opacity to 1 would do the job but I am doing something wrong.
I also tried with display: block; but it did not work.
Is my SVG wrong?
UPDATE:
I also tried placing the svg outside of the <a> but that makes the jumpy effect worst during the toggle transition.
try this :
.sidebar.close .nav-links li .iocn-link {
width:300px;
}
Now You can try thsi :
let arrow = document.querySelectorAll(".arrow");
for (var i = 0; i < arrow.length; i++) {
arrow[i].addEventListener("click", (e)=>{
let arrowParent = e.target.parentElement.parentElement;//selecting main parent of arrow
arrowParent.classList.toggle("showMenu");
});
}
let sidebar = document.querySelector(".sidebar");
let sidebarBtn = document.querySelector(".bx-menu");
console.log(sidebarBtn);
sidebarBtn.addEventListener("click", ()=>{
sidebar.classList.toggle("close");
});
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;600;700&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
.sidebarSvg{
margin-left: 15px;
margin-right: 15px;
}
.sidebar{
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 290px;
background: #193D4C;
z-index: 100;
transition: all 0.5s ease;
}
.sidebar.close{
width: 78px;
}
.sidebar .logo-details{
height: 60px;
width: 100%;
display: flex;
align-items: center;
}
.logo-icon{
margin-left: 15px;
}
.sidebar .logo-details i{
font-size: 30px;
color: #fff;
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
}
.sidebar .logo-details .logo_name{
font-size: 22px;
color: #fff;
font-weight: 600;
transition: 0.3s ease;
transition-delay: 0.1s;
margin-left:20px;
}
.sidebar.close .logo-details .logo_name{
transition-delay: 0s;
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links{
height: 100%;
padding: 30px 0 150px 0;
overflow: auto;
}
.sidebar.close .nav-links{
overflow: visible;
}
.sidebar .nav-links::-webkit-scrollbar{
display: none;
}
.sidebar .nav-links li{
position: relative;
list-style: none;
transition: all 0.4s ease;
}
.sidebar .nav-links li:hover{
background: #193D4C;
}
.sidebar .nav-links li .iocn-link{
display: flex;
align-items: center;
justify-content: space-between;
}
.sidebar.close .nav-links li .iocn-link{
display: block;
}
.sidebar .nav-links li i{
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
color: #fff;
font-size: 20px;
cursor: pointer;
transition: all 0.3s ease;
}
.sidebar .nav-links li.showMenu i.arrow{
transform: rotate(-180deg);
}
.sidebar.close .nav-links i.arrow{
display: none;
}
.sidebar .nav-links li a{
display: flex;
align-items: center;
text-decoration: none;
}
.sidebar .nav-links li a .link_name{
font-size: 18px;
font-weight: 400;
color: #fff;
transition: all 0.4s ease;
}
.sidebar.close .nav-links li a .link_name{
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links li .sub-menu{
padding: 6px 6px 14px 80px;
margin-top: -10px;
background: #193D4C;
display: none;
}
.sidebar .nav-links li.showMenu .sub-menu{
display: block;
}
.sidebar .nav-links li .sub-menu a{
color: #fff;
font-size: 15px;
padding: 5px 0;
white-space: nowrap;
opacity: 0.6;
transition: all 0.3s ease;
}
.sidebar .nav-links li .sub-menu a:hover{
opacity: 1;
}
.sidebar.close .nav-links li .sub-menu{
position: absolute;
left: 100%;
top: -10px;
margin-top: 0;
padding: 10px 20px;
border-radius: 0 6px 6px 0;
opacity: 0;
display: block;
pointer-events: none;
transition: 0s;
}
.sidebar.close .nav-links li:hover .sub-menu{
top: 0;
opacity: 1;
pointer-events: auto;
transition: all 0.4s ease;
}
.sidebar .nav-links li .sub-menu .link_name{
display: none;
}
.sidebar.close .nav-links li .sub-menu .link_name{
font-size: 18px;
opacity: 1;
display: block;
}
.sidebar .nav-links li .sub-menu.blank{
opacity: 1;
pointer-events: auto;
padding: 3px 20px 6px 16px;
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links li:hover .sub-menu.blank{
top: 50%;
transform: translateY(-50%);
}
.sidebar .profile-details{
position: fixed;
bottom: 0;
width: 290px;
display: flex;
align-items: center;
justify-content: space-between;
background: #1d1b31;
padding: 12px 0;
transition: all 0.5s ease;
}
.sidebar.close .profile-details{
background: none;
}
.sidebar.close .profile-details{
width: 78px;
}
.sidebar .profile-details .profile-content{
display: flex;
align-items: center;
}
.sidebar .profile-details img{
height: 52px;
width: 52px;
object-fit: cover;
border-radius: 16px;
margin: 0 14px 0 12px;
background: #1d1b31;
transition: all 0.5s ease;
}
.sidebar.close .profile-details img{
padding: 10px;
}
.sidebar .profile-details .profile_name,
.sidebar .profile-details .job{
color: #fff;
font-size: 18px;
font-weight: 500;
white-space: nowrap;
}
.sidebar.close .profile-details i,
.sidebar.close .profile-details .profile_name,
.sidebar.close .profile-details .job{
display: none;
}
.sidebar .profile-details .job{
font-size: 12px;
}
.home-section{
position: relative;
background: #E4E9F7;
height: 100vh;
left: 290px;
width: calc(100% - 260px);
transition: all 0.5s ease;
}
.sidebar.close ~ .home-section{
left: 78px;
width: calc(100% - 78px);
}
.home-section .home-content{
height: 60px;
display: flex;
align-items: center;
}
.home-section .home-content .bx-menu,
.home-section .home-content .text{
color: #11101d;
font-size: 35px;
}
.home-section .home-content .bx-menu{
margin: 0 15px;
cursor: pointer;
}
.home-section .home-content .text{
font-size: 26px;
font-weight: 600;
}
.userInitials {
height: 38px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
width: 38px;
text-align: center;
vertical-align: middle;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
background: white;
color: #193D4C;
font-weight: 600;
margin-bottom: 20px;
margin-left: 20px;
}
#media (max-width: 420px) {
.sidebar.close .nav-links li .sub-menu{
display: none;
}
}
.dont-break {
min-width: 100%;
white-space: nowrap;
overflow: hidden;
}
.centered-profile {
display:inline-block;
}
.staff-position{
font-size: small !important;
margin-top: 40px !important;
}
.staff-nav-holder {
margin-left: 20px;
}
.sidebar.close .nav-links li .iocn-link {
width:300px;
}
<!DOCTYPE html>
<!-- Created by CodingLab |www.youtube.com/CodingLabYT-->
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<!-- Boxiocns CDN Link -->
<link href='https://unpkg.com/boxicons#2.0.7/css/boxicons.min.css' rel='stylesheet'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="sidebar close">
<div class="logo-details">
<div class="logo-icon"><svg xmlns="http://www.w3.org/2000/svg" width="43.878" height="44.07" viewBox="0 0 43.878 44.07">
<g id="g110" transform="translate(24.953 4.408)">
<path id="path4" d="M-8.04,26.725A10.416,10.416,0,0,1-12.112,12.6,10.437,10.437,0,0,1,.23,7.767L4.939-3.049a22.3,22.3,0,0,0-28.5,13.106A22.166,22.166,0,0,0-12.748,37.54Z" fill="#f8e3a9"/>
<path id="path6" d="M6.523-2.315,1.815,8.5A10.417,10.417,0,0,1,5.887,22.623,10.438,10.438,0,0,1-6.455,27.459l-4.708,10.815a22.3,22.3,0,0,0,28.5-13.1A22.117,22.117,0,0,0,6.523-2.315" transform="translate(0.196 0.03)" fill="#f8e3a9"/>
<path id="path8" d="M-3.265,8.85a8.525,8.525,0,0,1,8.525,8.525A8.525,8.525,0,0,1-3.265,25.9a8.525,8.525,0,0,1-8.525-8.526h0A8.608,8.608,0,0,1-3.265,8.85" transform="translate(0.187 0.189)" fill="#f8e3a9"/>
</g>
</svg>
</div>
<span class="logo_name dont-break">STACKOVERFLOW</span>
</div>
<ul class="nav-links">
<li>
<div class="iocn-link">
<a href="#">
<span class="userInitials">JW</span>
<div class="col-9 staff-nav-holder">
<span class="link_name dont-break centered-profile">John Walker</span>
<span class="link_name staff-position">PM</span>
</div>
</a>
<i class='bx bxs-chevron-down arrow centered-profile' ></i>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="#">John Walker</a></li>
<li>Customize your homepage</li>
<li>Change your password</li>
<li>Logout</li>
</ul>
</li>
<li>
<div class="iocn-link">
<a href="#">
<svg class="sidebarSvg" xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="white" viewBox="0 0 32 32"><g id="icon_layer" data-name="icon layer"><path class="cls-1" d="M20.5,12H16.55a.5.5,0,0,1-.5-.5.5.5,0,0,1,.5-.5H20.5a.51.51,0,0,1,.5.5A.5.5,0,0,1,20.5,12Z"/><path class="cls-1" d="M20.5,17H16.55a.5.5,0,0,1,0-1H20.5a.5.5,0,0,1,0,1Z"/><path class="cls-1" d="M20.5,22H16.55a.5.5,0,0,1,0-1H20.5a.5.5,0,0,1,0,1Z"/><path class="cls-1" d="M12.27,18h0a.49.49,0,0,1-.37-.18l-.8-1a.5.5,0,1,1,.76-.64l.44.52,1.44-1.58a.5.5,0,0,1,.74.67l-1.83,2A.51.51,0,0,1,12.27,18Z"/><path class="cls-1" d="M22.44,5.5H21.32a.5.5,0,0,0,0,1h1.12A1.07,1.07,0,0,1,23.5,7.56V24.44a1.07,1.07,0,0,1-1.06,1.06H9.56A1.07,1.07,0,0,1,8.5,24.44V7.56A1.07,1.07,0,0,1,9.56,6.5h1.22a.5.5,0,1,0,0-1H9.56A2.06,2.06,0,0,0,7.5,7.56V24.44A2.06,2.06,0,0,0,9.56,26.5H22.44a2.06,2.06,0,0,0,2.06-2.06V7.56A2.06,2.06,0,0,0,22.44,5.5Z"/><path class="cls-1" d="M12.37,7.73h7.27a.5.5,0,0,0,.5-.5V4.78a.5.5,0,0,0-.5-.5H18a2,2,0,0,0-3.88,0H12.37a.5.5,0,0,0-.5.5V7.23A.5.5,0,0,0,12.37,7.73Zm.5-2.45h1.66a.5.5,0,0,0,.5-.5,1,1,0,0,1,2,0,.5.5,0,0,0,.5.5h1.6V6.73H12.87Z"/><path class="cls-1" d="M11.09,11.83l.8,1a.53.53,0,0,0,.37.18h0a.48.48,0,0,0,.37-.17l1.83-2a.5.5,0,0,0-.74-.68l-1.44,1.58-.44-.52a.5.5,0,1,0-.76.64Z"/><path class="cls-1" d="M13.5,23h-2a.5.5,0,0,1-.5-.5v-2a.5.5,0,0,1,.5-.5h2a.5.5,0,0,1,.5.5v2A.5.5,0,0,1,13.5,23ZM12,22h1V21H12Z"/></g></svg>
<span class="link_name">Projects</span>
</a>
<i class='bx bxs-chevron-down arrow' ></i>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="#">Category</a></li>
<li>Create a New Project</li>
<li>See All Projects</li>
</ul>
</li>
<li>
<div class="iocn-link">
<a href="#">
<i class='bx bx-book-alt' ></i>
<span class="link_name">Posts</span>
</a>
<i class='bx bxs-chevron-down arrow' ></i>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="#">Posts</a></li>
<li>Web Design</li>
<li>Login Form</li>
<li>Card Design</li>
</ul>
</li>
<li>
<a href="#">
<i class='bx bx-pie-chart-alt-2' ></i>
<span class="link_name">Analytics</span>
</a>
</li>
<li>
<a href="#">
<i class='bx bx-menu'></i>
<span class="link_name dont-break">Collapse sidebar</span>
</a>
</li>
</ul>
</div>
<section class="home-section">
<div class="home-content">
<span class="text"></span>
</div>
</section>
</body>
</html>

How to move navlinks down the page

Every time I try to move the navlinks/navbar down by about 25px, the clickable link stays at the top however the text appears where I move it to therefore the navlinks are no longer clickable.
How can I move the navbar down and ensure that the actual text is clickable?
Note: I've tried using margin and padding so many times. The links aren't clickable at all when I use margin.
UPDATE:The issue is related to the animated background because when I removed the background, the navbar worked fine. I've updated my post with the code for the background.
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
background-color: black;
color: white;
font-size: 20px;
}
.navbar-links ul {
margin: 0;
padding: 0;
display: flex;
}
.navbar-links li {
list-style: none;
}
.navbar-links li a {
text-decoration: none;
color: white;
padding-left: 1rem;
padding-right: 1em;
padding-top: 1em;
display: block;
}
.navbar-links li:hover {
background: #555;
}
.animation-area {
background: rgb(22,168,194);
background: linear-gradient(0deg, rgba(22,168,194,1) 0%, rgba(27,28,28,1)
100%);
width: 100%;
height: 100vh;
}
.box-area{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 97%;
overflow: hidden;
}
.box-area .box-item{
position: absolute;
display: block;
list-style: none;
width: 25px;
height: 25px;
background: rgba(255, 255, 255, 0.2);
animation: animatedSquares 20s linear infinite;
bottom: -150px;
}
.box-area .box-item:nth-child(1){
left: 86%;
width: 80px;
height: 80px;
animation-delay: 0s
}
.box-area .box-item:nth-child(2){
left: 12%;
width: 30px;
height: 30px;
animation-delay: 1.5s;
animation-duration: 10s;
}
.box-area .box-item:nth-child(3){
left: 70%;
width: 100px;
height: 100px;
animation-duration: 5.5s;
}
#keyframes animatedSquares{
0%{
transform: translateY(0) rotate(0deg);
opacity: 1;
}
100%{
transform: translateY(-800px) rotate(360deg);
opacity: 0;
}
}
<div class="banner-text">
<nav class="navbar">
<a href="#" class="toggle-button">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</a>
<div class="navbar-links">
<ul>
<li><a class="navlink" href="#">Page 1</a></li>
<li><a class="navlink" href="#">Page 2</a></li>
<li><a class="navlink" href="#">Page 3</a></li>
<li><a class="navlink" href="#">Page 4</a></li>
</ul>
</div>
</nav>
</div>
<div class="animation-area">
<ul class="box-area">
<li class="box-item"></li>
<li class="box-item"></li>
<li class="box-item"></li>
<li class="box-item"></li>
<li class="box-item"></li>
<li class="box-item"></li>
</ul>
</div>
Try this
.navbar-links li {
list-style: none;
margin-top: 1rem;
}
.navbar-links li a {
text-decoration: none;
color: white;
padding: .363rem;
display: block;
}
I've solved the issue! I have an animated background on the home screen and the background had position:absolute; which conflicted with the navbar. I just removed position: absolute; from the background and styled it differently.

100% height for vertical sticky menu - doesn't work

I'm trying to fit my sticky left menu to the height of my content, but I'm not be able to do it.
I try adding height: 100% to all parents div, but nothing happens
My code is: (before is and )
<main>
<div class="container">
<div class="content-wrapper">
<router-view />
</div>
<div class="navigation__menu">
<div
class="container-menu"
:class="{'show': this.$store.getters.showSidebar}">
<main-menu
#click.native="showNav" />
<menu-options />
</div>
</div>
</div>
</main>
<template>
<div id="main-menu">
<div class="control">
<i
class="fas fa-angle-double-right" />
</div>
</div>
</template>
<template>
<div id="menu-options">
<div
class="navigation-icons-menu">
<a
title="Home"
href="/"><i class="fas fa-home" /></a>
<a
title="FIG"
href="/fig-console"><i class="fas fa-clipboard-list" /></a>
<a
title="Service client"
href="/"><i class="fas fa-users" /></a>
<a
title="Budget"
href="/"><i class="fas fa-file-invoice" /></a>
<a
title="Contracting"
href="/"><i class="fas fa-file-contract" /></a>
<a
title="Invoicing"
href="/"><i class="fas fa-file-invoice-dollar" /></a>
<a
title="Administration"
href="/"><i class="fas fa-cogs" /></a>
</div>
<div
v-if="this.$store.getters.showSidebar"
class="navigation-links-menu">
<transition-group name="fade">
<div
v-show="this.$store.getters.showLink"
key="1">
<a
title="Home"
href="/">Home</a>
</div>
<div
v-show="this.$store.getters.showLink"
key="2">
<a
title="FIG"
href="/fig-console">FIG</a>
</div>
<div
v-show="this.$store.getters.showLink"
key="3">Service client</div>
<div
v-show="this.$store.getters.showLink"
key="4">Budget</div>
<div
v-show="this.$store.getters.showLink"
key="5">Contracting</div>
<div
v-show="this.$store.getters.showLink"
key="6">Invoicing</div>
<div
v-show="this.$store.getters.showLink"
key="7">Administration</div>
</transition-group>
</div>
</div>
</template>
.container-menu {
position: absolute;
top: 65px;
padding-top: 10px;
left: 0;
width: 62px;
min-height: 100%;
height: 100%;
background-color: $navy;
border: solid $white;
border-width: 0 1px 0 0;
z-index: 1001;
transition: all .5s ease-in-out;
.control {
display: flex;
justify-content: center;
align-items: center;
//width: 50px;
margin-bottom: 10px;
color: $white;
i {
font-size: 2rem;
cursor: pointer;
transition: all .5s ease-in-out;
}
}
&.show {
width: 170px;
.control > i {
color: $white;
transform: rotateZ(-180deg);
}
}
.navigation-icons-menu {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 50px;
float: left;
i {
color: $white;
font-size: 2rem;
padding: 10px 0;
cursor: pointer;
transition: all .5s ease-in-out;
&:hover {
color: $white;
}
}
}
.navigation-links-menu {
//padding:14px;
float: left;
color: $white;
div {
font-size: 1.35rem;
padding: 10px;
cursor: pointer;
#include breakpoint-only(tablet) {
font-size: 7px;
padding: 10px 5px;
}
a {
color: $white;
}
}
}
}
vh will solve your problem.
Instead of a pixel or percentage value. Use vh which stands for "viewport height".
An element with height: 100vh will be given a height the full height of the viewport.
.container-menu {
position: absolute;
top: 65px;
padding-top: 10px;
left: 0;
width: 62px;
height: 100vh;
background-color: $navy;
border: solid $white;
border-width: 0 1px 0 0;
z-index: 1001;
transition: all .5s ease-in-out;
.control {
display: flex;
justify-content: center;
align-items: center;
//width: 50px;
margin-bottom: 10px;
color: $white;
i {
font-size: 2rem;
cursor: pointer;
transition: all .5s ease-in-out;
}
}
&.show {
width: 170px;
.control > i {
color: $white;
transform: rotateZ(-180deg);
}
}
.navigation-icons-menu {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 50px;
float: left;
i {
color: $white;
font-size: 2rem;
padding: 10px 0;
cursor: pointer;
transition: all .5s ease-in-out;
&:hover {
color: $white;
}
}
}
.navigation-links-menu {
//padding:14px;
float: left;
color: $white;
div {
font-size: 1.35rem;
padding: 10px;
cursor: pointer;
#include breakpoint-only(tablet) {
font-size: 7px;
padding: 10px 5px;
}
a {
color: $white;
}
}
}
}

CSS transform transition issue

I am trying to realize a flipping card menu using only HTML & CSS. It is almost done except that the back side of the card takes time to display when receiving the first hover state. It's kind of doing the smooth transition move just for 90deg, then it goes instantly to display the final outcome (No more smooth transition done for the last 90deg).
After the first hover, everything goes fine.
Any suggestions?
EDIT: the snippet below has been edited to fit the correct answer.
#import url('https://fonts.googleapis.com/css?family=Open+Sans:400,700&display=swap');
.main{
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: 'Open Sans', sans-serif;
background-color: #000;
}
.header{
color:white;
font-size: 2vh;
margin-bottom: 2vh;
}
.header a{
text-decoration: none;
color: white;
font-weight: bold;
}
.card{
background-color: transparent;
width: 30vh;
height: 50vh;
perspective: 1000px;
perspective-origin: center;
margin-right: 0.5vh;
}
.card > .card-container{
position: relative;
width: 100%;
height: 100%;
transition: 1s transform ease;
transform-style: preserve-3d;
background-color: transparent;
}
.card:hover > .card-container{
transform: rotateY(180deg);
}
.card-container > .front,.card-container > .back {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.card-container > .front{
background-image: linear-gradient(to bottom right,red, yellow);
display: flex;
justify-content: center;
align-items: center;
border-radius: 0.5vh;
color: white;
font-size: 3vh;
cursor: pointer;
backface-visibility: hidden;
}
.card-container > .back{
background-color: transparent;
color: white;
font-size: 3vh;
transform: rotateY(180deg);
cursor: pointer;
}
.back > ul{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
list-style: none;
padding: 0;
margin: 0;
width: 100%;
height: 100%;
perspective: 1000px;
perspective-origin: center ;
}
.back > ul > li{
text-align: center;
height: calc(100% - (0.2vh * 4) /5);
width: 100%;
transition: 1s transform ease;
transform-style: preserve-3d;
}
.back > ul > li:not(:last-child){
margin-bottom: 0.2vh;
}
.back > ul > li > .child-front, .back > ul > li > .child-back {
backface-visibility: hidden;
width: 100%;
height: 100%;
position: absolute;
top:0;
left: 0;
border-radius: 0.5vh;
}
.back > ul > li > .child-front{
background-image: linear-gradient(to bottom left,red, orange);
display: flex;
justify-content: center;
align-items: center;
}
.back > ul > li > .child-back{
background-color: orange;
transform: rotateX(180deg);
display: flex;
justify-content: center;
align-items: center;
}
.back > ul > li:hover{
transform: rotateX(180deg);
}
.child-back span, .child-front span{
color: white;
display: block;
}
.child-back span{
font-weight: bold;
}
<div class="main">
<div class="header">
Find me on Github
</div>
<div class="card">
<div class="card-container">
<div class="front">
<span>Hover here</span>
</div>
<div class="back">
<ul class="menu">
<li class="child">
<div class="child-front"><span>Hover here</span></div>
<div class="child-back"><span>ITEM1</span></div>
</li>
<li class="child">
<div class="child-front"><span>Hover here</span></div>
<div class="child-back"><span>ITEM2</span></div>
</li>
<li class="child">
<div class="child-front"><span>Hover here</span></div>
<div class="child-back"><span>ITEM3</span></div>
</li>
<li class="child">
<div class="child-front"><span>Hover here</span></div>
<div class="child-back"><span>ITEM4</span></div>
</li>
<li class="child">
<div class="child-front"><span>Hover here</span></div>
<div class="child-back"><span>ITEM5</span></div>
</li>
</ul>
</div>
</div>
</div>
</div>
Delete backface-visibility: hidden;:
.card-container > .front,.card-container > .back {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
It actually rotates 180deg but because of backface-visibility you don't see the whole transform. It shows you after the rotate finishes.

Stop flex overlapping

I have the following navigation which I have made responsive by using display:flex:
#header-nav { display: flex; flex-grow: 1; background: #707276; background: rgba(112,114,118,0.75); }
#header-nav .nav-item { display: flex; flex-grow: 1; flex-basis: 0; }
#header-nav .nav-link { display: block; color: #ffffff; display: flex; flex-grow: 1; justify-content: center; align-items: center; white-space: nowrap; }
#header-nav > .nav-item > .nav-link { box-sizing: border-box; text-transform: uppercase; text-decoration: none; padding: 15px 0; position: relative; transition: color 0.5s ease-in-out; font-size: 115.385%; font-family: VegurRegular; }
#header-nav > .nav-item > .nav-link:hover { color: #000000; }
#header-nav > .nav-item > .nav-link:after { content: ''; display: block; position: absolute; bottom: 0; left: 0; right: 0; height: 5px; opacity: 0; transition: opacity 0.5s ease-in-out; background-color: #36383a; }
#header-nav > .nav-item > .nav-link:hover:after { opacity: 0.8; }
#header-nav .home { flex-grow: 0; flex-basis: auto; padding: 0 50px; }
#header-nav .nav-item.home > .nav-link { display: block; }
#header-nav .nav-item.home > .nav-link:after { display: none; }
<ul id="header-nav">
<li class="nav-item home">
<a href="/" class="nav-link">
<span id="logo-text" class="sprite">Logo</span>
</a>
</li>
<li class="nav-item">
Shop
</li>
<li class="nav-item">
Tiling Ideas
</li>
<li class="nav-item">
Advice
</li>
<li class="nav-item">
Find a Retailer
</li>
</ul>
As you can see, the logo stays the same width, whilst the rest is responsive. But if you use the fullpage link and then make the width of the screen smaller, you will see the links start to overlap each other. Is there any way to stop this from happening using flex?
I know I can find a route with using display table that would achieve the same thing but I would prefer to use display flex.
Try removing the white-space: nowrap; as it is is inherently not responsive.
#header-nav {
display: flex;
flex-grow: 1;
background: #707276;
background: rgba(112, 114, 118, 0.75);
}
#header-nav .nav-item {
display: flex;
flex: 1;
}
#header-nav .nav-link {
color: #ffffff;
display: flex;
flex-grow: 1;
text-align: center;
justify-content: center;
align-items: center;
align-content: center;
}
#header-nav > .nav-item > .nav-link {
box-sizing: border-box;
text-transform: uppercase;
text-decoration: none;
padding: 15px 0;
position: relative;
transition: color 0.5s ease-in-out;
font-size: 115.385%;
font-family: VegurRegular;
}
#header-nav > .nav-item > .nav-link:hover {
color: #000000;
}
#header-nav > .nav-item > .nav-link:after {
content: '';
display: block;
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 5px;
opacity: 0;
transition: opacity 0.5s ease-in-out;
background-color: #36383a;
}
#header-nav > .nav-item > .nav-link:hover:after {
opacity: 0.8;
}
#header-nav .home {
flex-grow: 0;
flex-basis: auto;
padding: 0 50px;
}
#header-nav .nav-item.home > .nav-link {
display: block;
}
#header-nav .nav-item.home > .nav-link:after {
display: none;
}
<ul id="header-nav">
<li class="nav-item home">
<a href="/" class="nav-link">
<span id="logo-text" class="sprite">Logo</span>
</a>
</li>
<li class="nav-item">
Shop
</li>
<li class="nav-item">
Tiling Ideas
</li>
<li class="nav-item">
Advice
</li>
<li class="nav-item">
Find a Retailer
</li>
</ul>
Alternatively, consider media queries to reduce the font size at lower screen sizes.

Resources