Underline hover is underlining extra - html

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

Related

Tabs like a little vibrate on hover in HTML, CSS

I want to create a menu but, when it's finished the tab looks like it shakes a little on hover, like when it's hovered, the text on the tab goes up a bit and then drops back to normal
* {
margin: 0px;
padding: 0px;
background: #dbdbea;
}
.tab {
width: 100%;
height: 100px;
position: absolute;
background: #999999;
}
.tab ul {
display: inline-flex;
background: #999999;
position: absolute;
margin-top: 29px;
margin-left: 15px;
}
.tab ul li {
background: #999999;
list-style: none;
}
.tab ul li a {
background: #999999;
color: #222222;
margin: 0px 11.666px 0px 11.666px;
padding: 0px 23.334px 0px 23.334px;
text-decoration-line: none;
font-family: arial;
font-size: 36px;
transition: 1s;
}
.tab ul li a:hover {
background: #666666;
margin: 0px;
padding: 30px 35px 30px 35px;
}
<div class="tab">
<ul>
<li>Link 1</li>
<li>Link 2</li>
</ul>
</div>
I tried everything I could but, the results still weren't what I wanted, i was really confused about how to fix this bug
can someone tell me what's wrong with the code?
Can you please check the below code? Hope it will work for you. We have removed some flex utilities and give hover effect using pseudo-element with the transition.
Please refer to this link: https://jsfiddle.net/yudizsolutions/p41tnefh/4/
* {
margin: 0px;
padding: 0px;
background: #dbdbea;
}
.tab ul {
display: flex;
align-items: center;
background: #999;
padding-left: 15px;
list-style: none
}
.tab ul li {
align-items: center;
background: #999;
}
.tab ul li a {
color: #222222;
text-decoration: none;
font-family: arial;
font-size: 36px;
padding: 29px 25px;
transition: 1s;
display: block;
background: #999;
position: relative;
overflow: hidden;
z-index: 1;
}
.tab ul li a::before {
content: '';
display: black;
position: absolute;
width: 100%;
height: 100%;
left: 50%;
top: 50%;
background: #666666;
height: 50%;
width: 80%;
transition: 0.6s all ease-in-out;
-webkit-transition: 0.6s all ease-in-out;
z-index: -1;
transform: translate(-50%, -50%);
opacity: 0;
}
.tab ul li a:hover:before {
opacity: 1;
height: 100%;
width: 100%;
}
<div class="tab">
<ul>
<li>Link 1</li>
<li>Link 2</li>
</ul>
</div>

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>

Using float to place an element in the right side with CSS

I'm trying to do a nav bar with a contact button stuck to the right of the page. I want contact to be aligned with the rest of the elements of the nav bar, however when I add float: right; it just disaligns my nav bar and it doesn't move contact to the right.
Here you can see my code: http://jsfiddle.net/LG2vR/19/
Can someone please tell me the proper way to accomplish this please?
Thanks!
Am not sure if this is what you need exactly, see the updated fiddle
http://jsfiddle.net/ov74xcyg/1/
Basically, i have used position absolute to move your last child of the navigation to the right side and increased width of the navigation till the end of the header.
nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100px;
padding: 10px 100px;
z-index: 500;
box-sizing: content-box;
transition: .3s;
background: red;
}
nav.white {
background: white;
height: 35px;
padding: 10px 100px;
transition: .5s;
}
nav ul {
list-style: none;
float: left;
margin: 0;
padding: 0;
display: flex;
width: 90%;
position: relative;
}
nav ul li {
list-style: none;
}
nav ul li:last-child {
display: inline-block;
right: 5%;
position: absolute;
top: 0;
}
nav ul li a {
line-height: 80px;
color: #FFFFFF;
margin: 12px 30px;
text-decoration: none;
text-transform: capitalize;
transition: .5s;
padding: 10px 5px;
font-size: 16px;
}
nav ul li a:hover {
background-color: rgba(255,255,255,0.2);
}
nav.white ul li a {
color: #000;
line-height: 40px;
transition: .5s;
}
nav ul li a:focus {
outline: none;
}
<div class="wrapper">
<nav>
<ul>
<li>LOGO</li>
<li>Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li><a class="contact" href="#">Contact</a></li>
</ul>
</nav>
Just add:
nav ul li a {
float: left;
}
right before:
nav ul li a.contact {
float: right;
}
or use flexbox!
.wrapper li {list-style-type: none;}
.wrapper {
overflow: hidden;
background-color: red;
}
.wrapper .logo{
margin-right : 30px;
}
.wrapper a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.wrapper a:hover {
background-color: #ddd;
color: black;
}
.wrapper a.active {
background-color: #4CAF50;
color: white;
}
.topnav-right {
float: right;
}
<div class="wrapper">
<a class="active logo" href="#">Logo</a>
Home
Page 1
Page 2
<div class="topnav-right">
<li><a class="contact" href="#">Contact</a></li>
</div>
</div>

I can't dropdown the submenu under its parent menus

It's the HTML of my code. I created navigation menubar with submenu in dropdown option but my submenu is not dropping down under the parent menu "dropdown" is parent menu.
.nav-wrap{
background:white;
width:100%;
height:50px;
position: relative;
top:-13px;
overflow:visible;
}
#example-one {
margin: 0 auto;
list-style: none;
position: relative;
width: 100%;
}
#example-one li {
display: inline-block;
font-family: 'Montserrat', sans-serif;
}
#example-one a {
color: #000;
font-weight:bold;
font-size: 14px;
float: left;
padding: 15px 15px;
text-decoration: none;
left:350px;
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;
-webkit-transition-property: left, right;
transition-property: left, right;
transition: width 1s ease;
-webkit-transition: width 1s ease;
}
#example-one a:hover:after{
width: 100%;
left: 0;
background: #000;
}
.dropbtn {
color: white;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
box-shadow: 10px 10px 10px 10px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content
{
display: block;
}
<div class="nav-wrap">
<ul class="group" id="example-one">
<li>Home</li>
<li>
<div class="dropdown">
<a class="dropbtn">Dropdown</a>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div></li>
<li>Offers</li>
<li>Group Sales</li>
<li>Reviews</li>
</ul></div>
Here is the CSS:
.nav-wrap{
background:white;
width:100%;
height:50px;
position: relative;
top:-13px;
overflow:visible;
}
#example-one {
margin: 0 auto;
list-style: none;
position: relative;
width: 100%;
}
#example-one li {
display: inline-block;
font-family: 'Montserrat', sans-serif;
}
#example-one a {
color: #000;
font-weight:bold;
font-size: 14px;
float: left;
padding: 15px 15px;
text-decoration: none;
left:350px;
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;
-webkit-transition-property: left, right;
transition-property: left, right;
transition: width 1s ease;
-webkit-transition: width 1s ease;
}
#example-one a:hover:after{
width: 100%;
left: 0;
background: #000;
}
.dropbtn {
color: white;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
box-shadow: 10px 10px 10px 10px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content
{
display: block;
}
.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;
}
#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;
-webkit-transition-property: left, right;
transition-property: left, right;
transition: width 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: 100%;
left: 0;
min-width: 160px;
box-shadow: 10px 10px 10px 10px rgba(0, 0, 0, 0.2);
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;
}
<div class="nav-wrap">
<ul class="group" id="example-one">
<li>Home</li>
<li><a class="dropbtn">Dropdown</a>
<ul class="dropdown-content">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</li>
<li>Offers</li>
<li>Group Sales</li>
<li>Reviews</li>
</ul>
</div>
I've updated your CSS code and HTML as well. Your structure is over complicated and css with id does not reuseable for other dropdown menu.
.nav {
display: inline-block;
text-align: left;
}
.nav,
.dropdown {
padding: 0;
margin: 0;
list-style-type: none;
}
.nav > li {
float: left;
position: relative;
}
.nav li > a {
display: block;
position: relative;
padding: 10px 25px;
color: #000;
font: bold 14px sans-serif;
text-decoration: none;
}
.nav .dropdown {
display: none;
position: absolute;
top: 100%;
background-color: #fff;
box-shadow: 10px 10px 10px 10px rgba(0, 0, 0, .2);
min-width: 160px;
}
.nav .dropdown .dropdown {
top: 0;
left: 100%;
}
.nav .dropdown > li {
position: relative;
}
.nav li:hover > .dropdown {
display: block;
}
.nav .dropdown a:hover {
background-color: #f1f1f1;
}
.nav a::after {
content: '';
position: absolute;
right: 0;
bottom: 0;
width: 0;
height: 3px;
background: #000;
transition-property: left, right;
transition: width 1s ease;
}
.nav a:hover::after {
width: 100%;
left: 0;
background: #000;
}
<div style="text-align: center">
<ul class="nav">
<li>Home</li>
<li>
Dropdown
<ul class="dropdown">
<li>Link 1</li>
<li>
Link 2
<ul class="dropdown">
<li>Link 2.1</li>
<li>Link 2.2</li>
<li>Link 2.3</li>
</ul>
</li>
<li>Link 3</li>
</ul>
</li>
<li>Offers</li>
<li>Group Sales</li>
<li>Reviews</li>
</ul>
</div>

How to bring navigation div to the front

i have a navigation bar that sticks to the top of the page as the user scrolls, however as the user continues to scroll down the page, the navigation menu seems to disappear behind some of the pages elements.
any help with this matter will be greatly appreciated, below is all the code.
* {
margin: 0;
padding: 0;
list-style: none;
font-family: 'Segoe UI';
}
p,
h5 {
margin-bottom: 10px;
line-height: 1.5;
}
h5 {
text-align: center;
border: 1px solid #ccc;
border-width: 1px 0;
}
h5.fixed {
position: fixed;
top: 80px;
left: 0;
background-color: #fff;
right: 0;
}
.nav a {
text-decoration: none;
color: #fff;
display: block;
transition: .3s background-color;
}
.nav a:hover {
background-color: #005f5f;
}
.nav a.active {
background-color: #fff;
color: #444;
cursor: default;
}
/* Option 1 - Display Inline */
.nav li {
display: inline-block;
margin-right: -4px;
}
<h5>
<div class="nav">
<ul>
<li class="home">Home</li>
<li class="tutorials"><a class="active" href="#">Tutorials</a></li>
<li class="about">About</li>
<li class="news">Newsletter</li>
<li class="contact">Contact</li>
</ul>
</div>
</h5>
There are few issues in you code. I could not understand why you using h5 in fixed div. To solve issue try this
h5.fixed {
position: fixed;
top: 80px;
left: 0;
background-color: #fff;
right: 0;
z-index:999;
}
But my suggestion is use some better way to implement fixed top menu. Please check this example https://getbootstrap.com/examples/navbar-fixed-top/
it was ok I guess but color of font was white so it was not visible, I changed it to #000 and its working, please correct if I'm wrong
Plus I added z-index: 9; for your website purpose, if nav is fixed then it will be higher in "z" dimension "above" all elements. Don't forget to use "position: relative/absolute/fixed" etc to make z-index working :)
* {
margin: 0;
padding: 0;
list-style: none;
font-family: 'Segoe UI';
}
p,
h5 {
margin-bottom: 10px;
line-height: 1.5;
}
h5 {
text-align: center;
border: 1px solid #ccc;
border-width: 1px 0;
}
h5.fixed {
position: fixed;
top: 80px;
left: 0;
background-color: #fff;
right: 0;
}
.nav{
position: relative;
z-index: 9;
}
.nav a {
text-decoration: none;
color: #000;
display: block;
transition: .3s background-color;
}
.nav a:hover {
background-color: #005f5f;
}
.nav a.active {
background-color: #fff;
color: #444;
cursor: default;
}
/* Option 1 - Display Inline */
.nav li {
display: inline-block;
margin-right: -4px;
}
<h5>
<div class="nav">
<ul>
<li class="home">Home</li>
<li class="tutorials"><a class="active" href="#">Tutorials</a></li>
<li class="about">About</li>
<li class="news">Newsletter</li>
<li class="contact">Contact</li>
</ul>
</div>
</h5>
Try using the z-index css property. This will allow you to place the element above others on the page.
Try to use this code: z-index property only active when the its elements has relative or absolute value. otherwise it does not work.
elementname {
position: relative;
z-index: 1;
}
please see this link: https://jsfiddle.net/emumsbgp/