Navigation hover effect - html

I have been trying to create my first html and css website, but right now I'm stuck in the navigation because I'm trying to do a hover effect in the links, what I want is when you hover a link, a box should appear over a link, this box will have a shadow, can you help me out?
Thank you!!
Here is my nav code atm:
<div class="row">
<nav class="main-nav nav-js">
<img class="logo" src="" alt="">
<ul>
<li>ABOUT US</li>
<li>SEARCH</li>
<li>TOP ARTISTS</li>
<li>CONTACTS</li>
</ul>
</nav>
</div>
css:
.main-nav {
background-color: #2c3136;
width: 100%;
height: 70px;
text-align: center;
box-shadow: 0 0 5 0 #000; }
.main-nav li{
display: inline;
list-style: none;
}
.main-nav li a {
text-decoration: none;
color: white;
margin-right: 50px;
font-size: 90%;
font-weight: bold;
}
.main-nav li a:link
.main-nav li a:visited {
padding: 8 0;
color: #fff;
background: transparent;
transition: background 0.3s ease-in-out;
}
.main-nav li a:hover,
.main-nav li a:active {
color: #fff;
background: #5a5a5a;
transition: background 0.3s ease-in-out;
}
Example of what I want: https://w3layouts.com/preview/?l=/boombox-a-entertainment-category-flat-bootstrap-responsive-template/

Here is a code snippet with your intended behavior:
.main-nav {
background-color: #2c3136;
width: 100%;
height: 70px;
text-align: center;
box-shadow: 0 0 5 0 #000;
}
.main-nav li {
display: inline;
list-style: none;
}
.main-nav li a {
text-decoration: none;
color: white;
margin-right: 50px;
font-size: 90%;
font-weight: bold;
padding: 4px;
border-radius: 4px;
}
.main-nav li a:link .main-nav li a:visited {
padding: 8 0;
color: #fff;
background: transparent;
transition: background 0.3s ease-in-out;
}
.main-nav li a:hover,
.main-nav li a:active {
color: #fff;
background: #5a5a5a;
box-shadow: 4px 4px 4px #000;
transition: background 0.3s ease-in-out;
}
<div class="row">
<nav class="main-nav nav-js">
<img class="logo" src="" alt="">
<ul>
<li>ABOUT US</li>
<li>SEARCH</li>
<li>TOP ARTISTS</li>
<li>CONTACTS</li>
</ul>
</nav>
</div>
I added padding: 4px; and border-radius: 4px; to your .main-nav li a selector and I added box-shadow: 4px 4px 4px #000; to your .main-nav li a:hover, .main-nav li a:active selector. I hope this helps.

Have you something like this?
nav ul li a:hover {
background-color: #333333;
color: #FFFFFF;
box-shadow: 2px 10px 8px #888888;
}

Related

How to make an opened link show that it is selected

I am working on a website and I want my navbar buttons to show when selected. I added a hover function that works but I want it to remain like that when the link is opened. Here is what I have right now.
HTML:
...<body>
<header>
<div class="main">
<div class="logo-text">
<h1 class="text-logo">Title</h1>
</div>
<nav>
<ul>
<li>Home</li>
<li>Store</li>
<li>About</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</header>
CSS:
ul {
list-style-type: none;
text-align: center;
margin-top: -3.7%;
}
ul li {
display: inline-block;
margin-left: 0%;
font-size: 170%;
}
ul li a {
transition: 0.6s ease;
text-decoration: none;
color: #000000;
padding: 5px 40px;
border: 2px solid #000000;
font-weight: 700;
}
ul li a:hover {
background-color: #000000;
color: #ffffff;
}
ul li a:visited {
background-color: #000000;
color: #ffffff;
}
What can I add or improve? Thanks in advance!
Create an active class and use it in your pages accordingly
ul li a:hover,
.active {
background-color: #000000;
color: #ffffff;
}
<li>Home</li>
ul {
list-style-type: none;
text-align: center;
margin-top: -3.7%;
}
ul li {
display: inline-block;
margin-left: 0%;
font-size: 170%;
}
ul li a {
transition: 0.6s ease;
text-decoration: none;
color: #000000;
padding: 5px 40px;
border: 2px solid #000000;
font-weight: 700;
}
ul li a:hover,
.active {
background-color: #000000;
color: #ffffff;
}
ul li a:visited {
background-color: #000000;
color: #ffffff;
}
<header>
<div class="main">
<div class="logo-text">
<h1 class="text-logo">Title</h1>
</div>
<nav>
<ul>
<li>Home</li>
<li>Store</li>
<li>About</li>
</ul>
</nav>
</div>
</header>
I would add a new class and call it something like .currentPage. Now on each of your pages, you have to give the current li item the class currentPage.
For example, on index.html the first li needs the class.
Then customize that class.
There's no selector that is able to select your current page.

Button text color

I can't seems to put it together on my brain after almost practicing for 24 hours.I need help on changing the button text color to white, while the rest stay the same color
//NAVIGATION
//========================
.nav ul
display: flex
padding-left: 0
padding-top: 15px
.nav li
list-style: none
padding: 10px
.nav ul li a
text-decoration: none
color: #000000
.nav ul li:last-child
color: #FFFFFF
.nav ul li a:hover
color: #5c6ac4
.nav li:not(:last-child)
margin-right: 20px
.nav li:nth-child(3)
margin-right: auto
//BUTTON
//==============
.btn
width: 160px
height: 20px
//border: 1px solid #5c6ac4
background: #5c6ac4
border-radius: 5px
box-shadow: 0 0 20px rgba(0,0,0,0.2)
padding: 10px 15px 10px 15px
.btn:hover
background: #212b35
transition: background-color .6s ease-out
<nav class="nav">
<ul>
<li>Work</li>
<li>About</li>
<li>Contact</li>
<li>Get started</li>
<li>Hire me</li>
</ul>
</nav>
I've prepared an image on my particular issue
You've already defined a color in .nav ul li a. You either need to overwrite that by adding color: white !important to .btn or change the structure of your code.
Handling a CSS file with many !important tags could become difficult in large projects, so try to avoid it.
Add color: white; to .btn {..} in css file (and comments in css are /* comment */:
.btn {
color: white;
width: 160px;
height: 20px;
/* border: 1px solid #5c6ac4; */
background: #5c6ac4;
border-radius: 5px;
box-shadow: 0 0 20px rgba(0,0,0,0.2);
padding: 10px 15px 10px 15px;
}
first you can't use preprocessor just like that, you should convert it to CSS and then use that CSS, and in CSS comments are /*...*/ and rules are like .btn{ key:value; }
so after converting your sass to css we have :
/* Navigation */
.nav ul {
display: flex;
padding-left: 0;
padding-top: 15px;
}
.nav li {
list-style: none;
padding: 10px;
}
.nav ul li a {
text-decoration: none;
color: #000000;
}
.nav ul li:last-child {
color: #FFFFFF;
}
.nav ul li a:hover {
color: #5c6ac4;
}
.nav li:not(:last-child) {
margin-right: 20px;
}
.nav li:nth-child(3) {
margin-right: auto;
}
/* Button */
.btn:hover {
background: #212b35;
transition: background-color .6s ease-out;
}
a.btn {
width: 160px;
height: 20px;
/*border: 1px solid #5c6ac4;*/
background: #5c6ac4;
border-radius: 5px;
box-shadow: 0 0 20px rgba(0,0,0,0.2);
padding: 10px 15px 10px 15px;
}
<nav class="nav">
<ul>
<li>Work</li>
<li>About</li>
<li>Contact</li>
<li>Get started</li>
<li>Hire me</li>
</ul>
</nav>

The <ul> in my nav extends to the side of the page

I have a nested <ul> within my nav ul. When the <ul> has only one element its padding is fine and the <li> fits nicely. However when I have more than one element in the nested <ul> it extends to the side of the page. I can see nothing to do with padding changes in my :first-child or anything in my css for the nested <ul>.
The nested ul with multiple elements
The nested ul with only one element
Here is the HTML:
<header id="header" class="alt">
<h1><strong>South Somerset Motocross Club</strong></h1>
<nav id="nav">
<ul>
<li>Home</li>
<li><a>Info</a>
<ul>
<li>Club Rules</li>
<li>Pre-Race Bike Check</li>
<li>Job Descriptions</li>
<li>Race Fees</li>
<li>Groups And Ages</li>
</ul>
</li>
<li><a>About Us</a>
<ul>
<li>Our Heritage</li>
<li>Committee</li>
</ul>
</li>
<li><a>News</a></li>
<li>Fixtures</li>
</ul>
</nav>
</header>
Here is the CSS:
#header nav {
height: inherit;
line-height: inherit;
position: absolute;
right: 1.25em;
top: 0;
vertical-align: middle;
}
#header nav ul {
list-style: none;
margin: 0;
padding-left: 0;
}
#header nav ul li {
color: #fff;
display: inline-block;
padding-left: 10px;
padding-right: 10px;
margin-left: 1em;
}
#header nav ul li ul {
display: none;
padding: 0;
margin: 0;
background-color: #eee;
border-radius: 4px;
}
#header nav ul li:hover ul {
display: block;
position: absolute;
}
#header nav ul li ul li {
border-radius: 4px;
margin: 0 0 0 0;
padding-left: 4px;
padding-top: 1px;
padding-right: 4px;
width: 100%;
color: black;
font-size: 12pt;
}
#header nav ul li ul li a {
color: #111;
padding: 0;
margin: 0;
display: block;
}
#header nav ul li ul li a:hover {
color: rgba(255, 255, 0, 1);
}
#header.alt nav ul li ul li a:hover {
color: rgba(255, 255, 0, 1);
}
#header.alt nav ul li ul li:hover {
background-color: #3477ff;
}
#header nav ul li ul li:hover {
background-color: #3477ff;
}
#header.alt nav ul li ul li a {
color: #000;
padding: 0;
display: block;
}
#header nav ul li a {
-moz-transition: color 0.1s ease-in-out;
-webkit-transition: color 0.1s ease-in-out;
-ms-transition: color 0.1s ease-in-out;
transition: color 0.1s ease-in-out;
color: #000;
display: inline-block;
text-decoration: none;
}
#header nav ul li a:hover {
color: #000;
}
Any ideas on how I can keep the width of the <ul> to the max length of one of the items?
Add display block in
#header nav ul li ul li {
border-radius: 4px;
margin: 0 0 0 0;
padding-left: 4px;
padding-top: 1px;
padding-right: 4px;
width: 100%;
color: black;
font-size: 12pt;
display:block;
}
here is the fiddle
Yop!
i checked Your css and the problem was here:
#header nav ul li ul li {
border-radius: 4px;
margin: 0 0 0 0;
padding-left: 4px;
padding-top: 1px;
padding-right: 4px;
width: 100%;
color: black;
font-size: 12pt;
}
Which i changed to this:
#header nav ul li ul li {
border-radius: 4px;
margin: 0 0 0 0;
padding-left: 4px;
padding-top: 1px;
padding-right: 4px;
//width: 100%;
display:table;
color: black;
font-size: 12pt;
}
So now it's getting the width of longest item :)
Hope i helped!

How to add dropdown menu?

I have an existing website with the menu code below and I want to add more stuff to my site but users need to nevigate to those pages please help me to add a sub menu in dropdown to the code I have. Please help?
HTML:
<!-- Header -->
<div id="header">
<div id="nav-wrapper">
<!-- Nav -->
<nav id="nav">
<ul>
<li class="active">Homepage</li>
<li>Left Sidebar</li>
<li>Right Sidebar</li>
<li>No Sidebar</li>
</ul>
</nav>
</div>
</div>
CSS:
#nav {
}
#nav-wrapper {
background: rgba(0,0,0,.1);
position: absolute;
top: 0;
left: 0;
width: 100%;
}
#nav > ul {
margin: 0;
padding: 0;
text-align: center;
}
#nav > ul > li {
display: inline-block;
border-right: 1px solid;
border-color: rgba(255,255,255,.1);
}
#nav > ul > li:last-child {
padding-right: 0;
border-right: none;
}
#nav > ul > li > a, #nav > ul > li > span {
display: inline-block;
padding: 1.5em 1.5em;
letter-spacing: 0.06em;
text-decoration: none;
text-transform: uppercase;
font-size: 1.1em;
outline: 0;
color: #FFF;
}
#nav li.active a {
color: #FFF;
}
#nav > ul > li > ul {
display: none;
}
#nav li:hover > ul {
opacity: 1;
visibility: visible;
margin: 0;
}
Change your css like
#nav li:hover > ul
{
opacity: 1;
display: block;
margin: 0;
position:absolute;
background:green;
}
<nav id="nav">
<ul>
<li class="active">Homepage
<ul>
<li><a href="index.html">Homepage</li>
<li>Pictures</li>
<li>Contact</li>
</ul>
</li>
<li>Pictures</li>
<li>Contact</li>
</ul>
</nav>
CSS :
#nav
{
}
#nav-wrapper
{
background: rgba(0,0,0,.1);
text-align:center;
margin:0;
padding:0;
width: 100%;
}
#nav ul {
display: inline;
margin: 0;
padding: 0;
text-align: center;
padding: 15px 4px 17px 0;
list-style: none;
border-right: 1px solid;
border-color: rgba(255,255,255,.1);
color: white;
}
ul li {
border-right: 1px solid;
border-color: rgba(255,255,255,.1);
display: inline-block;
margin: -4px;
position: relative;
padding: 15px 20px;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
text-align: center;
color: white;
}
ul li:hover {
border-right: 1px solid;
border-color: rgba(255,255,255,.1);
color: white;
}
ul li ul {
position: absolute;
top: 90px;
left: 0;
width: 200px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
ul li ul li {
border-right: 1px solid;
border-color: rgba(255,255,255,.1);
background: rgba(0,0,0,.1);
display: block;
text-transform: uppercase;
font-size: 1.1em;
outline: 0;
color: #FFF;
}
ul li ul li:hover { background: #666; }
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
#nav ul li a,
#nav ul li span
{
display: inline-block;
padding: 1.5em 1.5em;
letter-spacing: 0.06em;
text-decoration: none;
text-transform: uppercase;
font-size: 1.1em;
outline: 0;
color: #FFF;
}
#nav li.active a
{
color: #FFF;
}
HTML :
<div id="header">
<div id="nav-wrapper">
<!-- Nav -->
<nav id="nav">
<ul>
<li class="active">Homepage</li>
<li>Pictures
<ul>
<li>test</li>
<li>test2</li>
</ul>
</li>
<li>Contact</li>
</ul>
</nav>
</div>
JSFIDDLE DEMO

Aligning a dropdown menu in CSS in all browsers

I have a dropdown menu that is generated from WordPress so I do not want to change the HTML of it. i can change the CSS as needed though and I pretty much have ot working as I need it with the exception of an alignment issue with my dropdown menu.
Google Chrome
FireFox
Internet Explorer
From the images above you can see that IE and FIreFox display it the same but Chrome is always different from the 2. My Goal is to get this box to align perfectly with the right of the menu button and then get it to look that way in all 3 of these browsers.
I have extracted the HTML and CSS into a JSFiddle page for testing and playing around with here...
Code View: http://jsfiddle.net/jasondavis/hAb4k/
Full View for viewing the menu: http://jsfiddle.net/jasondavis/hAb4k/embedded/result/
My HTML
<nav id="head-nav-menu" class="nav-main" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">
<ul id="nav" class="nav nav-pills">
<li class="active menu-home">
Home
</li>
<li class="menu-about">
About
</li>
<li class="menu-projects">
Projects
</li>
<li class="menu-blog">
Blog
</li>
<li class="dropdown menu-services">
<a class="dropdown-toggle" data-toggle="dropdown" data-target="#" href="/services/">Services <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="menu-consulting">Consulting</li>
<li class="menu-magento-development">
Magento Development
</li>
<li class="menu-wordpress-development">
WordPress Development
</li>
<li class="menu-sugarcrm-development">
SugarCRM Development
</li>
<li class="menu-web-development">
Web Development
</li>
<li class="menu-seo">
SEO
</li>
</ul>
</li>
<li class="menu-contact">
Contact
</li>
</ul>
</nav>
CSS
body{
background: #40C8F4 !important;
}
nav ul, nav ol {
list-style: none;
list-style-image: none;
}
#head-nav-menu{
float: right;
margin-top: 29px;
}
#head-nav-menu li {
float: left;
position: relative;
padding: 0 2px 0 2px;
}
.nav a {
font-family: 'arial';
font-size: 18px;
padding: 8px 18px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
white-space: nowrap;
color: #fff;
opacity: 0.9;
letter-spacing: 1px;
text-decoration: none;
}
.menu-contact a {
border: 2px solid #FFF;
padding: 8px 18px;
transition: 0.05s linear;
-moz-transition: 0.05s linear;
-webkit-transition: 0.05s linear;
}
.nav .menu-contact a:hover {
background-color: #FFF;
color: #797979;
}
#nav ul a {
font-weight: 100;
}
.nav a:hover,
.nav > .active a {
opacity: 1;
background-color: #3DBCE6;
}
.nav > .active li a {
background-color: inherit;
}
.tinynav {
display: none;
width: 100%;
margin-top: .5em;
margin-bottom: .6em;
}
.nav li.button a {
background-color: rgba(255, 255, 255, 0.1);
border: 2px solid #FFF;
border-radius: 4px;
margin-top: 5px;
padding: 8px 18px;
font-family: 'ProximaNova-bold', Helvetica, Arial, sans-serif;
font-weight: normal;
margin-left: 16px;
color: #FFF !important;
}
.nav li.button a:hover {
background-color: #FFF;
opacity: 1;
color: #444 !important;
}
/* ==========================================================================
Main Container General Layout Styles
========================================================================== */
.header-container header {
padding-top: 13px;
padding-bottom: 18px;
}
/* Navigation > Dropdown Menus */
#nav .dropdown-menu,
#nav .children {
display: none;
padding: 0;
position: absolute;
z-index: 99999;
border: 1px solid #86DEFC;
width: 333%;
/*right: 8px;*/
left: -239%;
top: 23px;
background-color: #F2F9FC;
}
#nav .dropdown-menu li {
width: 195px;
float: left;
display: inline-block;
/*width: 50%;*/
}
.nav .dropdown-menu a {
color: #030303;
}
#nav li:hover > ul,
#nav ul li:hover > ul,
.dropdown:hover > ul {
display: inline-block;
-webkit-animation: fadeDown 250ms ease;
-moz-animation: fadeDown 250ms ease;
-ms-animation: fadeDown 250ms ease;
-o-animation: fadeDown 250ms ease;
animation: fadeDown 250ms ease;
background-color: #fff;
color: #000;
border: 1px solid #E9E9E9;
border-top: none;
}
#nav .dropdown-menu ul,
#nav .children ul {
left: 99.75%;
top: -1px;
}
#nav ul li,
#nav ul ul li {
margin-left: 0;
}
#nav ul li:first-child,
#nav ul ul li:first-child {
border-top: none;
}
#nav ul a,
#nav ul ul a {
font-size: 14px;
line-height: 21px;
text-align: left;
padding: 10px;
display: inline-block;
min-width: 125px;
border-bottom: none;
margin-bottom: 0 !important;
width: 100%;
letter-spacing: 1px;
font-family: arial;
}
#nav ul a:hover,
#nav ul ul a:hover {
color: #098EB9 !important;
background: none;
}
#nav ul ul.dropdown-menu a:hover {
width: 100%;
color: #63E924 !important;
border-bottom: none;
}
#nav li.current_page_item ul a,
#nav li.current-menu-parent ul a,
#nav li.current_page_parent ul a {
color: #000;
font-weight: 700;
}
#nav ul li.current-menu-item a {
color: #e9242e !important;
}
#head-nav-menu .nav li:hover a.dropdown-toggle {
background: #fff;
color: #000;
opacity: 1;
border-right: 1px solid #E7E7E7;
}
.nav .dropdown a:hover {
opacity: 1;
background-color: #fff;
}
#nav .dropdown-menu li:hover {
background: #F8F8F8;
}
Give display: block to .nav a
then remove left: 239% of #nav .dropdown-menu and give right: 2px and top: 38px to it.
Here is the edited demo for it.
http://jsfiddle.net/hAb4k/3/