css menu hover text color - html

I have this menu snipped and I am interested to know if there is any possibility to edit the CSS code, in order to obtain in the end a menu text in 2 colors (initial and on mouse over) on transparent background, applying the css text transition from one color to another.
body {
font: normal 1.0em Arial, sans-serif;
background: #A8CBFF;
}
nav {
font-size: 3.0em;
line-height: 1.0em;
color: white;
width:6em;
height: 9.0em;
position:absolute;
top:0; bottom:0;
margin:auto;
left: -4.5em;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
background-color: blue;
height: 1.0em;
padding: 0.25em;
position: relative;
border-top-right-radius: 0.75em;
border-bottom-right-radius: 0.75em;
-webkit-transition: -webkit-transform 500ms, background-color 500ms, color 500ms;
transition: transform 500ms, background-color 500ms, color 500ms;
}
nav ul li:nth-child(1) { background-color: #00aced;}
nav ul li:nth-child(2) { background-color: #3b5998;}
nav ul li:nth-child(3) { background-color: #517fa4;}
nav ul li:nth-child(4) { background-color: #007bb6;}
nav ul li:nth-child(5) { background-color: #cb2027;}
nav ul li:nth-child(6) { background-color: #ea4c89;}
nav ul li:hover {
background-color: #C1232D;
-webkit-transform: translateX(4.5em);
transform: translateX(4.5em);
}
nav ul li span {
display:block;
font-family: Arial;
position: absolute;
font-size:1em;
line-height: 1.25em;
height:1.0em;
top:0; bottom:0;
margin:auto;
right: 0.16666666666667em;
color: #F8F6FF;
}
a {
color: #FFF;
text-decoration: none;
}
<nav>
<ul>
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
<li>Category 4</li>
<li>Category 5</li>
<li>Category 6</li>
</ul>
</nav>
I've figured it out by setting background-color: to transparent; CodePen here; but at this point, I'm not so sure how to deal with the text colors because if I change a {color: red;} for example, I'll obtain a static color even on mouse over event, not a crossfading visual effect from one text color to another.

Putting it in the transition works. You just need to add a transition property to a selector that selects the a, not just the li. Specifically, nav ul li:hover a { color: black; }:
body {
font: normal 1.0em Arial, sans-serif;
background: #A8CBFF;
}
nav {
font-size: 3.0em;
line-height: 1.0em;
color: white;
width:6em;
height: 9.0em;
position:absolute;
top:0;
bottom:0;
margin:auto;
left: -4.5em;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
background-color: blue;
height: 1.0em;
padding: 0.25em;
position: relative;
border-top-right-radius: 0.75em;
border-bottom-right-radius: 0.75em;
-webkit-transition: -webkit-transform 500ms, background-color 500ms, color 500ms;
transition: transform 500ms, background-color 500ms, color 500ms;
}
nav ul li:nth-child(1) {
background-color: #00aced;
}
nav ul li:nth-child(2) {
background-color: #3b5998;
}
nav ul li:nth-child(3) {
background-color: #517fa4;
}
nav ul li:nth-child(4) {
background-color: #007bb6;
}
nav ul li:nth-child(5) {
background-color: #cb2027;
}
nav ul li:nth-child(6) {
background-color: #ea4c89;
}
nav ul li:hover {
background-color: #C1232D;
-webkit-transform: translateX(4.5em);
transform: translateX(4.5em);
}
nav ul li:hover a {
transition: color, 1500ms;
color: black;
}
nav ul li span {
display:block;
font-family: Arial;
position: absolute;
font-size:1em;
line-height: 1.25em;
height:1.0em;
top:0;
bottom:0;
margin:auto;
right: 0.16666666666667em;
color: #F8F6FF;
}
a {
color: #FFF;
text-decoration: none;
}
<nav>
<ul>
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
<li>Category 4</li>
<li>Category 5</li>
<li>Category 6</li>
</ul>
</nav>
You can change the text color to whatever you want, of course.

Related

I need help in fixing my drop down menu from moving when showing <li>

The Problem:
Look at Offers and the li:
After putting position: absolute
Current vs What I want to achieve
How to make my drop down menu so that when I hover on "Offers" the text doesn't move to the left? I would also like to decrease the width of the li as it is too big for me.
I have tried changing the display: property and putting spaces before and after the word "Offers" in HTML. The spaces worked but I didnt like it because the Offers will just look like having more space than the other options.
.nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 80px;
}
.menu {
float: right;
line-height: 80px;
margin: 0 9em;
text-align: center;
font-family: "Proxima Nova";
text-transform: uppercase;
font-weight: bolder;
letter-spacing: 0px;
}
.menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.menu ul li {
text-align: center;
list-style: none;
display: inline-table;
}
.menu ul li a {
text-decoration: none;
color: white;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
transition: all .3s ease-in-out;
}
.menu ul li a:hover {
color: orange;
}
.menu ul li ul li {
display: none; /*So li dont show up unless hover */
}
.menu ul li:hover ul li {
transition: all .3s ease;
display: block;
background: rgba(0, 0, 0, .6);
}
ul li:nth-child(5) a {
color: white;
border: 1px solid orange;
padding: 10px 20px;
border-radius: 4px;
background-color: none;
transition: all 1s ease-out;
}
ul li:nth-child(5) a:hover {
transition: all .5s ease-in;
background: rgba(204, 204, 204, 0.5);
color: orange;
}
<div class="nav">
<div class="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Offers
<ul>
<li>Packages</li>
<li>Services</li>
<li>Promos</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
</div>
</div>
I want to dropdown menu to not move when the li is shown in the Offers. And I would like to decrease the width of black background of the li
That's because the sub menu is taking a place and make its parent li wider.
A possible solution is to set the ul child position: absolute so it will not take a place.
Like this:
.menu ul ul {
position: absolute;
}
Live example:
body {
background: url(https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569_960_720.jpg) 0 0;
background-size: cover;
}
.nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 80px;
}
.menu {
float: right;
line-height: 80px;
margin: 0 9em;
text-align: center;
font-family: "Proxima Nova";
text-transform: uppercase;
font-weight: bolder;
letter-spacing: 0px;
}
.menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.menu ul li {
text-align: center;
list-style: none;
display: inline-table;
position: relative;
}
.menu ul li a {
text-decoration: none;
color: white;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
transition: all .3s ease-in-out;
}
.menu ul li a:hover {
color: orange;
}
.menu ul ul {
position: absolute;
width: 100%;
}
.menu ul li ul li {
display: none;
/*So li dont show up unless hover */
}
.menu ul li ul li a {
padding: 0;
text-align: center;
}
.menu ul li:hover ul li {
transition: all .3s ease;
display: block;
background: rgba(0, 0, 0, .6);
}
ul li:nth-child(5) a {
color: white;
border: 1px solid orange;
padding: 10px 20px;
border-radius: 4px;
background-color: none;
transition: all 1s ease-out;
}
ul li:nth-child(5) a:hover {
transition: all .5s ease-in;
background: rgba(204, 204, 204, 0.5);
color: orange;
}
<div class="nav">
<div class="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Offers
<ul>
<li>Packages</li>
<li>Services</li>
<li>Promos</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
</div>
</div>
The problem lies with the min-content size of the list items in the drop down, which are larger than the size of the parent list items in the top menu.
e.g. 'packages' renders at 120px whereas 'offers' is 98px.
The simplest solution is to set a max-width for all the list items based on the max-content size of the longest word (not very dynamic though).
Otherwise, use position:absolute to layout the sub menu as in this example:
https://codepen.io/skippingredpanda/pen/xNrxVg
Is simple, use:
.menu li { position: relative; } .menu li ul { position: absolute; top: your horizontal nav height; left: 0;}
And also you have a mistake in code, must be like this:
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>
Link 3
<ul>
<li>SubLink 1</li>
<li>SubLink 2</li>
<li>SubLink 3</li>
<li>SubLink 4</li>
</ul>
</li>
<li>Link 4</li>
</ul>
ul li {position: relative;}
ul li ul {position: absolute; display: none;}
ul li:hover ul {display: block;}

CSS Dropdown-menu not displaying when <li>-element is hovered.

I have a top navigation bar with 4 options, where I wish that while the fourth option is hovered, a dropdown-menu will display.
The navigation bar is an unordered list, and the dropdown-menu (which should be activated by the fourth option) is a div consisting of 3 links.
The list item that is supposed to display the dropdown-menu while hovered:
<li class="dropdownbutton">Contact</li>
With the help of this line of code:
.dropdownbutton:hover .dropdowncontent {
display:inline-block;
}
And this is the CSS for the dropdown-content:
.dropdowncontent {
display:none;
background-color:#333;
margin-left:272px;
width:90px;
text-align:center;
}
What am I missing?
This should be allright.
ul {
margin: 0;
padding: 0;
list-style: none;
background-color: #333;
}
ul li {
display: inline-block;
position: relative;
text-align: left;
background-color: #333;
}
ul li a {
display: block;
color: #f2f2f2;
text-align: center;
padding: 16px 15px;
text-decoration: none;
transition-duration: 0.3s;
-webkit-transition-duration: 0.3s;
font-size: 17px;
font-family: Arial;
}
ul li a:hover {
background-color: #555;
}
ul li ul.dropdown {
min-width: 100%;
display: none;
position: absolute;
z-index: 999;
left: 0;
width: 90px;
}
ul li:hover ul.dropdown {
display: block;
}
ul li ul.dropdown li {
display: block;
}
ul li ul.dropdown li a {
font-size: 14px;
padding: 10px 15px;
}
<ul>
<li>Home</li>
<li>About Us</li>
<li>Products</li>
<li>Contact
<ul class="dropdown">
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
</li>
</ul>

dropdown menu without borders

I want to do one small and easy dropdown menu, but I dont get it how to do this.
What I exacly mean ? :
And I want to do this thisway: If u click on ENG then its going to index_eng.html, but its not working.
My html:
<nav id="menu2">
<select>
<option href="index.html" value="est">EST</option>
<option href="index_eng.html" value="eng">ENG</option>
</select>
</nav>
My css:
#menu2 {
height: 30px;
overflow: visible;
border-radius: 5px;
background-color: #484848;
color: #FFFFFF;
padding: 5px 5px 0px 5px;
margin: 5px 5px 5px 5px;
font: 8pt verdana, arial, sans-serif;
}
At the moment I have this menu like this, but I want it like this picture above.
Need some clue or solution. Thank you!
Why don't you use anchors?
<nav id="menu2">
<ul>
<li>EST</li>
<li>ENG</li>
</ul>
</nav>
If you do not want to use anchors, you can achieve navigation with jQuery:
$('option').click(function() {
var url = $(this).attr('href');
window.location = url;
});
Try this if the above does not work:
window.location.assign(url);
This is very simple CSS3 drop-down menu:
Demo: http://jsfiddle.net/ahqbbwbm/11/
HTML
<ul>
<li>
EST <span class="arrow-down"></span>
<ul>
<li>EST</li>
<li>ENG</li>
</ul>
</li>
</ul>
CSS
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #2980b9;
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;
color: #fff;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-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 {
min-width: 80px;
background-color: #555;
}
ul li ul li > a {
text-decoration: none;
display: block;
color: #fff;
}
ul li ul li:hover {
background: #666;
}
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
ul li > span {
display: inline-block;
margin: 0 0 -3px 5px;
width: 12px;
height: 12px;
background-image: url('https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/down4-24.png'); /* Change this */
background-size: 12px 12px;
}
http://jsfiddle.net/yf18w6ay/
css
select{
border:0px;
outline:0px;
}
Below is the example for simple pure CSS Drop Down Menu..
HTML
<nav id="primary">
<ul>
<li>Menu 1
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4
<ul>
<li>Deep Menu 1
</li>
<li>Deep Menu 2</li>
</ul>
</li>
<li>Sub Menu 5</li>
</ul>
</li>
</ul>
CSS
#primary
{
margin-top:15px
}
#primary ul
{
list-style:none;
position:relative;
float:left;
margin:0;
padding:0
}
#primary ul a
{
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif
}
#primary ul li
{
position:relative;
float:left;
margin:0;
padding:0
}
#primary ul li.current-menu-item
{
background:#ddd
}
#primary ul li:hover
{
background:#f6f6f6
}
#primary ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
#primary ul ul li
{
float:none;
width:200px
}
#primary ul ul a
{
line-height:120%;
padding:10px 15px
}
#primary ul ul ul
{
top:0;
left:100%
}
#primary ul li:hover > ul
{
display:block
}

CSS dropdown on hover [duplicate]

This question already has answers here:
CSS drop down menu hover effect
(4 answers)
Closed 8 years ago.
I'm trying to create a drop down navigation bar, this is what I've got.
html
<div class="navBar">
<ul class="navBarStyles navBarWidth navBarMain">
<li class="onSelect">Item1</li>
<li>Item2</li>
<li>Item3</li>
<ul class="navBarExtended">
<li class="borderLeft">ExtraItem</li>
</ul>
<ul class="navBarExtra" id="floatRight">
<li class="i-icon">Dropdown</li>
<ul class="dropdown">
<li>SubItem1<li>
<li>SubItem2<li>
<li>SubItem3<li>
</ul>
</ul>
</ul>
</div>
css
a{
text-decoration: none;
}
.header {
width: 100%;
background-color: #000000;
}
.headerContent{
width: 960px;
margin: 0 auto;
}
.navBar{
font-family: "opensans-regular";
width: 100%;
position: absolute;
line-height: 48px;
background-color: #0088FF; /*0088FF*/
color: #ffffff;
}
.navBarWidth{
width: 400px;
margin: 0 auto;
}
.navBarStyles li{
float: left;
}
.navBarStyles li a{
display: inline-block;
color: #FFFFFF;
font-size: .9em;
text-align: center;
padding-left: 20px;
padding-right: 20px;
vertical-align: top;
letter-spacing: 0;
text-decoration: none;
}
.navBarMain li a:hover{
background-color: #40A5FF; /*#005569 #3D3C3C 12B0CC*/
text-shadow: none;
/* Firefox */
-moz-transition-property: background-color;
-moz-transition-duration: .30s;
-moz-transition-timing-function: ease-out;
-moz-transition-delay: 0s;
/* WebKit */
-webkit-transition-property: background-color;
-webkit-transition-duration: .30s;
-webkit-transition-timing-function: ease-out;
-webkit-transition-delay: 0s;
/* Opera */
-o-transition-property: background-color;
-o-transition-duration: .30s;
-o-transition-timing-function: ease-out;
-o-transition-delay: 0s;
/* Standard */
transition-property: background-color;
transition-duration: .30s;
transition-timing-function: ease-out;
transition-delay: 0s;
}
.navBarExtended li a:hover{
text-decoration: underline;
background: none;
}
/*Class applied to current page element */
.onSelect{
background-color: #40A5FF;
}
/*Navigation Bar Extra - Sytles*/
.navBarExtra li{
float: right;
opacity: .88;
}
.navBarExtra li:hover{
opacity: 1;
background: none;
cursor: pointer;
-moz-transition-property: opacity;
-moz-transition-duration: .30s;
-moz-transition-timing-function: ease-out;
-moz-transition-delay: 0s;
}
.dropdown{
font-family: 'opensans-regular';
font-size: .95em;
}
.navBarExtra ul li{
visibility: hidden;
float: left;
min-width: 150px;
position: absolute;
margin-top: 50px;
left: 0;
z-index: 999;
}
.navBarExtra ul li:hover > ul,
.navBarExtra ul li ul:hover{
visibility: hidden;
}
jsFiddle
but not able to display the sub items under dropdown button. How can I target the dropdown button to display those when user hovers over dropdown button?
To be honest, with all the complicated class names and styles involved in your example, it's hard to work out what needs fixing. I put together a simple example that you can edit to work however you like. Should be pretty self explanatory.
See on fiddle: http://jsfiddle.net/5Uejn/23/
HTML
<ul class="navbar">
<li>page 1</li>
<li>page 2</li>
<li>title 1
<ul>
<li>page 3</li>
<li>page 4</li>
<li>page 5</li>
</ul>
</li>
<li>title 2
<ul>
<li>page 6</li>
<li>page 7</li>
</ul>
</li>
</ul>
CSS
.navbar, .navbar ul
{
font-size:20px;
list-style:none;
z-index:10;
margin:0;
padding:0;
}
.navbar a, .navbar a:link
{
color:black;
text-decoration:none;
}
.navbar li
{
float:left;
background: #666;
width:100px;
}
.navbar li:hover, .navbar a:hover
{
background:#aaa;
color:blue
}
.navbar li ul
{
display:none;
}
.navbar li:hover ul
{
position:absolute;
display:block;
width:100px;
}
.navbar li ul li
{
float:none;
}

How to add space between menu and dropdown submenu

I'm working on a CSS3 full width dropdown menu, but some details i can't get right. :-(
What i try to achieve is this:
You can see there is a little 20px space between the mainmenu and the submenu. In this example i used a top-margin:20px for the ul submenu. But that doesn't really work, because you will leave the hover-area with your cursor and the submenu wil dissapear. The dropdown only works if the ul-container of the submenu "touches" the hover-area.
It did tried using the ul:before trick to add an empty block before the submenu ul, but somehow that doesn't work. :( It doens't take space like a block should do. It's just adding the content right over the ul element.
What do i overlook or doing wrong here? :( Why is the ul ul:after not working? Is there a better way to add a little bit of empty "hoverspace" above the submenu?
Your help would be very helpfull :-).
Live demo:
http://jsfiddle.net/JeroenGerth/hDmxd/
The HTML:
<nav>
<ul id="menu">
<li>Home</li>
<li>Tutorials >
<ul class="submenu">
<li>Photoshop 1</li>
<li>Dreamweaver 2</li>
<li>Photoshop 3</li>
<li>InDesign 4</li>
<li>Bridge 5</li>
<li>Lightroom 6</li>
<li>After Effects 7</li>
<li>Premiere 8</li>
<li>Motion 9</li>
<li>Aperture 10</li>
<li>iPhoto 11</li>
</ul>
</li>
<li>Downloads >
<ul class="submenu">
<li>Wallpapers 1</li>
<li>PSD files 2</li>
<li>Video's 3</li>
<li>Soundeffects 4</li>
<li>Icons 5</li>
<li>Maps 6</li>
</ul>
</li>
<li>About me</li>
<li>Contact</li>
</ul>
</nav>
The CSS:
body {background-color: #E9E9E9;}
nav ul { /*Main menu container*/
margin: 0px;
padding: 0px 20px;
background-color:#444;
color: #fff;
list-style: none;
position:relative;
display:inline-table;
border-radius: 5px;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li { /*Main menu-items*/ float:left;}
nav ul li a {
padding: 10px 20px;
color: #fff;
font-family: Calibri, Verdana, sans-serif;
text-decoration:none;
display: block;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
nav ul li a:hover {color: #66D1D3;}
nav ul ul { /*Submenu container*/
display:block;
border-radius:0px;
padding: 0px;
position: absolute;
background-color:#fff;
color: #000;
visibility:hidden;
opacity:0;
transition:all ease-in-out 0.4s;
left: 0px;
top: 100%;
width: 100%;
columns:100px 3;
-webkit-columns:100px 3; /* Safari and Chrome */
-moz-columns:100px 3; /* Firefox */
}
nav ul li:hover > ul { /*Show submenu*/
visibility:visible;
opacity:1;
transition-delay:0s;
}
nav ul ul:before { /*Why doesn't this work :( */
content: "";
display: block;
height: 20px;
position: absolute;
width: 100%;}
nav ul ul li { /*Submenu items*/
float: none;
border-bottom: 1px #CCCCCC dotted;
position:relative;
}
nav ul ul li a {
color: #000;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
nav ul ul li a:hover {
color: #66D1D3;
background-color: #444;
}
Add a margin-top to nav ul li:hover > ul:
nav ul li:hover > ul {
visibility:visible;
opacity:1;
transition-delay:0s;
margin-top: 20px; /* new */
}
Updated fiddle: http://jsfiddle.net/hDmxd/3/
Note: it won't disappear since the easing fadeout gives enough time for the user's mouse to leave the menu and enter the sub-menu.
nav ul li:hover > ul {
visibility:visible;
opacity:1;
transition-delay:0s;
margin-top:1.3em; /* added new */
}
You haven't submitted you styles on the class "nav" or it's parent! The space can be adjusted by playing about with the padding. e.g.
nav {
padding: 10px 5px 10px 5px;
}
div { //that's the div above your nav
padding: 10px 5px 10px 5px;
}
It's either one or the other