I'm trying to style my WordPress Menu. I want each menu item to have a different color and the background color of all the children on pages and posts must have the background color the same as the parent text color.
What I want is the following:
- <ul id="main-menu" class="menu">
<li id="1">This is Red
<ul>
<li id="4">Background Red</li>
</ul>
</li>
<li id="2">This is Blue
<ul>
<li id="5">Background Blue</li>
</ul>
</li>
<li id="3">This is Green
<ul>
<li id="6">Background Green</li>
</ul>
</li>
- </ul>
I managed to get this right on the home page only, thinking that it would be the same for each page. But on other pages it's not reflecting as it's intended to reflect.
CSS styling for lists that has the '>' in it I am still battling to understand - I just find it confusing.
If someone could point me to a good tuturial or show me how it's done, I'd be most greatful.
An ID's can't start with a number, change it if you're currently using it. If there's no way to change it you can use [id='1'] {/* some css */}
The HTML
<ul class="menu">
<li id="first">This is Red
<ul>
<li>Background Red</li>
</ul>
</li>
<li id="second">This is Blue
<ul>
<li>Background Blue</li>
</ul>
</li>
<li id="third">This is Green
<ul>
<li>Background Green</li>
</ul>
</li>
</ul>
The CSS
#first {
color: red;
}
#first ul > * {
background-color: red;
color: white;
}
#second {
color: blue;
}
#second ul > * {
background-color: blue;
color: white;
}
#third {
color: green;
}
#third ul > * {
background-color: green;
color: white;
}
Here it is at work http://jsfiddle.net/9mD8z/
Hope it solves your problem.
just Now i found the answer for this question:)
# Appearance > Menus look top and click: Screen Options!
Then check (CSS Classes) under: Show advanced menu properties
So will display new field called CSS Classes. with each item!
Now you can target the classes you have assigned from within your stylesheet.
Regards:)
Guest!
I've managed to work this out for my self the styling I need to apply actually goes like this:
.jqueryslidemenu #menu-item-12 a{color: #6cd7fb !important;}
.jqueryslidemenu #menu-item-12 > ul.sub-menu {border: 1px solid #6cd7fb; border-radius: 10px; background: none repeat scroll 0 0 #6cd7fb !important;-moz-box-shadow: 8px 8px 9px #888888; -webkit-box-shadow: 8px 8px 9px #888888; box-shadow: 8px 8px 9px #888888; }
.jqueryslidemenu #menu-item-12 > ul.sub-menu li a{color:#fff!important; background-color:#6cd7fb !important;}
.jqueryslidemenu #menu-item-12 ul.sub-menu > li a:hover{
background-color:#6cd7fb !important;
border-color: #56c8f5 #65E1F7 #AEEEF9; border-image: none;
border-style: solid;
border-width: 1px;
border-radius: 15px;
box-shadow: 0 -5px 9px #AEEEF9 inset;}
This is working for me - I know I have to work on the styling the color a bit more. If anyone has a better solution, I'm all ears :)
Obviously this is just for one of the menu items - the id of the other menu items change
Related
I use Jquery mobile with this listview. I can't get rid of the margin on the first item.
here's my html code:
<ul data-role="listview" data-inset="true">
<li data-icon="false">
<img src="images/meal.jpg" alt="meal" /><h2>Meals</h2><p>Enjoy the sweet Tinulang Barbeque ni Mang Juan for $99.</p>
</li>
<li data-icon="false">
<img src="images/desserts.jpg" alt="dessert"/><h2>Desserts</h2><p>Taste the Sea of Pier 3 with Condensed milk for $11.</p>
</li>
<li data-icon="false">
<img src="images/beverages.jpg" alt="beverage"/><h2>Beverages</h2><p>Drink the Water of Pandora with Amonium Nitrate for $25.</p>
</li>
</ul>
I tried this css code but still the same:
.listitem {
margin-top: 0px !important;
}
#list{
-webkit-box-shadow: none;
box-shadow: none;
border: none;
}
#list .ui-li {
border: none;
}
Any idea?
Check by applying inline style="margin:0 !important" if it still not solve your problem then check in inspect element if there is padding or margin
The margin above the first item is actually the top margin on the UL element. So assuming #list is your UL, just add margin-top: 0;:
#list{
-webkit-box-shadow: none;
box-shadow: none;
border: none;
margin-top: 0;
}
DEMO
I'm a relative newcomer to web design - after learning the basics a while ago (and promptly forgetting them), I started reading about it a few months ago. I've begun to make my own web pages in order to test and improve my skills, but I'm having issues with getting my navigation bar to display properly. The HTML code for my navigation bar is as follows:
<div class="nav">
<ul class="nav">
<li class="nav"><a class="nav" href="#">Home</a></li>
<li class="nav"><a class="nav" href="#">Coffee</a></li>
<li class="nav"><a class="nav" href="#">Food</a></li>
<li class="nav"><a class="nav" href="#">Catering</a></li>
<li class="nav"><a class="nav" href="#">About</a></li>
<li class="nav"><a class="nav" href="#">Contact</a></li>
</ul>
</div>
<!--Navigation bar.-->
The CSS code for the pertinent elements (div, ul, li & a) is all listed below:
div{
border: 2px;
border-radius: 3px;
margin: 0 auto 60 auto;
padding: 10px;
width: 980;
}
/*BASIC DIV ELEMENT.*/
/*LINKS.*/
a{
color: #545454;
font-family: lucida grande, lucida sans, sans-serif;
font-size: 14px;
text-decoration: none;
}
a:hover, a:active {
color: #191919;
}
/*LINKS.*/
/*NAV BAR*/
a.nav:link{
background-color: #D7C5CC;
color: #191919;
display: inline-block;
padding: 15px;
text-align:center;
width: 90px;
}
a.nav:hover{
color: #191919;
background-color: #EDD9DF;
}
li.nav{
float: left;
}
ul.nav{
display: center;
margin: 0 auto 0 auto;
}
/*NAV BAR*/
I'm an absolute beginner when it comes to writing HTML and CSS code, so apologies if that was poorly done. I'm having trouble with the navigation bar on two fronts:
I can't get the corners of the navigation bar to round properly. I've previously altered ul.nav and li.nav to have "border-radius: 10;" as an attribute - both to no avail.
I can't get the navigation bar to center properly on my page (I'm testing it in Chrome). Every other div centers perfectly; and I've tried editing the "display" and "float" attributes to no effect.
I've searched through many similar posts on Stackoverflow, but none of the answers seemed to get the desired result.
EDIT: My goal is to have a continuous (where all of the buttons are "connected") navigation bar where only the outermost corners are rounded. For example:
http://cssmenumaker.com/menu/indented-horizontal-menu
All you need is to add this CSS:
ul.nav li:first-child a {
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
}
ul.nav li:last-child a {
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
Here is a jsFiddle if that helps too.
Also, if you want an exact copy of the example you gave a link to, then here's that jsFiddle.
Please check this: jsFiddle.
To add a border-radius, I added the following CSS:
a.nav:link {
border-radius: 10px;
}
To center the navigation menu, I added the following CSS:
ul.nav{
text-align: center;
}
I also removed the float: left property assigned to li.nav and added this new CSS to it:
li.nav{
display: inline-block;
}
well in first time your class is invalide because you apply the same in differents levels, if you have a css properties for your class this properties maybe will have conflicts or not work.
in this case my recomendation is:
<nav>
<ul class="navbar">
<li class="nav-item selected">Home</li>
<li class="nav-item">Coffee</li>
<li class="nav-item">Food</li>
<li class="nav-item">Catering</li>
<li class="nav-item">About</li>
<li class="nav-item">Contact</li>
</ul>
</nav>
<style>
nav{
position:fixed;
}
.nav-item{
color: #000;
border: 1px solid blue;
background-color: rgba(255, 255, 255, .6 )
}
.nav-item:hover
{
background-color: rgba(0, 255, 255, .6 )
}
.selected{
color: #058;
border: 1px solid red;
background-color: rgba(255, 0, 255, .6 )
}
nav: is html5 item to make navigation bars
class {
navbar: there is the ensamble of items, use for set general options, distribution, for all items in navbar.
nav-item: is for create options for every sngle item, is posible create effects.
selected: other class for marked a selected item, is possible use many class in the same item, only need write a space, with javascript is possible set or delete a class, in this this case
<script>
$(".nav-item").click(function(){
$(".nav-item").removeClass("selected");
$(this).className = $(this).className + "selected";
});
</script>
this function change the class selected to the item clicked.
}
the style is only an uggly example
it its possible to select an parent Element by a specific class?
For an example i have an HTML-List:
<ul>
<li>Entry 1</li>
<li>Entry 2</li>
<li class="selected">Entry 3</li>
<li>Entry 4</li>
</ul>
All Elements has an bottom border:
ul li {
border-bottom: 1px solid #FF0000;
}
ul li.selected {
border-bottom: 1px solid #0000FF;
}
How i can tell over CSS that the color of the previous element is blue?
For little example (i know that :previous-child is not valid/exists but it's an little example):
ul li.selected:previous-child {
border-bottom: 1px solid #0000FF;
}
Here is an fiddle: http://jsfiddle.net/3W7PQ/
CSS 4 will allow this with the subject indicator, but there's no way in CSS as it exists today to select an element by reference to following elements.
The usual workaround is to have whatever generates your page specify the relationship itself. So, for example, you might have <li class="before-selected"> followed by <li class="selected">.
I am trying to put an image behind my header and menu. I set all of the layers above the background image div including all of the menu elements to position:relative;z-index:10; and the div with the background image to position:relative;z-index:0;
you can see my code here: http://wheresuccessblooms.com/wordpress/
I know it has something to do with the menu because when I delete the call to the menu the background image goes to where it should. Not sure what else I need to set the position and z-index to? PULLING MY HAIR OUT. lol Please help.
HTML:
<div class="menu-main-menu-container">
<ul id="menu-main-menu" class="menu">
<li id="menu-item-16" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-16">
HOME
</li>
<li id="menu-item-17" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-17">
ABOUT
</li>
<li id="menu-item-15" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-15">
Contact Us
</li>
</ul>
</div>
<div id="top_slider">
<div id="slider">
<div id="slider_wrap">
</div>
</div>
</div>
CSS: JUST THE MENU AND SLIDER CSS
nav{position:relative;z-index:5;}
div.menu-main-menu-container{position:relative;z-index:5;}
ul#menu-main-menu{position:relative;z-index:5;}
li.menu-item{position:relative;z-index:5;}
#page_nav {width:100%; height:53px;background-color:#f27479;position:relative;z-index:10;}
#page_nav ul { float: left; display: block;position:relative;z-index:5;}
#page_nav ul li { float: left; list-style-type: none; margin-top:20px;border-right:1px solid #ca6064;position:relative;z-index:5;}
#page_nav ul li a { color: #fff; text-decoration: none; font-size: 14px; text-transform: uppercase; font-weight: 700; text-shadow: 0px 1px 0px rgba(0,0,0,.5); padding-left: 20px;position:relative;z-index:5; }
#page_nav ul li a:hover { color: #a2a2a2; position:relative;z-index:5;}
#page_nav ul li.current a,
#page_nav ul li.current a:hover { color: #ba4040; position:relative;z-index:5;}
#top_slider{overflow:hidden;position:relative;z-index:0;left:0px;height:963px;top:-250px; margin:0px auto;
background:url('http://wheresuccessblooms.com/wordpress/wp-content/themes/WhereSuccessBlooms/images/slide_1.jpg') no-repeat top center;}
Your z-index looks like it's working fine to me. There does seem to be a positioning issue though. Set the top_slider div to position:absolute with width:100%. Or you can set position:fixed if you want it to stay put (also needs a width).
Put this line after your </nav> tag
<div style="clear:both"></div>
When trying to add an box with content inside it on a menu on a hover "drop down menu", it does something like this:
(source: gyazo.com)
I want the drop down to popup when I hover on the categories menu item.
This is the code I used for it:
<div class="secondheader">
<div class="container">
<div class="span12">
<ul class="nav6">
<li>Home</li>
<li class="dropdown1">Categories </li>
<li>Buy</li>
<li>Sell</li>
<li>Forums</li>
<li>Contact</li>
<li>item 1</li>
<li>Forums</li>
<li>Contact</li>
<li>item 1</li>
</ul>
</div>
</div>
</div>
</div>
The CSS:
.secondheader {
background-image: url("../img/second.png");
width: 100%;
height: 66px;
border-bottom: solid 6px #f0e8ce;
}
.nav6 {
list-style: none;
font-family: 'Dosis', sans-serif;
float: left
font-size: 20px;
margin-top: 13px;
margin-left: -35px;
}
.nav6 li {
display: inline;
margin: 0px;
font-size: 18px;
font-family: 'Dosis', sans-serif;
float: left;
margin-top: 10px;
}
.nav6 a {
color: #7d7253;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 20px;
padding-right: 20px;
}
.nav6 a:hover {
background-image: url("../img/hoverbg.png");
color: #53410f;
text-decoration: none;
}
I've tried using tutorials but I don't really understand on how to make the same thing for my layout I mean it has different ways and classes.
Do you want something like http://jsfiddle.net/b76Qc/?
Edit:
In your case the submenu is horizontal because you use descendant selectors instead of child selectors:
replace .nav6 li with .nav6>li and .nav6 li ul with .nav6>li>ul
See my jsfiddle if you want the complete code.
Edit 2:
If you want each element to have a different background,
<li class="dropdown1">Categories
<ul>
<li style="background:red">Buy</li>
<li style="background:blue">Sell</li>
<li style="background:green">Forums</li>
...
</ul>
</li>
But can you provide a link to your site instead of images? The square shown in http://gyazo.com/35835f003d0d8b776248196632cc1d4a.png is weird, but I can't know what's happening just with images...
Edit 3:
You have to change
.nav6 a {
color: #7D7253;
padding: 20px;
}
into
.nav6>li>a {
padding: 20px;
}
.nav6 a {
color: #7D7253;
}
And
.nav6 a:hover {
background-image: url("../img/hoverbg.png");
color: #53410F;
text-decoration: none;
}
into
.nav6 a:hover {
color: #53410F;
text-decoration: none;
}
.nav6 > li > a:hover {
background-image: url("../img/hoverbg.png");
}
Edit 4:
Sorry I didn't explain why I was telling you to use selectors with >, I thought you knew it.
Your html is like this:
<ul class="nav6">
<li>Home</li>
<li class="dropdown1">Categories
<ul>
<li>Buy</li>
<li>Sell</li>
<li>Forums</li>
<li>Contact</li>
<li>item 1</li>
<li>Forums</li>
<li>Contact</li>
<li>item 1</li>
</ul>
</li>
</ul>
If you use .nav6 a, the style will be applied to all <a> inside .nav6. That's a descendant selector.
Then, this will be applied both to menu's links and submenu's links:
<ul class="nav6">
<li>Home</li>
<li class="dropdown1">Categories
<ul>
<li>Buy</li>
<li>Sell</li>
...
</ul>
</li>
</ul>
But if you use a child selector like .nav6>li>a, the style is applied only to the links which are childs of a <li> which is a child of .nav6 (only menu's links). This way we can set which styles we want to apply to all links and which to menu's links:
<ul class="nav6">
<li>Home</li>
<li class="dropdown1">Categories
<ul>
<li>Buy</li>
<li>Sell</li>
...
</ul>
</li>
</ul>
Edit 5:
To fix the problem with backgrounds,
change
.nav6 a:hover {
color: #53410F;
text-decoration: none;
}
to
.nav6>li:hover>a, .nav6 .dropdown1 li:hover>a {
color: #53410F;
text-decoration: none;
}
and
.nav6 > li > a:hover
background-image: url("../img/hoverbg.png");
}
to
.nav6>li:hover>a {
background-image: url("../img/hoverbg.png");
}
To show you how little code is actualy required to make this work i set up a small example here: http://jsfiddle.net/fS5WV/
I put the explanations in the css.
The key lies in nesting the menu's properly, and giving the submenus a position absolute to prevent them from pushing the content down.
I hope it makes sense. Feel free to ask if you need further explanation.