Can't apply distinct styles to nav and ul - css

I'm trying to create two navigation menus in an HTML document. I am using nav and ul tags. But my CSS is not allowing me to create different appearance for both. One nav will be on the top of the page, the second is on the side. The appearance is taking on the menu within the side.
Here is the relevant section of the HTML:
<div id="navbar">
<nav id="navbar_text">
<ul>
<li>Home</li>
<li>About</li>
<li>Products</li>
<li>Services</li>
</ul>
</nav>
</div> <!--END navbar-->
<div id="main-wrap" class="group">
<aside>
<nav id="sidebar">
<ul>
<li>Contact Us</li>
<li>Awards & Articles</li>
<li>Testimonials</li>
<li>Photo Gallery</li>
</ul>
</nav>
Here is my CSS:
#sidebar a:link{
color: #663333;
}
#sidebar a:hover{
color: #dccfbd;
}
#navbar_text a:link{
color: #bca380;
}
#navbar_text a:hover{
color: #dccfbd;
}
#navbar_text{
width: 100%;
float: left;
}
#navbar_text li {
float: left;
list-style: none;
padding: 0;
background: #663333;
margin: 0;
color:#bca380;
}
nav ul li a {
display: block;
padding: 10px 10px 10px 15px;
background: #cab69a;
-webkit-border-radius: 8px 0px 0px 8px;
border-radius: 8px 0px 0px 8px;
margin-top: 10px;
font-family:Georgia, "Times New Roman", Times, serif;
font-size: 120%;
font-weight: bold;
color: #663333;
text-decoration: none;
-webkit-box-shadow: 2px 2px 1px 2px rgba(181, 154, 115, .25);
box-shadow: 2px 2px 1px 2px rgba(181, 154, 115, .25);
}
nav ul {
list-style:none;
}

If you want the #navbar_text and the #sidebar navigation menus to be styled differently, you must specify in the CSS specifically how you want each to look.
Therefore, you could use something like...
#navbar_text ul {}
#navbar_text ul li {}
#navbar_text ul li a {}
#navbar_text ul li a:hover {}
#sidebar ul {}
#sidebar ul li {}
#sidebar ul li a {}
#sidebar ul li a:hover {}
Basically, don't be too general by saying...
nav ul li a {}
because that will style both of the menus since they both use those same attributes.
If you are looking for help on the positioning of these two menus as opposed to the appearance, you will have to provide some more information about where they are located currently and where you'd like them to be. But the examples I stated above might help you with position, you just have to be specific in saying that you want the #sidebar menu to be positioned a certain way and the #navbar_text to be positioned a different way.
For example...
#navbar_text ul {
*add position styles here*
}
#sidebar ul {
*add position styles here*
}

try this Demo:
http://jsfiddle.net/pSkua/6/
CSS
body {
margin: 0;
padding: 0;
}
aside {
position: absolute;
right: 0;
}
#slidebar ul {
margin: 0;
padding: 0;
}
#slidebar li {
display: block;
}
#slidebar a {
display: inline-block;
}
#sidebar a:link {
color: #663333;
}
#sidebar a:hover {
color: #dccfbd;
}
#navbar_text a:link {
color: #bca380;
}
#navbar_text a:hover {
color: #dccfbd;
}
#navbar_text {
width: 100%;
margin: 0;
padding: 0;
}
#navbar_text li {
float: left;
list-style: none;
padding: 0;
background: #663333;
margin: 0;
color: #bca380;
}
nav ul li a {
display: block;
padding: 10px 10px 10px 15px;
background: #cab69a;
-webkit-border-radius: 8px 0px 0px 8px;
border-radius: 8px 0px 0px 8px;
margin-top: 10px;
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 120%;
font-weight: bold;
color: #663333;
text-decoration: none;
-webkit-box-shadow: 2px 2px 1px 2px rgba(181, 154, 115, .25);
box-shadow: 2px 2px 1px 2px rgba(181, 154, 115, .25);
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
.clr_both{
clear:both;
}

Related

Dropdown menu for nav with this css

So how do I make a dropdown menu using this css? Tried some tuts, but with this css I can't get any of those dropdowns working ;(.
CSS:
.main {
list-style: none;
margin: 0;
margin-bottom: 100px;
padding: 0px;
height: 44px;
text-decoration: none;
background-color: #171a21;
width: 100%;
text-align: left;
font-size: 18px;
-webkit-box-shadow: 0px 0px 8px rgba(0, 6, 0, 0.45);
-moz-box-shadow: 0px 0px 8px rgba(0, 6, 0, 0.45);
box-shadow: 0px 0px 8px rgba(0, 6, 0, 0.45);
}
.main li {
float: left;
padding: 16px;
margin: 0;
line-height: 17px;
height: 16px;
margin-bottom: -6px;
margin-left: 45px;
list-style:none;
}
.main p {
float: left;
margin: 0;
padding: 0;
line-height: 17px;
height: 44px;
margin-bottom: -6px;
}
.main a {
display: block;
color: #b8b6b4;
text-decoration: none;
transition: all linear 0.15s;
}
.main a:hover {
display: block;
color: white;
text-decoration: none;
}
HTML:
<ul class="main">
<li>Test
<ul>
<li>Test1</li>
<li>Test2</li>
<li>Test3</li>
</ul>
</li>
</ul>
I'm just starting with html&css and making a site.
Thanks for any help ;).
Check this Fiddle:
The key is in those lines of CSS code:
.main li ul {
display: none;
}
.main li:hover > ul {
display: block;
}
Should be quite self explicative.
add these lines to your css file:
.main li ul {display: none;}
.main li:hover ul {display: block;}

jmenu - transparency for child menu elements

I am using jmenu.js and setting child menu elements to have transparency. Problem is that the child elements with transparency show the parent's (i.e. main menu bar) background. What I want is have transparency on the child menus which show through to the page background. The CSS is:
.jMenu {
display: table;
margin: 0 0 0 50px;
padding: 0;
}
/* First level */
.jMenu li {
display: table-cell;
background: url('../images/tile_gray.png');
margin: 0;
}
.jMenu li a {
padding: 10px;
padding-right:55px;
display: block;
background-color: transparent;
color: white;
text-transform: uppercase;
margin-top:2px;
cursor: pointer;
font-size: 14px;
font-family: Myriad Pro, Lucida Sans, Segoe UI, Calibri, sans serif;
font-weight: bold;
text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
}
/* Lower levels */
.jMenu li ul {
display: none;
position: absolute;
z-index:9999;
padding: 0;
margin: 0;
}
.jMenu li ul li {
background-color: #fff;
display: block;
padding: 0;
}
.jMenu li ul li.arrow {
background: url('../images/tile_pink.png');
padding: 0;
border-bottom: none;
padding-bottom: 5px;
margin-top: 10px;
}
.jMenu li ul li a {
font-size: 13px;
text-shadow: 0px 0px 0px rgba(0,0,0,0);
text-transform: none;
padding: 7px;
display: block;
border-top: 1px solid transparent;
text-decoration: none;
}
.tran {
background: rgba(120, 120, 120, .2);
}
.jMenu li ul li a.isParent {
background: url('../images/tile_darker.png');
}
.jMenu li ul li a:hover {
background: url('../images/tile_green.png');
}
UPDATED
I changed the css to have the background transparent not on the anchor but on the li:
.jMenu li ul li {
background-color: #fff;
display: block;
background: rgba(0, 0, 0, .4);
padding: 0;
}
It looks like you have a background image on all .jMenu li. Even though you think you are just applying this background ('.../images/tile_gray.png') to only the first level, it is leaking down into the inner <li>'s
Try adding background-image: none; to your child li:
.jMenu li ul li {
background-color: #fff;
background-image: none;
display: block;
padding: 0;
}
This might work but it is hard to tell what exactly is going on without seeing it in action and without your HTML.

Making a menu button larger when active in Drupal 7

Similar to http://www.austintexas.gov/government I want to make a menu button bigger when it is active.
Here is my css for my main menu
#mobileMenu_mm1 {
margin: 10px 20px;
padding: 3px 0px;}
#navigation {
margin: 0px auto;
float: left;}
#main-menu{
clear: both;
float: left;
color: #fff;
font-size: 18px;
margin: 0px auto;
overflow: hidden;
width: 100%;}
#main-menu ul {
float: left;
margin-top: 10px;
margin-left: 20px;
padding: 0px 15px;}
#main-menu li {
float: left;
list-style-type: none;
font-weight: 400;
color: #333 !important;
background: rgb(0, 25, 60);
background: rgba(0, 25, 60, 0.9);}
#main-menu li a {
color: #777;
display: block;
padding: 7px 7px 7px 7px;
text-decoration: none;
line-height: 12px;}
/*----------------------MENU SPECIFIC COLORS--------------*/
#main-menu li#dhtml_menu-305{
border-radius: 15px 15px 0px 0px;
border-right: 2px solid #e6e7de;
background: #D1B37F;
}
#main-menu li#dhtml_menu-50692{
border-radius: 15px 15px 0px 0px;
border-right: 2px solid #e6e7de;
background: #ffff90;
}
#main-menu li#dhtml_menu-50690{
border-radius: 15px 15px 0px 0px;
border-right: 2px solid #e6e7de;
background: lightblue;
}
#main-menu li#dhtml_menu-50207{
border-radius: 15px 15px 0px 0px;
border-right: 2px solid #e6e7de;
background: #CAC37F;
}
#main-menu li#dhtml_menu-50207 li{
background: #CAC37F;
}
#main-menu li#dhtml_menu-50691{
border-radius: 15px 15px 0px 0px;
background: #E4B04A;
}
#main-menu li a:hover {
border-radius: 15px 15px 0px 0px;
background: rgb(200, 200, 200);
background: rgba(200, 200, 200, 0.7);
height: 35px;}
#main-menu li a .sf-sub-indicator {
display: block;
overflow: hidden;
position: absolute;
z-index: 15;
text-indent: -9999px;}
#main-menu li ul li a,
#main-menu li ul li a:link,
#main-menu li ul li a:visited {
border-top-width: 0;
color: #fff;
font-size: 14px;
padding: 10px 10px;
text-transform: none;
line-height: 13px;
width: 105px;}
#main-menu li ul {
height: auto;
padding: 0px 0px;
left: -9999px;
margin: 0 0 0 -2px;
position: absolute;
z-index: 15;
width: 0px;}
#main-menu li ul a {width: 110px;}
#main-menu li ul ul {margin: -33px 0 0 124px;}
#main-menu li:hover>ul,
#main-menu li.sfHover ul {left: auto;}
#main-menu ul li.leaf, #main-menu ul li.expanded, #main-menu ul li.collapsed {list-style:none;}
#main-menu ul.menu li {margin: 0;}
#main-menu li.expanded, #main-menu li.collapsed, #main-menu li.leaf {margin: 0;padding: 0;}
HTML/PHP
<nav id="navigation" role="navigation">
<div id="main-menu">
<?php
$main_menu_tree = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
print drupal_render($main_menu_tree);
?>
</div>
</nav><!-- end main-menu -->
<?php if ($page['header']): ?>
<div id="header" class="sixteen columns" style="margin: 0; padding: 0;>
<?php print render($page['header']); ?>
</div>
<?php endif; ?>
</div>
</div>
</header>
Here is a screenshot
Things I've Tried
I have already tried using :active and :current. For some reason only the first button on my menu has an active class given to it. Cheers!
Nothing is better than a live example:
http://jsfiddle.net/g105b/76JDZ/
The example uses JavaScript to add the active class to the currently selected li element, but the effect you are looking for is purely CSS.
A feature of Drupal is to automatically add the class name active to the currently selected li, so you can completely ignore the JavaScript in the linked example, and simply take the concept shown in CSS.
Use .active class name. All active menu links in Drupal has a class name active.
#main-menu li.active
If you are willing to select only the menu links that have children, use .expanded class name.
#main-menu li.expanded
Hope this works... Muhammad.

CSS issue: multiple CSS with the same element

<div id="nav">
<ul id="rightMin">
<li id="selectedmenu" onclick="location.href='index.php'">main</li>
<li onclick="location.href='aboutus.php'">about</li>
<li>contact us</li>
</ul>
</div>
CSS:
#selectedmenu {
display:inline;
float:right;
/*padding: 2px 7px 0px 7px;*/
height: 35px;
background: url('../images/selected.png') repeat-x;
cursor: pointer;
text-align: center;
line-height:35px;
padding: 0 5px 0 5px;
color: white;
}
div#nav ul li {
display:inline;
float:right;
/*padding: 2px 7px 0px 7px;*/
height: 35px;
cursor: pointer;
text-align: center;
line-height:35px;
padding: 0 5px 0 5px;
}
div#nav ul li:hover {
background: #232323;
color:#fff;
}
The element with the ID selectedmenu takes CSS #selectedmenu but when hovering it takes div#nav ul li:hover. how can i make it sticks with #selectedmenu
div#nav ul li#selectedmenu:hover {
add your css rules here...
}
Give selectedmenu a higher precedence:
div#nav ul li#selectedmenu {
...
}
just change it every time you hover it, try this:
div#nav ul li #selectedmenu:hover{ /* the style for #selectedmenu*/ }
hope this helps..

Help with adding image to drop-down menu

I have a CSS based drop-down menu, which I am implementing into wordpress, however I need help in adding a image on the right side of my links when a user hoovers over a link from the menu. Below is my code and here is a similar effect I've seen done and would like to get the same effect on my menu as well.
Something like this: http://www.clydequaywharf.co.nz/
html
<div class="header">
<div class="nav-holder">
<ul id="nav">
<li><?php wp_list_pages('title_li=&depth=0&sort_column=menu_order'); ?></li>
</ul>
</div>
</div>
css
.nav-holder {
height: 32px;
width: 1010px;
float: right;
position: relative;
}
#nav {
font-family: Arial;
font-size: 12px;
float: right;
margin: 0px 30px 0 0px; padding: 0 0px 0 0px;
color: #FFF;
}
#nav li a, #nav li {
float: left;
text-transform: capitalize;
z-index: 9997;
}
#nav li {
list-style: none;
position: relative;
list-style-position: outside;
}
#nav li a:hover { background:white; color: #666; font-weight: normal; }
#nav li:hover > a { background:white; color: #666; font-weight: normal;}
#nav li a {
margin: 0px 0px 0px 15.2px;
padding: 10px 8px 8px 8px;
text-decoration: none;
color: #FFF;
text-transform: uppercase;
font-weight:normal;
letter-spacing: 0.8px;
z-index: 1006;
/* background: -moz-linear-gradient(top, black, #3c3c3c 1px, #292929 25px); */
/* background: -webkit-gradient(linear, left top, left 25, from(black), color-stop(4%, #3c3c3c), to(#292929)); */
}
#nav li li a:link {
background-color: white;
color: #333;
font-size: 12px;
z-index: 9995;
height:22px;
/* background: -moz-linear-gradient(top, #11032e, #2a0d65); */
/* background: -webkit-gradient(linear, left top, left bottom, from(#11032e), to(#2a0d65)); */
}
#nav li li a:hover {
background: white;
color: #8B7500;
z-index: 9996;
/* background: -moz-linear-gradient(top, #11032e, #2a0d65); */
/* background: -webkit-gradient(linear, left top, left bottom, from(#11032e), to(#2a0d65)); */
}
/* Submenu */
#nav li ul {
display: none;
position: absolute;
left: 0;
top: 100%;
padding: 0px 1px 8px 1px; margin: 0px 0px 0px 0px;
}
#nav li:hover ul {
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 15px;
width: 184px;
display: block;
z-index: 5000;
}
#nav li ul li a {
float: none;
letter-spacing: 0.0em;
background: white;
margin: 0px 0px 0px 0px;
padding: 10px 0px 0px 12px; /* Move text inside menu */
z-index: 1000;
font-size: 12px;
color: #666;
word-spacing: wrap;
text-transform: lowercase;
*margin-left: -9px;
}
#nav li ul li {
_display: inline; /* for ie6 */
background: url(../images/wordpress.png) no-repeat;
}
#nav li ul li a {
width: 158px;
display: block;
}
/* *** */
/* Sub Sub Menu */
#nav li ul li ul {
display: none;
}
#nav li ul li:hover ul {
left: 100%;
top: 0;
z-index: 1000;
}
EDIT:
I see what you're trying to do now. Wrap the contents of the in some sort of container, then you can float elements inside of it. I super-dummed-down your fiddle, but the concept still stands. You should be able to implement it in your markup.
HTML:
<ul id="nav">
<li>
<a>Past Projects</a>
<div class="menu-item-container">
<img src="http://lorempixum.com/100/100/" class="menu-image">
<ul class='children'>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
</ul></div>
</li>
</ul>
CSS:
#nav li {
list-style: none;
position: relative;
}
#nav li div.menu-item-container {
position: absolute;
left: 0;
top:100%;
display:none;
}
#nav li:hover div.menu-item-container {
display:block;
}
#nav li img.menu-image {
float:right;
}
#nav li ul.children {
float:left;
}
Here's a fiddle: http://jsfiddle.net/thomas4g/VL3Sz/15/
Hope this helps!
I can't seem to reproduce your menu so I can't give an exact answer
For anyone stopping by, here was my original answer:
you can use the CSS pseudo class :hover (which i'm sure you're aware of) combined with a background-image, like so:
HTML:
<span class="menu-item">My Epic Menu Item</span>
CSS:
.menu-item {
padding:5px;
padding-right:25px;
}
.menu-item:hover {
background-image:url("http://lorempixum.com/20/20/");
background-position:right;
background-repeat:no-repeat;
}
Here's a fiddle if you want to play around with it: http://jsfiddle.net/thomas4g/NQQjX/4/
Please let me know if this isn't want you want, hopefully i can improve the answer.

Resources