How to get EpicGame's navbar transitions when hovering over link? - html

When you hover over, say, 'News', a blue underline will pop-in. From what I've seen, it is actually a background with a height transition from 0px -> 5px. However, my code is unable to replicate it.
* {
padding: 0;
margin: 0;
}
.navbar {
padding: 28px 36px;
background: black;
}
.navbar ul {
list-style: none;
}
.navbar li {
padding: 0 8px;
height: 100%;
position: relative;
transform: translateZ(0);
}
.navbar li::before {
display: block;
position: absolute;
bottom: 0;
left: 0;
z-index: -1;
background: blue;
transition: height .2s ease-in-out;
}
a {
display: block;
text-decoration: none;
color: white;
}
<div class="navbar">
<ul>
<li>Home
</ul>
</div>
I'm definitely missing something obvious here, but I don't get it. Help?

If I got you right, you did the most of the work, but you should always keep in mind when you using pseudo-elements like ::before you have to declare content property in it, otherwise it won't work at all. Then to make this work, you should just care about making the transition by putting initial with and height on ::before then make the height element to the actual one in hover.
So your final code should be something like this:
* {
padding: 0;
margin: 0;
}
.navbar {
padding: 28px 36px;
background: black;
}
.navbar ul {
list-style: none;
}
.navbar li {
padding: 0 8px;
height: 100%;
position: relative;
transform: translateZ(0);
}
.navbar li::before {
content: '';
display: block;
position: absolute;
bottom: 0;
left: 0;
z-index: -1;
width: 50px;
height: 0;
background: blue;
transition: height .2s ease-in-out;
}
.navbar li:hover::before {
height: 5px;
}
a {
display: block;
text-decoration: none;
color: white;
}
<div class="navbar">
<ul>
<li>Home
</ul>
</div>

Related

CSS Menu doesn't dropdown when it's hovered

I'm having trouble with the dropdown menu of my blog. When I hover over "Plamo Reviews", it doesn't drop down the sub-menus. I read some articles related to this but still cannot find any solution. I think I did something wrong with the CSS.
Could anyone help me?
I'd appreciate any help. Thank you in advance!
nav.fixnavbar {
position: relative;
display: block;
width: 100%;
background: #778595;
z-index: 99;
padding: 0;
margin-bottom: 0;
font-size: 0;
opacity: 1;
}
.fixednav {
position: relative;
margin: 0 auto;
padding: 0;
max-width: 1010px;
}
.fixednav li {
display: inline-block;
position: relative;
}
.fixednav li a {
display: inline-block;
padding: 20px;
color: #fff;
font-size: 14px;
font-weight: 700;
text-transform: uppercase;
}
.fixednav li a:hover {
background: #6c7a89;
color: #fff;
}
.nav-icon {
display: none;
}
nav.fixnavbar.main-nav-scrolled {
position: fixed;
top: 0;
left: 0;
opacity: 0.97;
-webkit-transform: translateZ(0);
transform: translateZ(0);
}
.sub-menu li {
display: none;
}
.fixednav li {
position: relative;
}
.sub-menu {
display: none;
position: absolute;
}
.fixednav li:hover .sub-menu {
display: block;
}
<nav class='fixnavbar'>
<ul class='fixednav' id='togglemenu'>
<li><a href='/'>Home</a></li>
<li><a href='/search/label/list'>List bài viết</a></li>
<li><a href='/search/label/kinh-nghiem'>Kinh nghiệm</a></li>
<li><a href='/search/label/review'>Plamo Reviews</a>
<ul class="sub-menu">
<li>No1</li>
<li>No2</li>
</ul>
</li>
<li class='indzign-box' onclick='document.getElementById(&apos;indzignbox&apos;).style.top=&apos;60px&apos;;document.getElementById(&apos;count-box&apos;).style.display=&apos;none&apos;;'><i class='fa fa-bars' /></li>
</ul>
</nav>
To achieve the behaviour you want, there are two things you should probably change:
You can get rid of the CSS rule that gives your sub-menus li elements a value of display: none as it's unnecessary. If the parent .sub-menu is set to display: none then the children will inherit that automatically.
You've set your .sub-menu to be position: absolute, but you haven't specified any additional CSS rules to indicate where it should go relative to its parent. So, for example, you can try making your .sub-menu rules look like the following:
.sub-menu {
display: none;
position: absolute;
top: 75px;
background: #ccc;
}
This way, you're saying that your menu should be positioned 75 pixels beneath its parent. The background is just so that your sub-menu is visible against the rest of your app (you can modify this to whatever you like, of course).
I don't think Stackoverflow is a place to get your homework done. Yet, here's a working sample with the minimal fixes to make it work.
You were missing the position (top) for the sub-menu and it was right beneath the fixed-nav.
There was no background-color for the sub-menu items, so the text which is white was not visible.
nav.fixnavbar {
position: relative;
display: block;
width: 100%;
background: #778595;
z-index: 99;
padding: 0;
margin-bottom: 0;
font-size: 0;
opacity: 1;
}
.fixednav {
position: relative;
margin: 0 auto;
padding: 0;
max-width: 1010px;
}
.fixednav li {
display: inline-block;
position: relative;
background-color: #6b7684;
}
.fixednav li a {
display: inline-block;
padding: 20px;
color: #fff;
font-size: 14px;
font-weight: 700;
text-transform: uppercase;
}
.fixednav li a:hover {
background: #6c7a89;
color: #fff;
}
.nav-icon {
display: none;
}
nav.fixnavbar.main-nav-scrolled {
position: fixed;
top: 0;
left: 0;
opacity: 0.97;
-webkit-transform: translateZ(0);
transform: translateZ(0);
}
.fixednav li {
position: relative;
}
.sub-menu {
display: none;
position: absolute;
top: 54px;
left: 0;
}
.fixednav li:hover .sub-menu {
display: block;
}
<nav class='fixnavbar'>
<ul class='fixednav' id='togglemenu'>
<li><a href='/'>Home</a></li>
<li><a href='/search/label/list'>List bài viết</a></li>
<li><a href='/search/label/kinh-nghiem'>Kinh nghiệm</a></li>
<li><a href='/search/label/review'>Plamo Reviews</a>
<ul class="sub-menu">
<li>No1</li>
<li>No2</li>
</ul>
</li>
<li class='indzign-box' onclick='document.getElementById(&apos;indzignbox&apos;).style.top=&apos;60px&apos;;document.getElementById(&apos;count-box&apos;).style.display=&apos;none&apos;;'><i class='fa fa-bars' /></li>
</ul>
</nav>

Hover submenu doesn't stay opened

I made full width dropdown submenu. the problem is that submenu disappears when I try to move mouse from mainlist to submenu. Also, transition on submenu is not applied. Code I wrote is at down below. Please check it and correct it.
body {
margin: 0;
padding: 0;
}
ul,
li,
a {
list-style: none;
text-decoration: none;
}
.wrap {
position: relative;
width: 100%;
height: 100px;
}
.list {
margin: 0;
padding: 0;
width: 100%;
left: 0;
top: 100px;
height: 100px;
text-align: center;
}
.list li {
display: inline-block;
margin: 20px;
}
.list>li:hover ul {
display: list-item;
opacity: 1;
}
.list>li:hover>a {
color: red;
}
.sub_list {
margin: 0;
padding: 0;
position: absolute;
display: none;
width: 100%;
height: 100px;
left: 0;
top: 50px;
text-align: center;
opacity: 0;
transition: all 0.5s;
}
.sub_list li {
display: inline-block;
margin: 20px;
}
.sub_list li a:hover {
color: red;
}
<div class="wrap">
<ul class="list">
<li>list-1
<ul class="sub_list">
<li>sublist-a</li>
<li>sublist-b</li>
<li>sublist-c</li>
</ul>
</li>
<li>list-2</li>
<li>list-3</li>
<li>list-4</li>
<li>list-5</li>
</ul>
</div>
I'd like to make submenu stay visible when mouse is on whole area of submenu div(100% width of screen).
please help
thank you
In addition to the problem regarding margin/padding/positioning addressed in other answers, the transition wouldn't work because you can't transition from display: none; to another state or vice versa. Instead, solely rely on opacity and add the pointer-events property so that the submenu will not itself trigger the hover or overlay any other content when it's hidden.
Here's the fully working code:
body {
margin: 0;
padding: 0;
}
ul, li, a {
list-style: none;
text-decoration: none;
}
.wrap {
position: relative;
width: 100%;
height: 100px;
}
.list {
margin: 0;
padding: 0;
width: 100%;
left: 0;
top: 100px;
height: 100px;
text-align: center;
}
.list li {
display: inline-block;
padding: 20px;
}
.list > li:hover ul {
pointer-events: all;
opacity: 1;
}
.list > li:hover > a {
color: red;
}
.sub_list {
margin: 0;
padding: 0;
position: absolute;
width: 100%;
height: 100px;
left: 0;
top: 50px;
text-align: center;
opacity: 0;
transition: all 0.5s;
pointer-events: none;
}
.sub_list li {
display: inline-block;
margin: 20px;
}
.sub_list li a:hover {
color: red;
}
<div class="wrap">
<ul class="list">
<li>list-1
<ul class="sub_list">
<li>sublist-a</li>
<li>sublist-b</li>
<li>sublist-c</li>
</ul>
</li>
<li>list-2
<ul class="sub_list">
<li>sublist-a</li>
<li>sublist-b</li>
<li>sublist-c</li>
</ul>
</li>
<li>list-3
<ul class="sub_list">
<li>sublist-a</li>
<li>sublist-b</li>
<li>sublist-c</li>
</ul>
</li>
<li>list-4
<ul class="sub_list">
<li>sublist-a</li>
<li>sublist-b</li>
<li>sublist-c</li>
</ul>
</li>
<li>list-5
<ul class="sub_list">
<li>sublist-a</li>
<li>sublist-b</li>
<li>sublist-c</li>
</ul>
</li>
</ul>
</div>
I fixed the issue for you: https://codepen.io/anon/pen/rboPLE
This is what i changed:
.list li {
display: inline-block;
padding: 20px; // this line was margin: 20px; before
}
When trying to reach the submenu you left the .list li item because it had a margin. With Padding the space belongs to the element and its still hovered when you move the mouse to submenu.
I colored the example in the link above so you can see the elements boundaries.
your code is perfect but minor issues is there.
use this css code:
.sub_list {
opacity: 0;
transition-duration: 200ms;
transition-timing-function: ease-in;
transition-property: opacity, margin-top, visibility;
visibility: hidden;
margin: 50px 0 0;
padding: 0;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 50px;
text-align: center;
}
.list > li:hover ul {
margin-top:0;
opacity: 1;
visibility: visible;
}
use this code its work perfect transition effect and dropdown submenu issues is solved.

Anti Aliasing making strange gap in skewed navigation

I've problem with creating a skewed navigation, actually everything is good except the strange gap between navigation item links. I did bit of research and I saw that is because of Anti Aliasing technique.
I tried to hack it with ::before selector and/or with applying border-right attribute to the block, but no success.
There is code:
* {
margin: 0;
padding: 0;
}
header {
width: 100%;
background: #1d1e22;
overflow: hidden;
}
ul {
margin-left: 5%;
position: relative;
}
ul li {
float: left;
list-style: none;
}
ul li a {
display: block;
padding: 20px;
text-decoration: none;
color: #fff;
background: #444857;
transform: skew(-20deg);
transition: all 300ms ease-in-out;
}
ul li a:hover {
background: #fff;
color: #000;
}
ul li a span {
transform: skew(20deg);
display: block;
}
<header>
<ul>
<li><span>Home</span></li>
<li><span>About us</span></li>
<li><span>Services</span></li>
<li><span>Contact</span></li>
</ul>
</header>
I want it to be without the black gap, just in one tone. If you know how to fix it, I will appreciate if you share it.
The issue here is how browsers handle subpixel rendering. As you are transforming the shape, the browser applies some antialiasing on the edges of the shapes for a smoother rendering.
Because of this there is no guarantee that the edge of two elements will align perfectly. See an interesting article about it.
The quickest fix is to apply some negative margin so that the shapes overlap.
* {
margin: 0;
padding: 0;
}
header {
width: 100%;
background: #1d1e22;
overflow: hidden;
}
ul {
margin-left: 5%;
position: relative;
}
ul li {
float: left;
list-style: none;
margin-left: -2px;
}
ul li a {
display: block;
padding: 20px;
text-decoration: none;
color: #fff;
background: #444857;
transform: skew(-20deg);
transition: all 300ms ease-in-out;
}
ul li a:hover {
background: #fff;
color: #000;
}
ul li a span {
transform: skew(20deg);
display: block;
}
<header>
<ul>
<li><span>Home</span></li>
<li><span>About us</span></li>
<li><span>Services</span></li>
<li><span>Contact</span></li>
</ul>
</header>
I added a box-shadow: 1px 0 1px #444857 to the <a> tags; https://codepen.io/nosnetrom/pen/QPaMBQ

White box within banner image

I am trying to add a border-top with 2px on my fixed navbar however on the a href hover it pushes all of the nav items down by 2px, I am trying to make it so it's static, any help is appreciated.
.fixed-nav-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 9999;
width: 100%;
height: 70px;
background-color: #3f3f3f;
}
.fixed-nav-bar li, .fixed-nav-bar a {
height: 0 auto;
line-height: 50px;
width: 100px;
overflow: hidden;
}
.menu {
width: 90%;
max-width: 960px;
margin: 0 auto;
text-align: center;
}
.menu a, .menu a:visited {
color: #ffffff;
overflow: hidden;
}
.menu a:hover, .menu a:target {
display: block;
border-top: 2px solid #72BCD4;
color: #72BCD4;
}
.menu-items { display: inline-block; }
.menu-items li {
display: inline-block;
margin-right: 10px;
margin-left: 10px;
}
.menu-items a {
text-decoration: none;
}
.show, .hide {
display: none;
padding-left: 15px;
background-color: transparent;
background-repeat: no-repeat;
background-position: center left;
color: #dde1e2;
}
.show {
background-image: url(../assets/down-arrow-icon.png);
}
.hide {
background-image: url(../assets/up-arrow-icon.png);
}
<nav class="fixed-nav-bar">
<div id="menu" class="menu">
<!-- Example responsive navigation menu -->
<a class="show" href="#menu">Menu</a><a class="hide" href="#hidemenu">Menu</a>
<ul class="menu-items">
<li>HOME</li>
<li>ABOUT</li>
<li>DESIGNS</li>
<li>CONTACT</li>
</ul>
</div>
</nav>
It's because of no border. Either give a transparent border with the same width or use the colour of the border. But in your case, it's screwed up. So I changed the overflow: hidden and used margin-top: -2px:
.fixed-nav-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 9999;
width: 100%;
height: 70px;
background-color: #3f3f3f;
}
.fixed-nav-bar li, .fixed-nav-bar a {
height: 0 auto;
line-height: 50px;
width: 100px;
}
.menu {
width: 90%;
max-width: 960px;
margin: 0 auto;
text-align: center;
}
.menu a, .menu a:visited {
color: #ffffff;
}
.menu a:hover, .menu a:target {
display: block;
border-top: 2px solid #72BCD4;
color: #72BCD4;
margin-top: -2px;
}
.menu-items {
display: inline-block;
}
.menu-items li {
display: inline-block;
margin-right: 10px;
margin-left: 10px;
}
.menu-items a {
text-decoration: none;
}
.show, .hide {
display: none;
padding-left: 15px;
background-color: transparent;
background-repeat: no-repeat;
background-position: center left;
color: #dde1e2;
}
.show {
background-image: url(../assets/down-arrow-icon.png);
}
.hide {
background-image: url(../assets/up-arrow-icon.png);
}
<nav class="fixed-nav-bar">
<div id="menu" class="menu">
<!-- Example responsive navigation menu -->
<a class="show" href="#menu">Menu</a><a class="hide" href="#hidemenu">Menu</a>
<ul class="menu-items">
<li>HOME</li>
<li>ABOUT</li>
<li>DESIGNS</li>
<li>CONTACT</li>
</ul>
</div>
</nav>
That's all because of box-sizing property. by default it adds value of paddings/margins/borders outside of content area, so element becomes bigger. Just define globally * {box-sizing: border-box;} it will make elements to fixed sizes. That means if element had no border, and then it adds, the element's area for content will be smaller, but the whole size will be the same. However, I strongly recommend you to use border at the beginning, otherwise, it will jump inside the element. You can set the color 'transparent' and it won't be visible. Then just by changing border-color it will be nicer.
I have created a little fiddler:
https://jsfiddle.net/marco_rensch/0hva2241/
this could be a possible solution
checkout CSS Code Changes between row 31 and 51
the key is to add a default border 2px transparent to the li's and change it by hover:
.menu-items li:hover{border-top: 2px solid #72BCD4;}

Underline hover is underlining extra

Here's the code I have problem with my underline hover effect its exppanding extra how to fix it please help me out ************************
HTML
<div class="nav-wrap">
<ul class="group" id="example-one">
<li>Home</li>
<li><a class="dropbtn">Models</a>
<ul class="dropdown-content">
<li></li>
<li>Audi</li>
<li>Bmw</li>
<li>Mercedes</li>
</ul>
</li>
<li>Offers</li>
<li>Group Sales</li>
<li>Reviews</li>
</ul>
</div>
And also i want my dropdown in the middle of his parent And here its*********
CSS
.nav-wrap {
background: white;
width: 100%;
}
#example-one {
text-align: right;
}
#example-one li {
text-align: left;
position: relative;
display: inline-block;
font-family: 'Montserrat', sans-serif;
top:-20px;
}
#example-one a {
color: #000;
font-weight: bold;
font-size: 14px;
padding: 15px 15px;
text-decoration: none;
position: relative;
color: #000;
}
#example-one a:after {
color: #333;
content: '';
position: absolute;
width: 0;
height: 3px;
display: block;
margin-top: 2px;
right: 0;
background: #000;
transition: width all 1s ease;
-webkit-transition: width 1s ease;
}
#example-one a:hover:after {
width: 100%;
left: 0;
background: #000;
}
.dropdown-content {
display: none;
position: absolute;
top: 30px;
left: 0;
background-color:white;
z-index: 1;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
}
#example-one li li {
display: block;
}
#example-one li:hover>ul {
display: block;
}
If I understand your problem correctly, the issue is with the dropdown items not being centered and the dropdown underline being too long. I believe this issue is caused by the padding on the dropdown div.
To resolve this, add some normalised padding to your .dropdown-content class:
.dropdown-content {
padding: 0 20px;
}
let the underline be attached to the text it self not to all the list item so it takes the width of just the text, now it takes the width of the whole cell in the list