I have a CSS drop-down menu that works perfectly on mouse hover but that only partly works on iPad & iPhone. Tapping the drop-down works the first time but fails on subsequent taps until the home link is tapped, which 'resets' the menu. Seems weird to me but maybe someone will recognize this behavior. The menu can be viewed at http://raleighfutbol4all.com/
<div id="menu">
<ul>
<li><a class="link" href="http://raleighfutbol4all.com">Home</a></li>
<li><a class="sm_parent" onClick="return true">Program</a>
<ul>
<li><a class="link" href="/program.php">Methods</a></li>
<li><a class="link" href="/schedule.php">Schedule</a></li>
<li><a class="link" href="locations.php">Locations</a></li>
<li><a class="link" href="reading.php">Reading</a></li>
</ul>
</li>
<li><a class="link" class="titlebar" href="contact.php">Contact</a></li>
<li><a class="sm_parent" onClick="return true">About</a>
<ul>
<li><a class="link" href="/about.php">The Coaches</a></li>
<li><a class="link" href="/mission.php">Mission Statement</a></li>
<li><a class="link" href="/testimonials.php">Testimonials</a></li>
<li><a class="link" href="/gallery.php">Gallery</a></li>
</ul>
</li>
</ul>
</div> <!-- menu -->
CSS:
#menu
{
display: block;
position: absolute;
white-space:nowrap;
z-index: 3;
}
#menu a.link:hover
{
color: #ffffff;
border: 1px solid #FFE135;
border-radius: 6px;
margin: 0px; /* needed to offset 1px border */
}
#menu a.sm_parent:hover /* sm_parent = submenu parent, has no link */
{
cursor: default;
}
#menu > ul /* top level ul only */
{
padding-left: 15px;
padding-right: 15px;
margin: 0;
}
#menu ul /* all ul's*/
{
display: inline-table;
position: relative;
list-style: none;
z-index: 3;
}
#menu ul li
{
float: left;
text-align: left;
}
#menu ul li a
{
display: block;
padding: 4px 20px;
color: #FFE135;
text-decoration: none;
margin: 1px; /* hover will replace this with 1px border, prevents shifting */
z-index: 3;
}
#menu ul li a:link { color: #FFE135; }
#menu ul li a:visited { color: #FFE135; }
#menu ul li a:active { color: #FFE135;}
#menu ul li:hover > ul
{
visibility: visible;
opacity: 1.0;
}
#menu ul li ul
{
visibility: hidden;
opacity: 0.0;
-webkit-transition: all 0.4s ease-in-out 0.0s;
-moz-transition: all 0.4s ease-in-out 0.0s;
-ms-transition: all 0.4s ease-in-out 0.0s;
-o-transition: all 0.4s ease-in-out 0.0s;
transition: all 0.4s ease-in-out 0.0s;
}
#menu ul ul
{
display: block;
background: black;
border-radius: 8px;
padding: 2px 8px;
position: absolute;
z-index: 3;
/*
top: 100% works with Chrrome, etc but not with IE, (of course) but not with
margin and or border values adding margin & border values between top menu (ul)
and submenu (ul) will require more % value deduction
*/
top: 88%;
}
#menu ul ul li
{
display: block;
position: relative;
float: none;
}
#menu ul ul > li
{
/* submenus with slightly smaller font */
font-size: 90%;
}
#menu ul ul li a
{
padding: 4px 10px;
}
#menu ul ul ul
{
/* 2nd generation submenu open to right of 1st generation dropdown submenus */
position: absolute; left: 100%; top:0;
}
#menu ul ul ul > li
{
/* This prevents 2nd generation > submenus from having ever diminishing font size*/
font-size: 100%;
}
First i noticed website is not responsive. most of the time drop downs not good for the Mobile equipment like IPod,Ipad and Android mobile. but if you can make responsive website with menu. you can get very good touch friendly user experience.
Here example mobile navigation : http://osvaldas.info/drop-down-navigation-responsive-and-touch-friendly
Related
I'm using ul to show the navigation bar in my homepage. I want to show a different color to any navigation bar which is focused. How can I do that on element li
Here is my code
<div id="menubar">
<ul id="menu" >
<!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
<li tabindex="1"><a href="#" >Home</a></li>
<li tabindex="1" ><a href="#" >Projects</a></li>
<li tabindex="1" ><a href="#" >Publications</a></li>
<li tabindex="1" ><a href="#" >News</a></li>
<li tabindex="1"><a href="#" >Members</a></li>
<li tabindex="1"><a href="#" >Contact Us</a></li>
</ul>
</div>
and style I'm trying is
background: #00C6F0;
But due to some unknown reason I"m unable to do so . Please help
You're overcomplicating your code. There is a <nav> tag in HTML5.
You do not need all those "wrappers" and tabindex is unnecessary too.
a {display:block}
a:focus {background: #00C6F0}
a:nth-child(2):focus {background: #f90}
a:nth-child(3):focus {background: #f99}
a:nth-child(4):focus {background: #f41}
a:nth-child(5):focus {background: #cfa}
a:nth-child(6):focus {background: #afc}
<nav>
Home
Projects
Publications
News
Members
Contact Us
</nav>
If you would like to have different background colours when you tab through the menu vs simply hovering over it, you can use this example here:
The important parts are the
.navbar ul li a[tabindex="1"]:focus {
background: #00C6F0;
}
as these select the individual tab-indexes while they are in focus. If you want all the menu items to have the same colour while tabbing though it, you can remove the tab-indexes 2-7 etc, and just have the selector as .navbar ul li a[tabindex]:focus
.navbar ul li a[tabindex="1"]:focus {
background: #00C6F0;
}
.navbar ul li a[tabindex="2"]:focus {
background: #feca57;
}
.navbar ul li a[tabindex="3"]:focus {
background: #ff6b6b;
}
.navbar ul li a[tabindex="4"]:focus {
background: #48dbfb;
}
.navbar ul li a[tabindex="5"]:focus {
background: #5f27cd;
}
.navbar ul li a[tabindex="6"]:focus {
background: #8395a7;
}
.navbar ul li a[tabindex="7"]:focus {
background: #10ac84;
}
* {
box-sizing: border-box;
}
.navbar {
text-align: center;
margin: 20px 0;
position: relative;
background: #E51573;
}
.navbar ul {
padding: 0;
}
.navbar ul li {
display: inline-block;
line-height: 30px;
font-size: 14px;
text-transform: uppercase;
padding: 0;
-webkit-transition: ease-in-out .15s;
-o-transition: ease-in-out .15s;
transition: ease-in-out .15s;
}
.navbar ul li:hover {
background: #EE2C86;
color: white;
}
.navbar ul li a {
display: inline-block;
color: white;
padding: 5px 9px;
text-decoration: none;
-webkit-transition: ease-in-out .15s;
-o-transition: ease-in-out .15s;
transition: ease-in-out .15s;
width: 100%;
font-weight: bold;
}
.navbar ul li a:hover {
background: #EE2C86;
color: white;
}
.navbar ul li:hover a {
color: white;
}
.navbar ul li a.active {
color: #FFF;
background: #71261F;
}
.navbar ul li:hover ul {
display: block;
}
.navbar ul li ul {
display: none;
position: absolute;
background: #9D9FA2;
padding: 0;
z-index: 200;
}
.navbar ul li ul li {
border: none;
padding: 0;
display: block;
}
.navbar ul li ul li:hover {
border-radius: 0;
}
.navbar ul li ul li:first-child {
border: none;
}
.navbar ul li ul li a {
margin: 5px 0;
color: white;
}
.navbar ul li ul li a:hover {
border-radius: 0;
}
.navbar ul li ul ul {
position: absolute;
left: 200px;
top: 0;
display: none;
}
.navbar ul li li:hover ul {
display: block!important;
}
<div class="navbar">
<ul>
<li><a tabindex="1" href="#">Home</a></li>
<li><a tabindex="2" href="#">Menu2</a>
<ul>
<li>Sub-Menu 1</li>
<li>Sub-Menu2
</ul>
</li>
<li><a tabindex="3" href="#">Menu3</a></li>
<li><a tabindex="4" href="#">Menu4</a></li>
<li><a tabindex="5" href="#">Menu5</a></li>
<li><a tabindex="6" href="#">Menu6</a></li>
<li><a tabindex="7" href="#">Menu7</a></li>
</ul>
</div>
You can try using the CSS :focus selector.
ul#menu li:focus{
background: #00C6F0;
}
This might help you
li a:focus {
background: #00C6F0;
}
I have a list for my navbar. I want to have a border below the active li item, not just on the bottom.
I've been able to add the border to the bottom using border-bottom, but again, it needs to be below the li element. Any help would be appreciated.
Here is my custom css so far, in addition to default Bootstrap navbar list:
.nav .active{
border-bottom: 5px solid yellow;
}
See below:
Just an example ..... use border-bottom with background-clip padding box
ul {
list-style-type: none;
}
li {
height: 50px;
width: 180px;
line-height: 50px;
border-bottom: 5px solid transparent;
background: #ddd;
display: inline-block;
text-align: center;
background-clip: padding-box;
}
li:hover {
border-bottom: 5px solid gold;
}
<ul>
<li>Hello</li>
<li>World</li>
</ul>
Altarnatively you can try box shadow. see this
ul {
list-style-type: none;
}
li {
height: 50px;
width: 180px;
line-height: 50px;
background: #ddd;
display: inline-block;
text-align: center;
}
li:hover {
box-shadow: 0 5px 0 0 gold;
}
<ul>
<li>Hello</li>
<li>World</li>
</ul>
Try like this: demo
CSS:
ul.nav {
list-style-type: none;
}
li {
display:block;
float:left;
line-height: 26px;
margin-right:10px;
background-color:#ccc;
padding:4px 10px;
border-bottom: 5px solid transparent;
}
li a{
text-decoration:none;
color:#000;
}
li:hover, li.active {
border-bottom: 5px solid red;
}
HTML:
<ul class="nav">
<li> Menu 1
</li>
<li class="active"> Menu 1
</li>
<li> Menu 1
</li>
<li> Menu 1
</li>
</ul>
I typically use an :after for small details like this, to get the border outside the menu items normal height.
HTML:
<ul>
<li>Home</li>
<li class="active">About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
<div class="main">
Next Box
</div>
CSS:
html,body{
margin:0px;
padding:0px;
}
ul{
/* for looks */
list-style:none;
margin:0px;
padding:0px;
}
li{
background:black;
color:white;
display:inline-block;
margin:0px;
padding:5px 20px;
}
li.active{
position:relative;
}
li.active:after{
content:'';
position:absolute;
top:100%;
left:0px;
border-top:5px solid yellow;
width:100%;
}
.main{
background-color:#dddddd;
min-height:400px;
}
Most of the css is just for presentation but the key stuff is on the li, the li.active, and the li.active:after.
You can check out my demo at jsfiddle
This is the sample I always use. Hope this can help you ;)
This method is using the last child of the "li" element as the border.
The class "selected" on "li" element choose the position of the border to stay at initial.
When the mouse is on one of the menu bar button, the bar will follow it by an animation.
If you don't want an animation, please just delete ALL transition CSS style in ".menu > li:last-child" class.
If you want to know more about last child CSS style, please go to this link >> http://www.w3schools.com/cssref/sel_last-child.asp
.menu, .menu li {
margin: 0;
padding: 0;
list-style: none;
display: inline-block;
}
.menu {
margin: auto;
position: relative;
overflow: hidden;
height: 25px;
}
.menu li {padding: 0px 5px;}
.menu > li {
text-align: center;
width: 80px;
font-size: 14px;
}
.menu > li > a {
display: block;
padding: 0px 0px;
color: #444;
text-decoration: none;
font-size: 15px;
-webkit-transition: color 0.5s ease;
-moz-transition: color 0.5s ease;
-ms-transition: color 0.5s ease;
-o-transition: color 0.5s ease;
transition: color 0.5s ease;
}
.menu li a:hover {
color: #ffa500;
}
.menu > li:last-child {
position: absolute;
top: 20px;
right: -90px;
height: 5px;
width: 80px;
background: #ffa500;
-webkit-transition: transform 0.5s ease;
-moz-transition: transform 0.5s ease;
-ms-transition: transform 0.5s ease;
-o-transition: transform 0.5s ease;
transition: transform 0.5s ease;
}
.menu .selected {
position: relative;
pointer-events: none;
cursor: default;
}
.selected a {
color: #ffa500 !important;
}
.menu li:nth-child(1):hover ~ li:last-child {
-webkit-transform:translateX(-375px) !important;
-moz-transform:translateX(-375px) !important;
-ms-transform:translateX(-375px) !important;
-o-transform:translateX(-375px) !important;
transform:translateX(-375px) !important;
}
.menu li:nth-child(1).selected ~ li:last-child {
-webkit-transform:translateX(-375px);
-moz-transform:translateX(-375px);
-ms-transform:translateX(-375px);
-o-transform:translateX(-375px);
transform:translateX(-375px);
}
.menu li:nth-child(2):hover ~ li:last-child {
-webkit-transform:translateX(-280px) !important;
-moz-transform:translateX(-280px) !important;
-ms-transform:translateX(-280px) !important;
-o-transform:translateX(-280px) !important;
transform:translateX(-280px) !important;
}
.menu li:nth-child(2).selected ~ li:last-child {
-webkit-transform:translateX(-280px);
-moz-transform:translateX(-280px);
-ms-transform:translateX(-280px);
-o-transform:translateX(-280px);
transform:translateX(-280px);
}
.menu li:nth-child(3):hover ~ li:last-child {
-webkit-transform:translateX(-185px) !important;
-moz-transform:translateX(-185px) !important;
-ms-transform:translateX(-185px) !important;
-o-transform:translateX(-185px) !important;
transform:translateX(-185px) !important;
}
.menu li:nth-child(3).selected ~ li:last-child {
-webkit-transform:translateX(-185px);
-moz-transform:translateX(-185px);
-ms-transform:translateX(-185px);
-o-transform:translateX(-185px);
transform:translateX(-185px);
}
.menu li:nth-child(4):hover ~ li:last-child {
-webkit-transform:translateX(-90px) !important;
-moz-transform:translateX(-90px) !important;
-ms-transform:translateX(-90px) !important;
-o-transform:translateX(-90px) !important;
transform:translateX(-90px) !important;
}
.menu li:nth-child(4).selected ~ li:last-child {
-webkit-transform:translateX(-90px);
-moz-transform:translateX(-90px);
-ms-transform:translateX(-90px);
-o-transform:translateX(-90px);
transform:translateX(-90px);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div class="menubox">
<ul class="menu">
<li class="selected">
<a href="#">
First
</a>
</li>
<li>
<a href="#">
Second
</a>
</li>
<li>
<a href="#">
Third
</a>
</li>
<li>
<a href="#">
Forth
</a>
</li>
<li></li>
</ul>
</div>
</body>
</html>
I like to know how bootstrap3 drop-down-menu system in its tutorial page works.
1. It folds all to main topic by default (you can click or scroll-up/down to expand)
2. It expands automatically when you scroll up and down or click particular menu.
3. It matches you with the topic and has some hi-light in the sub-menu
http://getbootstrap.com/css
Can this matching only complete with only css and html, or it has to deal with JavaScript also?
If it can be both way what is the suit case for it uses.
This is PURE CSS solution of bootstrap dropdown menu, here is working fiddle
http://jsfiddle.net/DTcHh/1837/
HTML
<nav>
<ul>
<li>
Has Dropdown
<ul>
<li>
Change password </li>
<li>
Edit personal data
</li>
</ul>
</li>
<li>
Support
</li>
<li>
Logout
</li>
</ul>
</nav>
CSS
nav > ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
color: #555;
}
nav > ul li {
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 10px;
background: #fff;
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;
}
nav > ul li:hover {
background-color: #e7e7e7;
color: #555;
}
nav > ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
min-width: 225px;
display: none;
opacity: 0;
visibility: hidden;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, 0.15);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.176);
font-size: 14px;
list-style: outside none none;
padding: 5px 0;
text-align: left;
z-index: 10000;
}
nav > ul li ul li {
background-color: transparent;
display: block;
color: #262626;
width:90%;
text-align:left;
padding-left:10px;
padding-right:10px;
text-transform:uppercase;
}
nav > ul li ul li:hover {
background-color: #f5f5f5;
color: #262626;
text-decoration:none;
}
nav > ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
ul li ul a li i{
padding-right:5px;
}
nav ul li ul a li{
color:grey !important;
}
nav ul li ul a{
color:grey;
font-size:12px;
}
Please can someone help?
How can I centre this CSS menu?
See below for the beginning of the code
Whatever I try doesn't seem to work.
I'm sure it is quite simple really but I cannot figure it out.
Thanks in advance!
#cssmenu {
position: relative;
height: 44px;
background: #ffffff;
width: auto;
float: left;
}
#cssmenu ul {
list-style: none;
padding: 0;
margin: 0;
line-height: 1;
position:relative;
display: inline-block;
vertical-align: top;
}
#cssmenu > ul {
position: relative;
display: block;
background: #ffffff;
height: 32px;
width: 100%;
z-index: 500;
}
#cssmenu > ul > li {
display: block;
position: relative;
float: left;
margin: 0;
padding: 0;
position:relative;
}
#cssmenu > ul > #menu-button {
display: none;
}
#cssmenu ul li a {
display: block;
font-family: 'Noto Sans';
text-decoration: none;
}
#cssmenu > ul > li > a {
font-size: 14px;
font-weight: bold;
padding: 15px 20px;
color: #000000;
text-transform: uppercase;
-webkit-transition: color 0.25s ease-out;
-moz-transition: color 0.25s ease-out;
-ms-transition: color 0.25s ease-out;
-o-transition: color 0.25s ease-out;
transition: color 0.25s ease-out;
}
#cssmenu > ul > li.has-sub > a {
padding-right: 32px;
}
#cssmenu > ul > li:hover > a {
color: #000000;
}
#cssmenu li.has-sub::after {
display: block;
content: '';
position: absolute;
width: 0;
height: 0;
}
#cssmenu > ul > li.has-sub::after {
right: 10px;
top: 20px;
border: 5px solid transparent;
border-top-color: #000000;
}
#cssmenu > ul > li:hover::after {
border-top-color: #000000;
}
HTML
<div id='cssmenu'>
<ul>
<li class='active'><a href='index.html'><span>Home</span></a></li>
<li class='has-sub'><a href='#'><span>Products</span></a>
<ul>
<li class='has-sub'><a href='#'><span>Product 1</span></a>
<ul>
<li><a href='#'><span>Sub Item</span></a></li>
<li class='last'><a href='#'><span>Sub Item</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Product 2</span></a>
<ul>
<li><a href='#'><span>Sub Item</span></a></li>
<li class='last'><a href='#'><span>Sub Item</span></a></li>
</ul>
</li>
</ul>
</li>
<li><a href='#'><span>About</span></a></li>
<li class='last'><a href='#'><span>Contact</span></a></li>
</ul>
</div>
One way of doing it is by setting the display type of #cssmenu to inline-block and then wrap everything in a container with text-align: center. You also need to set text-align: left on #cssmenu such that the text aligns correctly again.
JSFiddle
Ok, I'm going to assume that in your HTML, the #cssmenu element is the one you are trying to center.
As others have said, block elements can be centered by using a width: and a margin: 0 auto.
The dilema here is that if you set a width to it, then you have to adjust the width everytime the menu items change, so what I do is leave it without a width attribute and only enhance it (center it) for users with JS support.
If using jQuery, you could do something like this:
function navCenter(){
if($('#cssmenu').length){
var ulWidth = 0;
$('#cssmenu > ul > li').each(function(){
ulWidth += $(this).outerWidth(true);
});
$('#cssmenu').css('width', ulWidth);
}
}
So the above piece of code sets a width on the #cssmenu element and the css applies a margin: 0 auto, centering it.
Let me know if this make sense.
This is how you can center the ul with all its list-items in a container without js or jquery. There's no need to adjust something if the list-items are changed.
<div class="menuwrapper">
<ul class="nav">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
.menuwrapper {
width: 100%;
text-align: center;
}
.nav, .nav li, .nav a {
margin: 0;
padding: 0;
border: 0;
}
.nav {
float: left;
position: relative;
left: 50%;
top: 0;
list-style-type: none;
text-align: center;
}
.nav li {
float: left;
width: auto;
right: 50%;
display: block;
position: relative;
list-style-type: none;
cursor: pointer;
}
.nav a {
display: block;
padding: 8px 10px;
text-decoration: none;
font: bold 16px arial,sans-serif;
line-height: 1;
outline: 0;
}
JSFiddle: http://jsfiddle.net/x6bM3/
If you hover over the products link you will see i have created a drop down effect, but what im trying to do is give it a nice transition instead of it just appearing.
I have tried using :hover with the css transitions on various parts of the menu, but after researching it i realised the animation wont work with display: none; on it. Please help,
Thanks in advance,
Adam
CSS:
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
list-style: none;
position: relative;
display: inline-table;
margin-top: 23px;
padding: 0;
float: left;
}
nav ul:after {
content:"";
display: block;
}
nav ul li {
float: left;
height: 50px;
width: auto;
padding: 5px;
margin-left: 22px;
}
nav ul li a {
display: block;
text-decoration: none;
}
nav ul ul {
background: #363c43;
border-radius: 3px;
border: 1px solid #2e363f;
padding: 7px;
position: absolute;
font-size: 0.9em;
}
nav ul ul:before {
content:'';
display:block;
width:0;
height:0;
position:absolute;
border-right: 7px solid transparent;
border-left: 7px solid transparent;
border-bottom:10px solid #363c43;
top:-8px;
left: 30px;
}
nav ul ul li {
height: 30px;
float: none;
position: relative;
padding: 0px 0px 5px 0px;
margin: 0px;
}
/* Other base styles */
* {
font-family: arial;
}
a:link, a:visited {
color: #979797;
font-size: 1.145em;
/* 18px */
text-decoration: none;
font-weight: lighter;
-webkit-transition: all .25s linear;
transition: color .25s linear;
}
a:hover {
color: #c4c1c1;
font-size: 1.145em;
/* 22px */
text-decoration: none;
}
HTML:
<nav>
<ul class="menu">
<li>home
</li>
<li>products
<ul>
<li>product 1
</li>
<li>product 2
</li>
</ul>
</li>
<li>solutions
</li>
</ul>
</nav>
I can explain in detail, but this person does a great job: https://stackoverflow.com/a/3332179/363605
nav ul ul {
display: block;
-webkit-transition: opacity 1s ease-in;
-moz-transition: opacity 1s ease-in;
-o-transition: opacity 1s ease-in;
transition: opacity 1s ease-in;
opacity: 0;
height: 0;
overflow: hidden;
}
nav ul li:hover > ul {
height: auto;
opacity: 1;
}
http://jsfiddle.net/pYhrk/