Wordpress menu center aligned and spaced evenly - css

I need some help regarding my menu arrangement. I'm using Wordpress on my site, with Vantage theme of which I even bought the premium theme.
My problem is the following: I'd like to make my menu items centered, spaced evenly, and I can't seem to achieve that without messing up my sub-menus.
Here's what I tried so far, without success:
https://stackoverflow.com/a/14103766/3990536
http://icode4you.net/wordpress-tricks-create-an-automatically-centered-and-evenly-spaced-navigation-menu/
https://stackoverflow.com/a/16274725/3990536
The codes actually work; my menu gets aligned niceley, but it also affects my sub-menus, I assume because they use the same class. I can't seem to figure out how to define new class for them, or separate the sub-menu from the actual main menu.
The thing I don't understand here, is the connection between my sub-menus and the main menu. If I edit .main-navigation li, my sub-menu is affected as well, even tough there should be a separate li for my main and my sub menu.
My site is the following: http://classwebdesign.hu/testing/
My menu's css looks like this:
/* =Menu
----------------------------------------------- */
.main-navigation{
margin:0 -35px;
background:#343538;
font-size:1em;
position:relative;
text-transform:uppercase;
letter-spacing: 0.08em;
/* Font awesome icons */
/* General menu link styling */
/* For when the menu becomes a sticky menu */
}
.main-navigation [class^="icon-"]{
display:inline-block;
margin-right:15px;
font-size:16px;
line-height:0.5em;
color:#CCCCCC;
}
.main-navigation a:hover [class^="icon-"]{
color:#FFFFFF;
}
.main-navigation ul{
list-style:none;
margin:0;
padding-left:0;
zoom:1;
/* Second level menu items */
}
.main-navigation ul:before{
content:'';
display:block;
}
.main-navigation ul:after{
content:'';
display:table;
clear:both;
}
.main-navigation ul li{
display:block;
position:relative;
float:left;
}
.main-navigation ul li:hover > a{
background:#00bcff;
color:#FFFFFF;
}
.main-navigation ul li a{
padding:20px 35px;
-ms-box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}
.main-navigation ul li a,.main-navigation ul li a > *{
-webkit-transition:all 0.4s ease;
-moz-transition:all 0.4s ease;
-o-transition:all 0.4s ease;
transition:all 0.4s ease;
}
.main-navigation ul ul{
-webkit-box-shadow:0 1px 2px rgba(0,0,0,0.15);
-moz-box-shadow:0 1px 2px rgba(0,0,0,0.15);
box-shadow:0 1px 2px rgba(0,0,0,0.15);
background:#464646;
display:none;
position:absolute;
top:100%;
left:0;
z-index:99999;
/* Third Level Items */
}
.main-navigation ul ul a{
width:200px;
padding:15px 20px;
}
.main-navigation ul ul li{
position:relative;
/* Hovering over 2nd level items */
}
.main-navigation ul ul li:hover > a{
background:#00bcff;
color:#FFFFFF;
}
.main-navigation ul ul ul{
left:100%;
top:0;
margin-left:0;
}
.main-navigation ul li:hover > ul{
display:block;
}
.main-navigation a{
display:block;
text-decoration:none;
color:#e2e2e2;
font-weight:bold;
}
.main-navigation.sticky{
-webkit-box-shadow:0 2px 1px rgba(0,0,0,0.15);
-moz-box-shadow:0 2px 1px rgba(0,0,0,0.15);
box-shadow:0 2px 1px rgba(0,0,0,0.15);
}
body.has-menu-search .main-navigation ul{
margin-right:59px;
}
/* Handle the navigation slightly differently on mobile devices */
body.mobile-device .main-navigation ul ul{
display:none;
}
body.mobile-device .main-navigation li:hover > ul{
display:block;
}
.mobile-nav-frame [class^="icon-"]{
display:inline-block;
margin-right:10px;
min-width:1em;
}
.mobile-nav-icon{
font-family:'FontAwesome';
display:inline-block;
margin-right:10px;
}
.mobile-nav-icon:before{
font-size:14px;
content:"\f00b";
}
#search-icon{
position:absolute;
top:0;
right:0;
height:100%;
}
#search-icon #search-icon-icon{
-ms-box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
position:relative;
display:block;
cursor:pointer;
background-color:#303134;
width:59px;
height:100%;
}
#search-icon #search-icon-icon,#search-icon #search-icon-icon .icon-search{
-webkit-transition:all 0.4s ease;
-moz-transition:all 0.4s ease;
-o-transition:all 0.4s ease;
transition:all 0.4s ease;
}
#search-icon #search-icon-icon .icon{
position:absolute;
display:block;
width:17px;
height:17px;
top:50%;
left:50%;
margin-top:-8px;
margin-left:-8.5px;
background: url('images/sprites-1-2.png') no-repeat -102px 0;
}
#search-icon #search-icon-icon:hover{
background-color:#00bcff;
}
#search-icon #search-icon-icon:hover .icon{
background: url('images/sprites-1-2.png') no-repeat 0 0;
}
#media screen and (-webkit-min-device-pixel-ratio: 2) {
#search-icon #search-icon-icon .icon{
background: url(images/retina/search-icon.png) no-repeat;
background-size:17px 17px;
}
#search-icon #search-icon-icon:hover .icon{
background: url(images/retina/search-icon-white.png) no-repeat;
background-size:17px 17px;
}
}
#search-icon .searchform{
display:none;
position:absolute;
top:100%;
right:0;
width:1080px;
background:#2d2e31;
z-index:10;
overflow-x:hidden;
}
#search-icon .searchform input[name=s]{
color:#d1d1d1;
font-size:17px;
font-weight:200;
-ms-box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
display:block;
width:100%;
height:42px;
border:none;
-webkit-border-radius:0px;
-moz-border-radius:0px;
border-radius:0px;
background:transparent;
outline:none;
padding:0 15px;
}
Thanks for your help in advance!
EDIT: With the answer below I was able to align them centered, but they are not evenly spaced which would be very important for me as well. Thanks!

Have a look at answers like this on on the site;
Align center menu within div
It's a simple way of achieving what you want without messing your sub-menus. Remove the float from the li and set their display property to inline-block. Then set text-align: center on the parent ul;
.main-navigation ul {
list-style: none;
margin: 0;
padding-left: 0;
zoom: 1;
text-align: center;
}
.main-navigation ul li {
display: block;
position: relative;
/* float: left; */
display: inline-block;
}

Related

Have Buttons to the Left Move When One of the Buttons Are Hovered On, Too

When you hover on one of the menu buttons at http://hijinxnetwork.net/web.html, the buttons on the right, but not the buttons on the left. I would like the buttons on the left to move as well.
CSS:
#nav {
width:800px;
margin:0 auto;
}
#nav ul {
position:relative;
top:187px;
left:auto;
right:auto;
}
#nav li {
float:left;
display:inline;
display:block;
margin-left:3px;
margin-right:3px;
padding-left:20px;
padding-right:20px;
font-family: 'Roboto', sans-serif;
font-weight:100;
text-transform:uppercase;
font-size:24px;
background-color: #363636;
height:50px;
padding-top:20px;
transition: 1s;
position:relative;
left: 0;
}
#nav li:hover {
font-size:30px;
background-color:#a61919;
height:60px;
margin-right: -10px;
left: -10px;
margin-left:10px;
}
#nav li a {
color:#ffffff;
text-decoration:none;
}
Following your code, this should work:
#nav ul {
left: 0px;
right: 0px;
transition: 1s;
}
#nav ul:hover {
left: -5px;
right: -5px;
}
That would make buttons move equally to both sides. It adds the "expanding" animation to the ul element, 5 pixels on each side.

Fixed CSS positioning of nav menu on floating navbar

visualisation of problem: http://tinyurl.com/q83t89y
Is there a way to have the browse button to stay on the exact location that it is now?
For example if I resize my window or zoom in / out the browse button leaves its location.
Here is the css:
<style>
ul.Nav2 {
list-style-type:none;
margin:0 auto;
padding:0;
overflow:hidden;
width:auto;
}
ul.Nav2>li {
position:fixed;
top:0;
right: 25%;
padding:0px;
width:100px;
height:20px;
margin:10px;
z-index: 9999;
float: right;
}
ul.Nav2 li a {
font-family:"Arial";
font-size:15px;
color:#FFF;
display:block;
width:auto;
height:35px;
line-height:20px;
/*removed
text-align:center;
*/
text-decoration:none;
opacity:0.6;
padding:0px 10px;
;
;
;
-o-transition:all 0.2s ease-in-out;
transition:all 0.2s ease-in-out;
}
ul.Nav2 li a:hover {
opacity:1;
}
ul.Nav2 ul {
list-style:none;
position:absolute;
left:-9999px;
text-align:right;
float:right
/*added*/
display:block;
padding:0;
min-width:9.3ex;
}
ul.Nav2 ul li {
padding-top:1px;
float:none;
}
ul.Nav2 ul a {
white-space:nowrap;
}
ul.Nav2 li:hover ul {
left:inherit;
}
ul.Nav2 li:hover a {
text-decoration:none;
}
ul.Nav2 li:hover ul a {
text-decoration:none;
}
ul.Nav2 li:hover ul li a:hover {
}
</style>
The problem is that ul.Nav2>li has been positioned to the right side of the browser. I think you should leave it alone and...
Create a fixed container <div> like radio bar. (Green box in the example below)
Set an invisible <div> in the center of container. (Red box)
Position the Browse menu to the centered box. (Blue box) Use margin-left to avoid overlapping the radio-bar.
Example: http://jsfiddle.net/Stocki/ZGzb6/

vertical gap on menu without using jquery

I was wondering how, in this example, it is possible to have a gap between the menu item and the list.
This is the CSS code for the demo
#colorNav > ul{
width: 450px; /* Increase when adding more menu items */
margin:0 auto;
}
#colorNav > ul > li{ /* will style only the top level li */
list-style: none;
box-shadow: 0 0 10px rgba(100, 100, 100, 0.2) inset,1px 1px 1px #CCC;
display: inline-block;
line-height: 1;
margin: 1px;
border-radius: 3px;
position:relative;
}
#colorNav > ul > li > a{
color:inherit;
text-decoration:none !important;
font-size:24px;
padding: 25px;
}
#colorNav li ul{
position:absolute;
list-style:none;
text-align:center;
width:180px;
left:50%;
margin-left:-90px;
top:70px;
font:bold 12px 'Open Sans Condensed', sans-serif;
/* This is important for the show/hide CSS animation */
max-height:0px;
overflow:hidden;
-webkit-transition:max-height 0.4s linear;
-moz-transition:max-height 0.4s linear;
transition:max-height 0.4s linear;
}
#colorNav li ul li{
background-color:#313131;
}
#colorNav li ul li a{
padding:12px;
color:#fff !important;
text-decoration:none !important;
display:block;
}
#colorNav li ul li:nth-child(odd){ /* zebra stripes */
background-color:#363636;
}
#colorNav li ul li:hover{
background-color:#444;
}
#colorNav li ul li:first-child{
border-radius:3px 3px 0 0;
margin-top:25px;
position:relative;
}
#colorNav li ul li:first-child:before{ /* the pointer tip */
content:'';
position:absolute;
width:1px;
height:1px;
border:5px solid transparent;
border-bottom-color:#313131;
left:50%;
top:-10px;
margin-left:-5px;
}
#colorNav li ul li:last-child{
border-bottom-left-radius:3px;
border-bottom-right-radius:3px;
}
/* This will trigger the CSS */
/* transition animation on hover */
#colorNav li:hover ul{
max-height:200px; /* Increase when adding more dropdown items */
}
Here is the link:
http://demo.tutorialzine.com/2012/10/css3-dropdown-menu/
#colorNav li ul li:first-child {
margin-top: 25px;
}
Is what is creating the gap.

Css Transition For My Home Made Nav

I have created a nav menu myself for my website, I'm no expert but I think the menu turned out great ... I would like for my the menus to open a little slower then instant, maybe have a .5s transition ... I have tried to implement myself but I just don't seem to be able to figure it out .... I have created a jsfiddle to show my nav bar ... I was hoping to someone could show me how to had a transition to all the drop down menus if its possible ... Thank You
jsfiddle : http://jsfiddle.net/vRdEp/ (its a little broken on here)
my site : www.curious-howto.com
My css:
ul#navitemul {
border-radius: 0px 20px 20px 20px;
margin:0px!important;
width:500px;
}
.belownav {
top:0px;
left:183px;
position:absolute;
z-index:100;
box-shadow: 0 0 10px #000 inset;
border-radius: 5px 0px 0px 5px;
padding:20px!important;
background:#282828!important;
}
.navitem a {
margin-right: 10px;
border: 1px solid #424242!important;
text-overflow:ellipsis;
display:block;
overflow:hidden;
border-radius:5px;
width:200px!important;
padding:0px!important;
float:left;
height:40px;
background:#424242!important;
}
.navitem a:hover {
border:1px solid #585858!important;
background:#000!important;
}
img.fl {
float:left;
}
span.marleft {
letter-spacing:1px;
font-size:12px!important;
text-decoration:none;
color:white!important;
margin-left:15px!important;
line-height:38px;
}
li.marright{
float:left!important;
margin-bottom:10px!important;
margin-right:10px!important;
}
.ontop{
color:white;
font-size:28px!important;
margin-bottom:20px!important
}
ul#loginmenu {
border-radius:0px 0px 30px 30px;
z-index:1000;
left:200px;
width:500px!important;
overflow:auto;
max-height:600px;
left:-100px!important;
}
li.logo {
margin:0px!important;
line-height:10px!important;
border-radius: 30px 0px 0px 0px;
padding:10px 40px 10px 40px!important
}
span#navlogo {
font-size:20px;
}
#menu{
position:relative;
top:10px;
width:80%;
max-width:750px;
min-width:660px;
height:47px;
border-radius: 30px 30px 0px 0px;
background-color:#172322;
margin:0px;
padding:0px;
list-style:none;
color:#fff;
display:inline-block;
float:right;
z-index:1000;
}
#menu a {
color:#fff;
text-decoration:none;
}
#menu > li {
transition:width 2s, height 2s;
-webkit-transition:width 2s, height 2s, -webkit-transform 2s;
/* Safari */padding: 13px 0px;
background:#172322 none repeat scroll 0 0;
cursor:pointer;
float:left;
position:relative;
}
#menu > li a:hover {
color:#B0D730;
}
#menu .logo {
background-color: #7cb7e3;
width:87px;
padding:0px;
}
/* sub-menus*/
#menu ul {
padding:0px;
margin:0px;
display:block;
display:inline;
}
#menu li ul {
position:absolute;
left:-24px;
top:0px;
margin-top:45px;
line-height:16px;
background-color:#172322;
color:#0395CC;
/* for IE */ display:none;
}
#menu li:hover ul {
display:block;
}
#menu li ul li{
display:block;
margin:5px 20px;
padding: 5px 0px;
list-style-type:none;
}
#menu li ul li:first-child {
border-top: none;
}
#menu li ul li a {
display:block;
color:#0395CC;
}
#menu li ul li a:hover {
color:#7FCDFE;
}
/* main submenu */
#menu #main li {
text-align:center;
margin:10px 10px 10px 10px!important
}
#menu #main {
border-radius: 0px 0px 30px 30px;
width:167px;
left:0px;
top:-20px;
padding-top:20px;
background-color:#7cb7e3;
color:#fff;
z-index:999;
}
/* search */
.searchContainer div {
background-color:#fff;
display:inline;
padding:5px;
}
.searchContainer input[type="text"] {
border:none;
}
.searchContainer ul {
vertical-align:middle;
}
The problem is that transitions animate a property when that property changes. For example, if I had a div that was 100px wide, then added a class to it that switched it to be 300px wide, you could set transition: width 3s and it would grow over that 3 second period.
In your case, all that's changing is display:block / display:hidden
To get it to transition, you'll need to change things so that, rather than hiding it with display:hidden, you're hiding it by shrinking it to be really tiny and growing, or changing the opacity, etc.

How can I fix my drop down?

if you open the following link
http://dev.scopedesign.com/client/nyfarmersmarket_02/
you find an navigation bar if you go on "ABOUT US" you will see a drop down..
then you se the problem in drop down
now i want to give you a little idea from how i make this..
I am working on joomla CMS, & i do some changes in navigation module to get my style now the follwing CSS i used for this.. the problem is it is displaying the .parent.active a
background in drop downs i dont want that for this purpose i made .parent.active a ul
but it doesnt work..
you can check this how it works by inspect element in the browser.
.parent.active a{
background-image:url(../images/selected.png);
background-repeat:repeat-x;
padding-top:13px;
padding-bottom:13px;
}
.parent.active a ul{
background-image:none !important;
background-repeat:none;
padding-top:0px !important;
padding-bottom:0px !important;!
}
.menusan
{
/* Use these parameters to positions your menu. */
position: absolute;
// left: 10px;
}
.menusan, .menusan li, .menusan li ul { /* all lists */
padding: 0;
margin: 0;
// list-style: none;
display:block;
float:left;
}
.menusan li a{
padding-left:20px;
padding-right:18px;
}
.menusan li a:hover{
background-image:url(../images/selected.png);
background-repeat:repeat-x;
padding-top:13px;
padding-bottom:13px;
}
.menusan li{ /* all list items */
padding-top:11px;
padding-bottom:11px;
// padding-left:20px;
// padding-right:18px;
-moz-border-right:#537d28 groove 2px;
border-right:#7cb43f groove 2px;
[border-right:#537d28 groove 2px;
border-right:#7cb43f groove 2px;/
border-right:#7cb43f groove 2px;]
}
.menusan li ul { /* second-level lists */
//top:35px;
margin-top:13px;
float:left;
position: absolute;
border: none;
left: -98%; /* Use left instead of display to hide menus; display: none isn’t read by screen readers. */
}
.menusan li ul li{
display:list-item;
float:none;
border: none;
background-color:#537d28;
color:#fff;
//padding:10px 10px 24px 10px;
}
.menusan li ul li:hover{
display:list-item;
float:none;
background-color:#96c73d;
}
.menusan li ul li a{
display:block;
float:left;
}
.menusan li ul li a:hover{
display:block;
float:left;
background-color:#96c73d;
}
.menusan li:hover ul, .menusan li.sfhover ul { /* lists nested under hovered list items */
left: auto; /* change is to 10px, 20px, etc for indenting the sub menu */
border: none;
display:block;
float:left;
}
/* **************** Dropdown Menu styling end here ***************/
One thing i specialy want to let you know guys that it is difficult to make div in it or cheange style name because it is a dynamic module.
Cleaned up and fixed your CSS, try this:
.navigation {
background-color:#537D28;
color:#fff;
float:left;
font-family:Arial, Helvetica, sans-serif;
font-size:11px;
height:40px;
margin-bottom:0.6em;
width:100%;
}
.menusan {
margin: 0;
list-style-type: none;
font-weight:700;
float: left;
color:#fff;
}
.menusan > li {
margin:0;
float: left;
border-right:1px groove #7cb43f;
position:relative;
}
.menusan li a {
display:block;
height:40px;
line-height:40px;
padding:0 25px;
text-decoration:none;
color:#fff;
}
.menusan .active {
background: url("http://dev.scopedesign.com/client/nyfarmersmarket_02/templates/nyfm/images/selected.png") repeat-x center center;
}
.menusan li a:hover {
background: url("http://dev.scopedesign.com/client/nyfarmersmarket_02/templates/nyfm/images/selected.png") repeat-x center center;
}
.menusan li.parent ul {
position:absolute;
z-index:9999;
top:40px;
left:0;
display:none;
background-color:#537D28;
}
.menusan li.parent:hover ul {
display:block;
}
.menusan li.parent ul a {
float:left;
}
.menusan li.parent ul a:hover {
background-color:#70A835;
}
.menusan li.parent ul a {
width:55px;
}

Resources