I spent a bit of time creating a new navigation menu for a project. I used float elements in my CSS file which seems to play an important factor in keeping my navigation menu keep its appearance. But currently the alignment of the navigation menu is off and my goal is to have it centered in the view.
header {
background: #3d4144 url("../img/bg.png") 0 0 repeat;
border-bottom: 5px solid #ddd;
height: 170px;
padding-top: 15px;
}
#title {
color: white;
display: block;
letter-spacing: 2px;
margin-left: 50px;
padding: 20px;
position: relative;
text-align: left;
}
#headerMessage {
color: white;
display: block;
letter-spacing: 2px;
padding: 20px;
position: relative;
text-align: center;
}
.container {
margin: 0 auto;
width: 540px;
}
#navHeader {
-webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.06);
background: #464b4c;
background-image: -webkit-linear-gradient(top, #464b4c, #3f4344);
background-image: -moz-linear-gradient(top, #464b4c, #3f4344);
background-image: -o-linear-gradient(top, #464b4c, #3f4344);
background-image: linear-gradient(to bottom, #464b4c, #3f4344);
border-top: 1px solid #353939;
border-bottom: 1px solid #2e3131;
box-shadow: inset 0 1px rgba(255, 255, 255, 0.06);
height: 36px;
}
#navHeader a {
-webkit-transition: 0.1s ease-out;
-moz-transition: 0.1s ease-out;
-o-transition: 0.1s ease-out;
transition: 0.1s ease-out;
-webkit-transition-property: background-color, line-height;
-moz-transition-property: background-color, line-height;
-o-transition-property: background-color, line-height;
transition-property: background-color, line-height;
text-align: center;
}
#navHeader #navHeaderUL {
float: left;
border-left: 1px solid #353939;
border-left: 1px solid rgba(0, 0, 0, 0.2);
border-right: 1px solid #4d5354;
border-right: 1px solid rgba(255, 255, 255, 0.06);
}
#navHeader li {
float: left;
}
#navHeader a {
display: block;
padding: 0 20px;
line-height: 36px;
color: #ddd;
text-decoration: none;
text-shadow: 0 -1px #2e3131;
border-left: 1px solid #4d5354;
border-left: 1px solid rgba(255, 255, 255, 0.06);
border-right: 1px solid #353939;
border-right: 1px solid rgba(0, 0, 0, 0.2);
cursor: pointer;
}
#navHeader a:hover {
background: #4d5354;
background: rgba(255, 255, 255, 0.05);
}
#navHeader li.active a,
#navHeader li.active a:hover,
#navHeader a:active {
padding: 0 21px;
line-height: 33px;
color: #eee;
background: #323637;
border-left: 0;
border-right: 0;
border-bottom: 3px solid #48a9c0;
background-image: -webkit-linear-gradient(top, #484e4f, #323637);
background-image: -moz-linear-gradient(top, #484e4f, #323637);
background-image: -o-linear-gradient(top, #484e4f, #323637);
background-image: linear-gradient(to bottom, #484e4f, #323637);
-webkit-box-shadow: inset 0 -1px #151717, inset 0 -1px 8px rgba(0, 0, 0, 0.2);
box-shadow: inset 0 -1px #151717, inset 0 -1px 8px rgba(0, 0, 0, 0.2);
}
#navHeader li.green a,
#navHeader li.green a:active {
border-bottom-color: #56c93d;
}
#navHeader li.red a,
#navHeader li.red a:active {
border-bottom-color: #a54e49;
}
#navHeader li.purple a,
#navHeader li.purple a:active {
border-bottom-color: #c052b9;
}
#navHeader li.yellow a,
#navHeader li.yellow a:active {
border-bottom-color: #c0bb30;
}
<header>
<h1 id="title">Insert Title</h1>
<h2 id="headerMessage">INSERT MESSAGE!</h2>
<nav id="navHeader">
<div class="container">
<ul id="navHeaderUL">
<li class="active">Home
<li class="green">Schedule
<li class="red">Track
<li class="yellow">Contact
</ul>
</div>
<!-- end of container -->
</nav>
<!-- end of navHeader -->
</header>
You can remove line-height on #navHeader a which is causing the off vertical alignment (or is this intended?).
Remove float and set display: inline-block so you can horizontally center the ul with text-align: center.
Please find CSS tweaks commented below.
header {
background: #3d4144 url("../img/bg.png") 0 0 repeat;
border-bottom: 5px solid #ddd;
height: 170px;
padding-top: 15px;
}
#title {
color: white;
display: block;
letter-spacing: 2px;
margin-left: 50px;
padding: 20px;
position: relative;
text-align: left;
}
#headerMessage {
color: white;
display: block;
letter-spacing: 2px;
padding: 20px;
position: relative;
text-align: center;
}
.container {
margin: 0 auto;
width: 540px;
}
#navHeader {
-webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.06);
background: #464b4c;
background-image: -webkit-linear-gradient(top, #464b4c, #3f4344);
background-image: -moz-linear-gradient(top, #464b4c, #3f4344);
background-image: -o-linear-gradient(top, #464b4c, #3f4344);
background-image: linear-gradient(to bottom, #464b4c, #3f4344);
border-top: 1px solid #353939;
border-bottom: 1px solid #2e3131;
box-shadow: inset 0 1px rgba(255, 255, 255, 0.06);
height: 36px;
}
#navHeader a {
-webkit-transition: 0.1s ease-out;
-moz-transition: 0.1s ease-out;
-o-transition: 0.1s ease-out;
transition: 0.1s ease-out;
-webkit-transition-property: background-color, line-height;
-moz-transition-property: background-color, line-height;
-o-transition-property: background-color, line-height;
transition-property: background-color, line-height;
text-align: center;
}
#navHeader #navHeaderUL {
/* new */
text-align: center;
/*float: left;*/
border-left: 1px solid #353939;
border-left: 1px solid rgba(0, 0, 0, 0.2);
border-right: 1px solid #4d5354;
border-right: 1px solid rgba(255, 255, 255, 0.06);
}
#navHeader li {
/* new*/
float: none;
display: inline-block;
}
#navHeader a {
display: block;
padding: 0 20px;
/*new*/
/*margin-top: -6px;*/
/*line-height: 36px;*/
color: #ddd;
text-decoration: none;
text-shadow: 0 -1px #2e3131;
border-left: 1px solid #4d5354;
border-left: 1px solid rgba(255, 255, 255, 0.06);
border-right: 1px solid #353939;
border-right: 1px solid rgba(0, 0, 0, 0.2);
cursor: pointer;
}
#navHeader a:hover {
background: #4d5354;
background: rgba(255, 255, 255, 0.05);
}
#navHeader li.active a,
#navHeader li.active a:hover,
#navHeader a:active {
padding: 0 21px;
/*new*/
margin-top: -6px;
/*line-height: 33px;*/
color: #eee;
background: #323637;
border-left: 0;
border-right: 0;
border-bottom: 3px solid #48a9c0;
background-image: -webkit-linear-gradient(top, #484e4f, #323637);
background-image: -moz-linear-gradient(top, #484e4f, #323637);
background-image: -o-linear-gradient(top, #484e4f, #323637);
background-image: linear-gradient(to bottom, #484e4f, #323637);
-webkit-box-shadow: inset 0 -1px #151717, inset 0 -1px 8px rgba(0, 0, 0, 0.2);
box-shadow: inset 0 -1px #151717, inset 0 -1px 8px rgba(0, 0, 0, 0.2);
}
#navHeader li.green a,
#navHeader li.green a:active {
border-bottom-color: #56c93d;
}
#navHeader li.red a,
#navHeader li.red a:active {
border-bottom-color: #a54e49;
}
#navHeader li.purple a,
#navHeader li.purple a:active {
border-bottom-color: #c052b9;
}
#navHeader li.yellow a,
#navHeader li.yellow a:active {
border-bottom-color: #c0bb30;
}
<header>
<h1 id="title">Insert Title</h1>
<h2 id="headerMessage">INSERT MESSAGE!</h2>
<nav id="navHeader">
<div class="container">
<ul id="navHeaderUL">
<li class="active">Home
<li class="green">Schedule
<li class="red">Track
<li class="yellow">Contact
</ul>
</div>
<!-- end of container -->
</nav>
<!-- end of navHeader -->
</header>
Related
I'm trying to adjust the spacing(gap) between menu so it'll fit with the navbar.By changing margin doesn't seems to do it. Anyone have idea on how to fix this ? Is it possible to re-position each menu individually ?
Here's the demo
#navbar {
width: 1200px;
height: 180px;
background: url(http://i67.tinypic.com/5cygax.png) no-repeat center center;
background-size: contain;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
margin-left: 80px;
margin-top: 100px;
}
#menu {
display: inline-block;
margin: 65px 50px 0px 100px;
position: relative;
float: left;
width: 100px;
padding: 0 10px;
border-radius: 8px;
box-shadow: inset 0 1px 1px rgba(255, 255, 255, .5), inset 0 -1px 0 rgba(0, 0, 0, .15), 0 1px 3px rgba(0, 0, 0, .15);
background: #8495F5;
}
#menu,
#menu ul {
list-style: none;
}
#menu: li {
float: left;
position: relative;
border-right: 1px solid rgba(0, 0, 0, .1);
box-shadow: 1px 0 0 rgba(255, 255, 255, .25);
perspective: 1000px;
}
#menu: li:first-child {
border-left: 1px solid rgba(255, 255, 255, .25);
box-shadow: -1px 0 0 rgba(0, 0, 0, .1), 1px 0 0 rgba(255, 255, 255, .25);
}
#menu a {
display: block;
position: inherit;
z-index: 10;
padding: 15px 20px 15px 20px;
text-decoration: none;
color: rgba(75, 75, 75, 1);
line-height: 1;
font-family: sans-serif;
font-weight: 700;
font-size: 12px;
letter-spacing: 0.15em;
background: transparent;
text-shadow: 0 1px 1px rgba(255, 255, 255, .9);
transition: all .25s ease-in-out;
text-align: center;
}
#menu: li:hover>a {
background: #333;
color: rgba(0, 223, 252, 1);
text-shadow: none;
}
#menu li ul {
position: absolute;
left: 0;
z-index: 1;
width: 250px;
padding: 0;
opacity: 0;
visibility: hidden;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
background: transparent;
overflow: hidden;
transform-origin: 50% 0%;
}
#menu li:hover ul {
padding: 5px 0;
background: #333;
opacity: 1;
visibility: visible;
box-shadow: 1px 1px 7px rgba(0, 0, 0, .5);
animation-name: swingdown;
animation-duration: 1s;
animation-timing-function: ease;
}
#keyframes swingdown {
0% {
opacity: .99999;
transform: rotateX(90deg);
}
30% {
transform: rotateX(-20deg) rotateY(5deg);
animation-timing-function: ease-in-out;
}
65% {
transform: rotateX(20deg) rotateY(-3deg);
animation-timing-function: ease-in-out;
}
100% {
transform: rotateX(0);
animation-timing-function: ease-in-out;
}
}
#menu li li a {
padding-left: 15px;
font-weight: 400;
color: #ddd;
text-shadow: none;
border-top: dotted 1px transparent;
border-bottom: dotted 1px transparent;
transition: all .15s linear;
}
#menu li li a:hover {
color: rgba(0, 223, 252, 1);
border-top: dotted 1px rgba(255, 255, 255, .15);
border-bottom: dotted 1px rgba(255, 255, 255, .15);
background: rgba(0, 223, 252, .02);
}
<div id="container">
<div id="navbar">
<ul id="menu">
<li><a class="home" href="#">Home</a></li>
</ul>
<ul id="menu">
<li><a class="register" href="#">Register</a></li>
</ul>
<ul id="menu">
<li><a class="guide" href="#">Guide</a>
<ul>
<li>New Features</li>
<li>Quest & Event Guide</li>
<li>Brigand & T-map Guide</li>
</ul>
</ul>
<ul id="menu">
<li><a class="download" href="#">Download</a>
<ul>
<li>Patch Download</li>
</ul>
</ul>
</div>
</div>
I am guessing you want something like this?
The last lines in the CSS will control each LI position.
SOURCE:
#navbar{
width: 1200px;
height: 180px;
background: url(http://i67.tinypic.com/5cygax.png) no-repeat center center;
background-size: contain;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
margin-left: 80px;
margin-top: 100px;
}
ul#menu {
display: inline-block;
margin: 65px 0 0px 195px;
position: relative;
width: 800px;
list-style-type:none;
}
ul#menu, ul#menu-sub {
list-style-type: none;
}
ul#menu > li {
padding: 0 10px;
box-shadow: inset 0 1px 1px rgba(255,255,255,.5), inset 0 -1px 0 rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.15);
background: #8495F5;
width: 100px;
float: left;
position: relative;
display: inline-block;
border-right: 1px solid rgba(0,0,0,.1);
box-shadow: 1px 0 0 rgba(255,255,255,.25);
border-radius: 8px;
}
#menu li:first-child {
border-left: 1px solid rgba(255,255,255,.25);
box-shadow: -1px 0 0 rgba(0,0,0,.1), 1px 0 0 rgba(255,255,255,.25);
}
#menu a.menu-top {
display: block;
position: inherit;
z-index: 10;
padding: 15px 20px 15px 20px;
text-decoration: none;
color: rgba(75,75,75,1);
line-height: 1;
font-family: sans-serif;
font-weight: 700;
font-size: 12px;
letter-spacing: 0.15em;
background: transparent;
text-shadow: 0 1px 1px rgba(255,255,255,.9);
transition: all .25s ease-in-out;
text-align: center;
}
#menu-sub {
position: absolute;
left: 0;
z-index: 1;
width: 250px;
padding: 0;
opacity: 0;
visibility: hidden;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
background: transparent;
overflow: hidden;
transform-origin: 50% 0%;
}
#menu-sub a {
padding-left: 15px;
font-weight: 400;
color: #ddd;
text-shadow: none;
border-top: dotted 1px transparent;
border-bottom: dotted 1px transparent;
transition: all .15s linear;
padding: 10px;
display:block;
}
#menu-sub a:hover {
color: rgba(0,223,252,1);
border-top: dotted 1px rgba(255,255,255,.15);
border-bottom: dotted 1px rgba(255,255,255,.15);
background: rgba(0,223,252,.02);
}
#menu-sub li:hover > a {
background: #333;
color: rgba(0,223,252,1);
text-shadow: none;
}
#menu li:hover #menu-sub {
padding: 5px 0;
background: #333;
opacity: 1;
visibility: visible;
box-shadow: 1px 1px 7px rgba(0,0,0,.5);
animation-name: swingdown;
animation-duration: 1s;
animation-timing-function: ease;
}
#keyframes swingdown {
0% {
opacity: .99999;
transform: rotateX(90deg);
}
30% {
transform: rotateX(-20deg) rotateY(5deg);
animation-timing-function: ease-in-out;
}
65% {
transform: rotateX(20deg) rotateY(-3deg);
animation-timing-function: ease-in-out;
}
100% {
transform: rotateX(0);
animation-timing-function: ease-in-out;
}
}
/* controlling each li's position */
ul#menu li:nth-child(1) { /*first */
margin-right: 3%
}
ul#menu li:nth-child(2) { /*first */
margin-right: 200px;
}
ul#menu li:nth-child(3) { /*first */
margin-right: 3%
}
ul#menu li:nth-child(4) { /*first */
margin-right: 0;
}
<div id="container">
<div id="navbar">
<ul id="menu">
<li><a class="menu-top home" href="#">Home</a></li>
<li><a class="menu-top register" href="#">Register</a></li>
<li>
<a class="menu-top guide" href="#">Guide</a>
<ul id="menu-sub">
<li>New Features</li>
<li>Quest & Event Guide</li>
<li>Brigand & T-map Guide</li>
</ul>
</li>
<li>
<a class="menu-top download" href="#">Download</a>
<ul id="menu-sub">
<li>Patch Download</li>
</ul>
</li>
</ul>
</div>
</div>
View Pen: Adjust gap between menu
Changed margin for #menu
#menu {
margin: 65px 0 0px 20px;
}
#navbar {
width: 1200px;
height: 180px;
background: url(http://i67.tinypic.com/5cygax.png) no-repeat center center;
background-size: contain;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
margin-left: 80px;
margin-top: 100px;
}
#menu {
display: inline-block;
margin: 65px 0 0px 20px;
position: relative;
float: left;
width: 100px;
padding: 0 10px;
border-radius: 8px;
box-shadow: inset 0 1px 1px rgba(255, 255, 255, .5), inset 0 -1px 0 rgba(0, 0, 0, .15), 0 1px 3px rgba(0, 0, 0, .15);
background: #8495F5;
}
#menu,
#menu ul {
list-style: none;
}
#menu: li {
float: left;
position: relative;
border-right: 1px solid rgba(0, 0, 0, .1);
box-shadow: 1px 0 0 rgba(255, 255, 255, .25);
perspective: 1000px;
}
#menu: li:first-child {
border-left: 1px solid rgba(255, 255, 255, .25);
box-shadow: -1px 0 0 rgba(0, 0, 0, .1), 1px 0 0 rgba(255, 255, 255, .25);
}
#menu a {
display: block;
position: inherit;
z-index: 10;
padding: 15px 20px 15px 20px;
text-decoration: none;
color: rgba(75, 75, 75, 1);
line-height: 1;
font-family: sans-serif;
font-weight: 700;
font-size: 12px;
letter-spacing: 0.15em;
background: transparent;
text-shadow: 0 1px 1px rgba(255, 255, 255, .9);
transition: all .25s ease-in-out;
text-align: center;
}
#menu: li:hover>a {
background: #333;
color: rgba(0, 223, 252, 1);
text-shadow: none;
}
#menu li ul {
position: absolute;
left: 0;
z-index: 1;
width: 250px;
padding: 0;
opacity: 0;
visibility: hidden;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
background: transparent;
overflow: hidden;
transform-origin: 50% 0%;
}
#menu li:hover ul {
padding: 5px 0;
background: #333;
opacity: 1;
visibility: visible;
box-shadow: 1px 1px 7px rgba(0, 0, 0, .5);
animation-name: swingdown;
animation-duration: 1s;
animation-timing-function: ease;
}
#keyframes swingdown {
0% {
opacity: .99999;
transform: rotateX(90deg);
}
30% {
transform: rotateX(-20deg) rotateY(5deg);
animation-timing-function: ease-in-out;
}
65% {
transform: rotateX(20deg) rotateY(-3deg);
animation-timing-function: ease-in-out;
}
100% {
transform: rotateX(0);
animation-timing-function: ease-in-out;
}
}
#menu li li a {
padding-left: 15px;
font-weight: 400;
color: #ddd;
text-shadow: none;
border-top: dotted 1px transparent;
border-bottom: dotted 1px transparent;
transition: all .15s linear;
}
#menu li li a:hover {
color: rgba(0, 223, 252, 1);
border-top: dotted 1px rgba(255, 255, 255, .15);
border-bottom: dotted 1px rgba(255, 255, 255, .15);
background: rgba(0, 223, 252, .02);
}
<div id="container">
<div id="navbar">
<ul id="menu">
<li><a class="home" href="#">Home</a></li>
</ul>
<ul id="menu">
<li><a class="register" href="#">Register</a></li>
</ul>
<ul id="menu">
<li><a class="guide" href="#">Guide</a>
<ul>
<li>New Features</li>
<li>Quest & Event Guide</li>
<li>Brigand & T-map Guide</li>
</ul>
</ul>
<ul id="menu">
<li><a class="download" href="#">Download</a>
<ul>
<li>Patch Download</li>
</ul>
</ul>
</div>
</div>
I am trying to figure out why it can not align correctly. I have tried: display, align changing the margins, changing the padding, changing the position. event the top or doing a float on it.
Photo of what it looks like
.headerMenu {
background-color: #272626;
Height: 56px;
border-bottom: 0px;
padding-left: auto;
padding-right: auto;
width: 100%;
}
#wrapper {
margin-left: auto;
margin-right: auto;
width: 1000px;
padding-top: 0px;
padding-bottom: 0px;
}
.logo {
padding-top: 9px;
padding-bottom: 9px;
width: 38px;
transition-timing-function: linear;
transition: all 2s;
}
.logo .img {
background-image: url(../img/logo-white-p.png);
width: 38px;
height: 38px;
transition-timing-function: linear;
transition: all 0.5s;
}
.logo:hover {
background-color: rgba(255, 255, 255, 1.00);
}
.logo .img:hover {
background-image: url(../img/logo-black-p.png);
}
.search_box {
position: absolute;
top: 13px;
margin-left: 155px;
}
#search input[type="text"] {
background: url(../img/search-icon-white.png) no-repeat 10px 6px #000;
outline: none;
border: 0 none;
font: bold 12px;
color: #fff;
width: 350px;
padding: 6px 15px 6px 35px;
text-shadow: 0 2px 2px rgba(255, 255, 255, 0.30);
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
-webkit-transition: all 0.7s ease 0s;
-moz-transition: all 0.7s ease 0s;
-o-transition: all 0.7s ease 0s;
-transition: all 0.7s ease 0s;
}
#search input[type="text"]:focus {
background: url(../img/search-icon.png) no-repeat 10px 6px #fff;
color: #6a6f75;
width: 350px;
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.9) inset;
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.9) inset;
-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.9) inset;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}
#media screen and (max-width: 1280px) {
#menu {
postion: absolute;
top: 0px;
right0px;
height: 37px;
padding-top: 19px;
}
}
#menu a {
color: #000;
text-decoration: none;
font-size: 14px;
padding-top: 19px;
padding-bottom: 22px;
padding-left: 10px;
padding-right: 10px;
}
#menu a:hover {
border-bottom: 2px solid #000000;
}
<div class="headerMenu">
<div id="wrapper">
<div class="logo">
<div class="img"></div>
</div>
<div class="serch_box">
<form action="serch.php" method="get" id="search">
<input type="text" name="q" size="60px" placeholder="Search..." />
</form>
</div>
<div id="menu">
Home
About
Login
Register
</div>
</div>
</div>
Your problem lies in the fact that a div element is a block element and therefore forces itself to a new line.
If we tell the system to make each div under the #wrapper to be an inline element, then it will all line up as expected.
It also requires vertical-align: middle to make everything align to the middle of the header. If this isn't present then it sets it to the bottom of the header element.
.headerMenu {
background-color: #272626;
Height: 56px;
border-bottom: 0px;
padding-left: auto;
padding-right: auto;
width: 100%;
}
#wrapper {
margin-left: auto;
margin-right: auto;
width: 1000px;
padding-top: 0px;
padding-bottom: 0px;
}
div#wrapper > div {
display: inline-block;
vertical-align: middle;
}
.logo {
padding-top: 9px;
padding-bottom: 9px;
width: 38px;
transition-timing-function: linear;
transition: all 2s;
}
.logo .img {
background-image: url(../img/logo-white-p.png);
width: 38px;
height: 38px;
transition-timing-function: linear;
transition: all 0.5s;
}
.logo:hover {
background-color: rgba(255, 255, 255, 1.00);
}
.logo .img:hover {
background-image: url(../img/logo-black-p.png);
}
.search_box {
position: absolute;
top: 13px;
margin-left: 155px;
}
#search input[type="text"] {
background: url(../img/search-icon-white.png) no-repeat 10px 6px #000;
outline: none;
border: 0 none;
font: bold 12px;
color: #fff;
width: 350px;
padding: 6px 15px 6px 35px;
text-shadow: 0 2px 2px rgba(255, 255, 255, 0.30);
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
-webkit-transition: all 0.7s ease 0s;
-moz-transition: all 0.7s ease 0s;
-o-transition: all 0.7s ease 0s;
-transition: all 0.7s ease 0s;
}
#search input[type="text"]:focus {
background: url(../img/search-icon.png) no-repeat 10px 6px #fff;
color: #6a6f75;
width: 350px;
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.9) inset;
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.9) inset;
-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.9) inset;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}
#media screen and (max-width: 1280px) {
#menu {
postion: absolute;
top: 0px;
right0px;
height: 37px;
padding-top: 19px;
}
}
#menu a {
color: white;
text-decoration: none;
font-size: 14px;
padding-top: 19px;
padding-bottom: 22px;
padding-left: 10px;
padding-right: 10px;
}
#menu a:hover {
border-bottom: 2px solid #000000;
}
<div class="headerMenu">
<div id="wrapper">
<div class="logo">
<div class="img"></div>
</div>
<div class="serch_box">
<form action="serch.php" method="get" id="search">
<input type="text" name="q" size="60px" placeholder="Search..." />
</form>
</div>
<div id="menu">
Home
About
Login
Register
</div>
</div>
</div>
I'm having trouble with a search box that has a dropdown. In the dropdown there are links but to open the links I have to double click them. Here is a link to my jsfiddle of it https://jsfiddle.net/ag7L02u0/. Anyone have a solution?
HTML:
<form class="search" method="post" action="" >
<input type="text" name="inputSearch" id="inputSearch" placeholder="Search Username" autocomplete="off" />
<ul class="search-ac" id="user-result">
<li>Search Result #2<br /><span>Description...</span></li>
<li>Search Result #3<br /><span>Description...</span></li>
<li>Search Result #4</li>
</ul>
<input type="submit" name="search" id="search" Style="display:none;">
</form>
CSS:
.search {
position: relative;
width: 300px;
float: right;
margin-top:5px;
}
.search input {
height: 26px;
width: 100%;
padding: 5px 12px 0px 25px;
background: white url("../img/search.png") 8px 6px no-repeat;
border: 1px solid;
border-color: #a8acbc #babdcc #c0c3d2;
-webkit-appearance: textfield;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-box-shadow: inset 0 1px #e5e7ed, 0 1px #fcfcfc;
box-shadow: inset 0 1px #e5e7ed, 0 1px #fcfcfc;
}
.search input:focus {
outline: 0;
border-color: #66b1ee;
-webkit-box-shadow: 0 0 2px rgba(85, 168, 236, 0.9);
box-shadow: 0 0 2px rgba(85, 168, 236, 0.9);
}
.search input:focus + .search-ac {
display: block;
}
.search-ac {
display: none;
position: absolute;
top: 35px;
left: 0;
right: 0;
z-index: 100;
background: #fdfdfd;
border: 1px solid;
border-color: #cbcfe2 #c8cee7 #c4c7d7;
border-radius: 3px;
background-image: -webkit-linear-gradient(top, #fdfdfd, #eceef4);
background-image: -moz-linear-gradient(top, #fdfdfd, #eceef4);
background-image: -o-linear-gradient(top, #fdfdfd, #eceef4);
background-image: linear-gradient(to bottom, #fdfdfd, #eceef4);
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-webkit-padding-start: 0px;
}
.search-ac:hover {
display: block;
}
.search-ac li {
display: block;
z-index: 100000;
}
.search-ac li:first-child {
margin-top: -1px;
}
.search-ac li:first-child:before, .search-ac li:first-child:after {
content: '';
display: block;
width: 0;
height: 0;
position: absolute;
left: 50%;
margin-left: -5px;
border: 5px outset transparent;
}
.search-ac li:first-child:before {
border-bottom: 5px solid #c4c7d7;
top: -11px;
}
.search-ac li:first-child:after {
border-bottom: 5px solid #fdfdfd;
top: -10px;
}
.search-ac li:first-child:hover:before, .search-ac li:first-child:hover:after {
display: none;
}
.search-ac li:last-child {
margin-bottom: -1px;
}
.search-ac a {
display: block;
position: relative;
margin: 0 -1px;
padding: 6px 40px 6px 10px;
color: #808394;
font-weight: 500;
text-decoration: none;
text-shadow: 0 1px white;
border: 1px solid transparent;
border-radius: 3px;
z-index:110;
}
.search-ac a span {
font-weight: 200;
}
.search-ac a:before {
content: '';
position: absolute;
top: 50%;
right: 10px;
margin-top: -9px;
width: 18px;
height: 18px;
background: url("../img/arrow.png") 0 0 no-repeat;
}
.search-ac a:hover {
color: white;
text-shadow: 0 -1px rgba(0, 0, 0, 0.3);
background: #338cdf;
border-color: #2380dd #2179d5 #1a60aa;
background-image: -webkit-linear-gradient(top, #59aaf4, #338cdf);
background-image: -moz-linear-gradient(top, #59aaf4, #338cdf);
background-image: -o-linear-gradient(top, #59aaf4, #338cdf);
background-image: linear-gradient(to bottom, #59aaf4, #338cdf);
-webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.2), 0 1px rgba(0, 0, 0, 0.08);
box-shadow: inset 0 1px rgba(255, 255, 255, 0.2), 0 1px rgba(0, 0, 0, 0.08);
}
:-moz-placeholder {
color: #a7aabc;
font-weight: 200;
}
::-webkit-input-placeholder {
color: #a7aabc;
font-weight: 200;
line-height: 14px;
}
::-webkit-search-decoration,
::-webkit-search-cancel-button {
-webkit-appearance: none;
}
.lt-ie9 .search input {
line-height: 26px;
}
.btn-default{
float:right;
margin-top: -38px;
}
Have you tried changing your href attribute to something else than "#"?
I tried tour example and put there
<a href="http://stackoverflow.com" target="_">
works fine
Works for me? I just added www.google.com in the href and target="_blank" (so i didn't navigate away) and it re-directs. What are you doing with the links in your real document please.
html, body {
-webkit-font-smoothing: antialiased;
height: 100%;
/* The html and body elements cannot have any padding or margin. */
font-family: 'Open Sans', sans-serif;
background-color: #f4f5f6;
}
h1 {
font-weight: 700;
}
h2 {
letter-spacing: -1px;
font-weight: 300;
margin-top: 0;
}
h3 {
letter-spacing: -1px;
font-weight: 100;
margin-top: 0;
font-size: 4em;
}
iframe{
width: 100%;
border: 0;
}
/*#features,#support,#testimonials,#news, #bottom{background-color: #f4f5f6;}*/
/* Wrapper for page content to push down footer */
#wrap {
min-height: 100%;
height: auto!important;
height: 100%;
/* Negative indent footer by it's height */
margin: 0 auto -60px;
color: #333;
}
/* Set the fixed height of the footer here */
#push {
height: 60px;
}
/*Navbar Customizations*/
.navbar-purity {
background: #2D3538;
background-color: #2D3538;
filter: none;
background-image: none;
border: none;
box-shadow: none;
-webkit-box-shadow: none;
-mox-box-shadow: none;
-webkit-transition: background .3s ease;
-moz-transition: background .3s ease;
-o-transition: background .3s ease;
-ms-transition: background .3s ease;
transition: background .3s ease;
}
.navbar-purity {
background: rgba(46, 46, 46, 0.35);
border: none;
}
.navbar-purity .navbar-brand {
padding: 10px 5px;
}
.navbar-purity .navbar-toggle{
border-color: transparent;
}
.navbar-purity .navbar-toggle {
border-color: transparent;
}
.navbar-purity .navbar-toggle:hover,
.navbar-purity .navbar-toggle:focus {
background-color: #333;
}
.navbar-purity .navbar-toggle .icon-bar {
background-color: #fff;
}
.navbar-purity.sticky {
background: rgba(0, 0, 0, 0.7);
border-bottom: none;
}
.navbar-purity.sticky .nav > li > a:hover {
color: #fff;
background: none;
box-shadow: none;
-webkit-box-shadow: none;
-mox-box-shadow: none;
}
.navbar-purity.sticky .nav > li.active a {
background: transparent;
color: #fff;
box-shadow: none;
-webkit-box-shadow: none;
-mox-box-shadow: none;
}
.navbar-purity.sticky .nav > li a {
background: transparent;
color: #b4b4b4;
box-shadow: none;
-webkit-box-shadow: none;
-mox-box-shadow: none;
}
.navbar-purity.sticky .dropdown-menu li >a {
display: block;
clear: both;
font-weight: 400;
line-height: 20px;
white-space: nowrap;
}
.navbar-purity .sticky .dropdown-menu li > a:hover, .navbar-purity .sticky .dropdown-menu li > a:focus, .navbar-purity .sticky .dropdown-submenu:hover > a {
text-decoration: none;
color: #FFF;
background-color: #292929;
background-image: none;
}
.navbar-purity .dropdown-menu li > a:hover, .navbar .dropdown-menu li > a:focus, .navbar .dropdown-submenu:hover > a {
text-decoration: none;
color: #FFF;
background-color: #292929;
background-image: none;
}
.navbar .nav > li > .dropdown-menu:after {
border-bottom: 6px solid #383838;
}
.dropdown-menu {
margin: 5px 0 0;
border-radius: 0;
-webkit-border-radius: 0;
-moz-border-radius: 0;
background-color: #383838;
padding: 0;
border: 0;
;
}
.dropdown-menu li > a {
color: #a5a5a5;
padding: 10px;
border-bottom: 1px solid #474747;
}
.navbar-fixed-top .navbar-inner, .navbar-static-top .navbar-inner {
box-shadow: none;
-webkit-box-shadow: none;
-mox-box-shadow: none;
}
.navbar .nav > li > a {
text-shadow: none;
color: #d3d3d3;
font-size: 15px;
font-weight: 700;
text-decoration: none;
vertical-align: middle;
font-size: 15px!important;
padding: 18px;
-webkit-box-align: center;
-moz-box-align: center;
-o-box-align: center;
box-align: center;
-webkit-transition: color .3s ease;
-moz-transition: color .3s ease;
-o-transition: color .3s ease;
-ms-transition: color .3s ease;
transition: color .3s ease;
}
.navbar .nav > li > a:hover {
color: #999;
background: rgba(0, 0, 0, 0.36);
box-shadow: none;
-webkit-box-shadow: none;
-mox-box-shadow: none;
}
.navbar .nav > li.active a {
background: rgba(0, 0, 0, 0.36);
color: #999;
box-shadow: none;
-webkit-box-shadow: none;
-mox-box-shadow: none;
}
.navbar .nav > li.active a:hover {
background: rgba(0, 0, 0, 0.36);
color: #C6D0D3;
box-shadow: none;
-webkit-box-shadow: none;
-mox-box-shadow: none;
}
/* Nav bar CSS END*/
/*General Items CSS*/
#main-media {
padding-bottom: 10px;
}
section {
position: relative;
}
header {
background: url(../images/header2.jpg) no-repeat fixed #020202;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.btn-landing {
text-shadow: 0 -1px 0 #6c9a15;
color: #fff;
background-color: #8AB833;
background-image: 0;
background-image: 0;
background-image: 0 to(#6c9a15));
background-image: 0;
background-image: 0;
background-image: linear-gradient(top, #a8d651, #6c9a15);
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#a8d651', endColorstr='#6c9a15', GradientType=0);
border-color: #8AB833 #6c9a15 #6c9a15 #8AB833;
border-color: rgba(0, 0, 0, 0.25) rgba(0, 0, 0, 0.35) rgba(0, 0, 0, 0.35) rgba(0, 0, 0, 0.25);
}
.btn-landing:hover, .btn-landing:active, .btn-landing.active, .btn-landing.disabled, .btn-landing[disabled] {
background-color: #6c9a15;
}
.btn-landing:hover {
color: #fffffb;
text-shadow: 0 -1px 0 #4e7c00;
}
.btn-landing:focus {
color: #eeff97;
-webkit-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
-moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
border-color: #8AB833 #6c9a15 #6c9a15 #8AB833;
border-color: rgba(0, 0, 0, 0.25) rgba(0, 0, 0, 0.35) rgba(0, 0, 0, 0.35) rgba(0, 0, 0, 0.25);
}
.btn-landing.active, .btn-landing:active {
background-image: none;
-webkit-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
-moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
color: #eeff97;
}
.btn-landing {
font-family: Open Sans, sans-serif;
min-width: 200px;
padding: 20px;
font-size: 19px!important;
font-weight: 300;
background: #8AB833;
border-radius: 0;
When I view my page on a pc or tablet the sign up form is visible but if I view it on a mobile the form is not displayed? This has been driving me nuts for the last 4 hours and I can't seem to find the solution!
Here is my source
<!--################ HEADER START ################-->
<header id="top" data-stellar-background-ratio="0">
<div class="container home">
<div class="flexslider home">
<ul class="slides">
<li class="margintop10p">
<h1>Set Your Course For The Life You <span style="color: #f4f400"> Always Wanted</span></h1>
</li>
</ul>
</div>
<div class="col-md-12">
<div class="subscribe">
<center>
<h2 class="info-text">Sign Up For Your FREE Introductory Session.</h2>
<h4 class="info-text"> <span style="color: #FFFFFF">Discover the power of the subconscious and how to use it to live a life that you love!</span></h4>
<div class="row">
<form class="form-inline" class="infusion-form" accept-charset="UTF-8" action="https://zi258.infusionsoft.com/app/form/process/2ae00069f47efab206dbbafa757ff586" method="POST" target="_blank">
<input name="inf_form_xid" type="hidden" value="2ae00069f47efab206dbbafa757ff586" />
<input name="inf_form_name" type="hidden" value="Free Session Sign Up" />
<input name="infusionsoft_version" type="hidden" value="1.45.0.48" />
<div class="form-group">
<label class="sr-only" for="inf_field_FirstName">First Name</label>
<input class="form-control" class="infusion-field-input-container" id="inf_field_FirstName" name="inf_field_FirstName" type="text" placeholder="Enter first name" />
</div>
<div class="form-group">
<label class="sr-only" for="inf_field_Email">Email</label>
<input class="form-control" class="infusion-field-input-container" id="inf_field_Email" name="inf_field_Email" type="email" placeholder="Enter email"/>
<input class="btn btn-success btn-fill" type="submit" value="Sign Up" target="_blank"/>
</div>
</form>
</div>
</center>
</div>
</div>
<div class="social-header hidden-phone">
</div>
</div>
<div id="home-arrow" class="hidden-phone">
<i class="icon-double-angle-down icon-3x" id="iconHome"></i>
</div>
</header>
<!--################ HEADER END ################-->
It's hard to tell, but I believe it's due to your fixed height header#top.
I inspected the form to get it up in the inspection panel, then I used the chrome device emulator and selected 'Samsung Galaxy S III'. When I went into this new view, the form wasn't there. As I already selected the element, the DOM highlight showed that it was below the next content. I tried using position:absolute; z-index:10; and surely enough it was just in the wrong position. To fix this I went through all the element's ancestors and discovered it was header#top's height:...px (sorry I only just realised this value is generated from screen height at run time so won't be there in your file...). Removing this fixes the problem - I think. Hard to tell without testing it for real - after all, I only emulated.
So to fix it, try adding this to header{...}
height: auto!important;
min-height: 100vh;
I'm using this:
jsfiddle.net/wromLbq5
And am hoping to have the ability to have multiple accordion sections open at once, and on page load. By this I mean, when one opens, I don't want the other to close. Is this possible? Without javascript as well.
(Ignore all the sub accordions too- I only need one layer)
HTML
<ul class="accordion">
<li id="one" class="files">
My Files<span>495</span>
<ul class="sub-menu">
<li><em>01</em>Dropbox<span>42</span></li>
<li><em>02</em>Skydrive<span>87</span></li>
<li><em>03</em>FTP Server<span>366</span></li>
<li><em>01</em>Dropbox<span>42</span></li>
<li><em>01</em>Dropbox<span>42</span></li>
</ul>
</li>
<li id="two" class="mail">
Mail<span>26</span>
<ul class="sub-menu">
<li><em>01</em>Hotmail<span>9</span></li>
<li><em>02</em>Yahoo<span>14</span></li>
<li><em>03</em>Gmail<span>3</span></li>
</ul>
</li>
<li id="three" class="cloud">
Cloud<span>58</span>
<ul class="sub-menu">
<li><em>01</em>Connect<span>12</span></li>
<li><em>02</em>Profiles<span>19</span></li>
<li><em>03</em>Options<span>27</span></li>
</ul>
</li>
<li id="four" class="sign">
Sign Out
<ul class="sub-menu">
<li><em>01</em>Log Out</li>
<li><em>02</em>Delete Account</li>
<li><em>03</em>Freeze Account</li>
</ul>
</li>
</ul>
CSS
body {margin:50px;}
/* Reset */
.accordion,
.accordion ul,
.accordion li,
.accordion a,
.accordion span {
margin: 0;
padding: 0;
border: none;
outline: none;
}
.accordion li {
list-style: none;
}
/* Layout & Style */
.accordion li > a {
display: block;
position: relative;
min-width: 110px;
padding: 0 10px 0 40px;
height: 32px;
color: #fdfdfd;
font: bold 12px/32px Arial, sans-serif;
text-decoration: none;
text-shadow: 0px 1px 0px rgba(0,0,0, .35);
background: #6c6e74;
background: -moz-linear-gradient(top, #6c6e74 0%, #4b4d51 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6c6e74), color-stop(100%,#4b4d51));
background: -webkit-linear-gradient(top, #6c6e74 0%,#4b4d51 100%);
background: -o-linear-gradient(top, #6c6e74 0%,#4b4d51 100%);
background: -ms-linear-gradient(top, #6c6e74 0%,#4b4d51 100%);
background: linear-gradient(top, #6c6e74 0%,#4b4d51 100%);
-webkit-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
-moz-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
}
.accordion > li:hover > a,
.accordion > li:target > a {
color: #3e5706;
text-shadow: 1px 1px 1px rgba(255,255,255, .2);
/*background: url(../img/active.png) repeat-x;*/
background: #a5cd4e;
background: -moz-linear-gradient(top, #a5cd4e 0%, #6b8f1a 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a5cd4e), color-stop(100%,#6b8f1a));
background: -webkit-linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
background: -o-linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
background: -ms-linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
background: linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
}
.accordion li > a span {
display: block;
position: absolute;
top: 7px;
right: 0;
padding: 0 10px;
margin-right: 10px;
font: normal bold 12px/18px Arial, sans-serif;
background: #404247;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
-webkit-box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);
-moz-box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);
box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);
}
.accordion > li:hover > a span,
.accordion > li:target > a span {
color: #fdfdfd;
text-shadow: 0px 1px 0px rgba(0,0,0, .35);
background: #3e5706;
}
/* Images */
.accordion > li > a:before {
position: absolute;
top: 0;
left: 0;
content: '';
width: 24px;
height: 24px;
margin: 4px 8px;
background-repeat: no-repeat;
background-image: url(http://designmodo.com/demo/css3accordionmenu/img/icons.png);
background-position: 0px 0px;
}
.accordion li.files > a:before { background-position: 0px 0px; }
.accordion li.files:hover > a:before,
.accordion li.files:target > a:before { background-position: 0px -24px; }
.accordion li.mail > a:before { background-position: -24px 0px; }
.accordion li.mail:hover > a:before,
.accordion li.mail:target > a:before { background-position: -24px -24px; }
.accordion li.cloud > a:before { background-position: -48px 0px; }
.accordion li.cloud:hover > a:before,
.accordion li.cloud:target > a:before { background-position: -48px -24px; }
.accordion li.sign > a:before { background-position: -72px 0px; }
.accordion li.sign:hover > a:before,
.accordion li.sign:target > a:before { background-position: -72px -24px; }
/* Sub Menu */
.sub-menu li a {
color: #797979;
text-shadow: 1px 1px 0px rgba(255,255,255, .2);
background: #e5e5e5;
border-bottom: 1px solid #c9c9c9;
-webkit-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
-moz-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
}
.sub-menu li:hover a { background: #efefef; }
.sub-menu li:last-child a { border: none; }
.sub-menu li > a span {
color: #797979;
text-shadow: 1px 1px 0px rgba(255,255,255, .2);
background: transparent;
border: 1px solid #c9c9c9;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.sub-menu em {
position: absolute;
top: 0;
left: 0;
margin-left: 14px;
color: #a6a6a6;
font: normal 10px/32px Arial, sans-serif;
}
/* Functionality */
.accordion li > .sub-menu li {
height: 0;
overflow: hidden;
-webkit-transition: height .2s ease-in-out;
-moz-transition: height .2s ease-in-out;
-o-transition: height .2s ease-in-out;
-ms-transition: height .2s ease-in-out;
transition: height .2s ease-in-out;
}
.accordion li:target > .sub-menu li {
height: 33px;
}
I'm trying to avoid any java script.
Is this possible?
No this is not possible with only css, because your example uses the CSS3 :target selector. When you click on another item the target changes.
You cannot set state with css but you can style it. If you would like to keep each section open after clicking you would have to use javascript, but you don't need jQuery
If you would like to use javascript, this mimics the css as closely as possible while allowing the accordions to stay open. To close the accordion simply click on the title again.
var lists = document.querySelectorAll('.accordion > li > a'); // get list title links
for (var i = 0; i < lists.length; i++) { // for each list title link
lists[i].href = "javascript:void()"; // stop the page from jumping
lists[i].onclick = function(e) { // when you click the link
var items = e.target.parentNode.querySelectorAll('li'); // get all list items that are siblings of the clicked link
for (var x = 0; x < items.length; x++) { // for each list item
if (items[x].style.height != '33px') { // if its not open
items[x].style.height = '33px'; // open it
} else { // otherwise
items[x].style.height = '0px'; // close it
}
}
};
}
Wrap this in a script tag then either drop it in at the bottom of the body, or wrap it in document.onload = function() { /* Script Here */ }
(Demo)
Note while any style with the :target selector will cease to have effect, you should leave them in the css as a fallback in case the user has javascript disabled.
This css is showing all of the accordions as closed using this style:
.accordion li > .sub-menu li {
height: 0px;
}
You could set it to 33px to show all open when the page opens - but that would break the functionality as it is the :target selector which then sets the height and thus causes the selected section to show as open.
The only solution is to move into javascript.....
Can it be done? Yes
Do you need to change your HTML? Yes
Is it pretty? No
Basically instead of Target maintaining state. Use a checkbox replacing you top level a tags with label.
body {margin:50px;}
/* Reset */
.accordion,
.accordion ul,
.accordion li,
.accordion label,
.accordion span {
margin: 0;
padding: 0;
border: none;
outline: none;
}
.accordion li {
list-style: none;
}
.accordion input[type="checkbox"]{display:none;}
/* Layout & Style */
.accordion li > label, .accordion li > a {
display: block;
position: relative;
min-width: 110px;
padding: 0 10px 0 40px;
height: 32px;
color: #fdfdfd;
font: bold 12px/32px Arial, sans-serif;
text-decoration: none;
text-shadow: 0px 1px 0px rgba(0,0,0, .35);
background: #6c6e74;
background: -moz-linear-gradient(top, #6c6e74 0%, #4b4d51 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6c6e74), color-stop(100%,#4b4d51));
background: -webkit-linear-gradient(top, #6c6e74 0%,#4b4d51 100%);
background: -o-linear-gradient(top, #6c6e74 0%,#4b4d51 100%);
background: -ms-linear-gradient(top, #6c6e74 0%,#4b4d51 100%);
background: linear-gradient(top, #6c6e74 0%,#4b4d51 100%);
-webkit-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
-moz-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
}
.accordion > li:hover > label,
.accordion > li:target > label,
.accordion > li > input[type="checkbox"]:checked ~ label{
color: #3e5706;
text-shadow: 1px 1px 1px rgba(255,255,255, .2);
/*background: url(../img/active.png) repeat-x;*/
background: #a5cd4e;
background: -moz-linear-gradient(top, #a5cd4e 0%, #6b8f1a 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a5cd4e), color-stop(100%,#6b8f1a));
background: -webkit-linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
background: -o-linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
background: -ms-linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
background: linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
}
.accordion li > label span, .accordion li > a span {
display: block;
position: absolute;
top: 7px;
right: 0;
padding: 0 10px;
margin-right: 10px;
font: normal bold 12px/18px Arial, sans-serif;
background: #404247;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
-webkit-box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);
-moz-box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);
box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);
}
.accordion > li:hover > label span,
.accordion > li:target > label span,
.accordion > li > input[type="checkbox"]:checked ~ label span{
color: #fdfdfd;
text-shadow: 0px 1px 0px rgba(0,0,0, .35);
background: #3e5706;
}
/* Images */
.accordion > li > label:before {
position: absolute;
top: 0;
left: 0;
content: '';
width: 24px;
height: 24px;
margin: 4px 8px;
background-repeat: no-repeat;
background-image: url(http://designmodo.com/demo/css3accordionmenu/img/icons.png);
background-position: 0px 0px;
}
.accordion li.files > label:before { background-position: 0px 0px; }
.accordion li.files:hover > labe:before,
.accordion li.files:target > label:before { background-position: 0px -24px; }
.accordion li.mail > label:before { background-position: -24px 0px; }
.accordion li.mail:hover > label:before,
.accordion li.mail:target > label:before { background-position: -24px -24px; }
.accordion li.cloud > label:before { background-position: -48px 0px; }
.accordion li.cloud:hover > label:before,
.accordion input[type="checkbox"]:checked:before { background-position: -48px -24px; }
.accordion li.sign > label:before { background-position: -72px 0px; }
.accordion li.sign:hover > label:before,
.accordion input[type="checkbox"]:checked:before { background-position: -72px -24px; }
/* Sub Menu */
.sub-menu li > a {
color: #797979;
text-shadow: 1px 1px 0px rgba(255,255,255, .2);
background: #e5e5e5;
border-bottom: 1px solid #c9c9c9;
-webkit-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
-moz-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
}
.sub-menu li:hover a { background: #efefef; }
.sub-menu li:last-child a { border: none; }
.sub-menu li > a span {
color: #797979;
text-shadow: 1px 1px 0px rgba(255,255,255, .2);
background: transparent;
border: 1px solid #c9c9c9;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.sub-menu em {
position: absolute;
top: 0;
left: 0;
margin-left: 14px;
color: #a6a6a6;
font: normal 10px/32px Arial, sans-serif;
}
/* Functionality */
.accordion li > .sub-menu li {
height: 0;
overflow: hidden;
-webkit-transition: height .2s ease-in-out;
-moz-transition: height .2s ease-in-out;
-o-transition: height .2s ease-in-out;
-ms-transition: height .2s ease-in-out;
transition: height .2s ease-in-out;
}
.accordion input[type="checkbox"]:checked ~ .sub-menu li {
height: 33px;
}
<ul class="accordion">
<li id="one" class="files">
<input type="checkBox" id="cbOne" checked="checked" /><label for="cbOne" >My Files<span>495</span></label>
<ul class="sub-menu">
<li><em>01</em>Dropbox<span>42</span></li>
<li><em>02</em>Skydrive<span>87</span></li>
<li><em>03</em>FTP Server<span>366</span></li>
<li><em>01</em>Dropbox<span>42</span></li>
<li><em>01</em>Dropbox<span>42</span></li>
</ul>
</li>
<li id="two" class="mail">
<input type="checkBox" id="cbTwo" checked="checked" /><label for="cbTwo" >Mail<span>26</span></label>
<ul class="sub-menu">
<li><em>01</em>Hotmail<span>9</span></li>
<li><em>02</em>Yahoo<span>14</span></li>
<li><em>03</em>Gmail<span>3</span></li>
</ul>
</li>
<li id="three" class="cloud">
<input type="checkBox" id="cbThree" checked="checked" /><label for="cbThree" >Cloud<span>58</span></label>
<ul class="sub-menu">
<li><em>01</em>Connect<span>12</span></li>
<li><em>02</em>Profiles<span>19</span></li>
<li><em>03</em>Options<span>27</span></li>
</ul>
</li>
<li id="four" class="sign">
<input type="checkBox" id="cbFour" checked="checked" /><label for="cbFour" >Sign Out</label>
<ul class="sub-menu">
<li><em>01</em>Log Out</li>
<li><em>02</em>Delete Account</li>
<li><em>03</em>Freeze Account</li>
</ul>
</li>
</ul>
Look Ma! No Javascript!