CSS position issue - css

basically i have div with width of 960px and it has navigation on right hand, the navigation works fine, just the last sub navigation shows content extended to 960px, so i was wondering if somehow i can push it to left side, without pushing top navigation with it, i been trying but it dont work. following is the example and css code
navigation, the last black line is the
end of 960px;
screenshot for navigation question two
(question from comment)
css code example
#topNav {
float: right;
position: relative;
}
#topNav li {
position: relative;
float: left;
line-height:1.5em;
padding: 0 .5em;
}
#topNav a span {
clear: both;
}
#topNav ul ul {
display:none;
position: absolute;
top: 20px;
right: 0;
}
#topNav ul ul li {
float:none;
white-space:nowrap;
position: relative;
margin:0;
}
#topNav li.active {
height: 50px;
background-color:#FFF;
border-top:#666 1px solid;
border-right:#666 1px solid;
border-left:#666 1px solid;
border-bottom:#FFF 1px solid;
z-index: 2;
}
#topNav ul ul.active {
display: block;
background-color:#F8F8F8;
border:#666 1px solid;
margin-top: -1px;
margin-right: -1px;
z-index: 1;
}
html 5 code
<nav id="topNav">
<ul>
<li class="active">Home</li>
<li>Everyone</li>
<li>Profile</li>
<li><a href="#" title="Account" >Account</a>
<ul>
<li>Edit Friends</li>
<li>Account Settings</li>
<li>Privacy Settings</li>
<li>Help Center</li>
<li>Logout</li>
</ul>
</li>
<li>Layouts
<ul class="active">
<li>Default Layout</li>
<li>Default Elements</li>
<li>Default Form</li>
<li>Media Detail</li>
</ul>
</li>
</ul>
</nav>

Try adding the following:
#topNav ul ul {
right: 0;
}
Rather than left: 0;. This should make it line up with the right hand side of the top menu item (Layouts in this case), rather than the left hand side.

Related

Background color won't take up whole element

I have a drop down menu button that turns grey when hovered over. However, the grey does not expand throughout the whole button, but stops at the where I set the padding.
HTML:
#dropdown {
list-style: none;
display: none;
position: absolute;
background-color: #fff;
padding: 10px;
z-index: 99999;
width: 230%;
}
#dropdown li:hover,
#dropdown li:active {
background-color: #e3e3e3;
}
#dropdown.active, #menu:target #dropdown {
display: block;
}
<ul class="main-nav js--main-nav">
<li id="menu">
Help▾
<ul id="dropdown">
<li>Give</li>
<li>Get Help</li>
<li>Get Involved</li>
</ul>
</li>
</ul>
What I want is for the grey to take up all of the drop-down menu when hovered over, as opposed to just stopping at the padding.
EDIT: I should have clarified, when I meant I want it to take up "all" of the drop down menu, I meant just the "li" when I hover over that.
Is this what you were looking for?
#dropdown {
list-style: none;
display: none;
position: absolute;
background-color: #fff;
padding: 10px;
z-index: 99999;
width: 230%;
}
#dropdown:hover {
background-color: #eee;
}
#dropdown li:hover,
#dropdown li:active {
background-color: #e3e3e3;
}
#dropdown.active, #menu:target #dropdown {
display: block;
}
<ul class="main-nav js--main-nav">
<li id="menu">
Help▾
<ul id="dropdown">
<li>Give</li>
<li>Get Help</li>
<li>Get Involved</li>
</ul>
</li>
</ul>

CSS Drop Down menus won't align with parent Menus

Having trouble getting the drop-down menus to be directly aligned with the parent ones - at the moment they always fall from the center of the top one, see image.
My code:
body {
background: url('body-bkg.jpg');
background-repeat: no-repeat;
background-position: center top;
}
#navMenu {
margin: 0;
padding: 0;
text-align: center;
}
/*controls top parent box in navigation bar*/
#navMenu ul {
margin: 0;
padding: 0;
line-height: 30px;
display: inline-block;
}
/*controls top parent box in navigation bar*/
#navMenu li {
margin: 0;
padding: 0;
list-style: none;
position: relative;
background-color: hsla(0, 9%, 202%, 0.7);
float: left;
}
#navMenu ul li {
position: relative;
}
/*controls link text parent and children boxes in navigation bar*/
#navMenu ul li a {
text-decoration: none;
height: 30px;
width: 150px;
display: block;
color: #2e1c1c;
border: 1px solid #000;
}
/*controls children boxes in navigation bar*/
#navMenu ul ul {
position: absolute;
visibility: hidden;
top: 31px;
}
/*controls children boxes in navigation bar when hovered on parent box*/
#navMenu ul li:hover ul {
visibility: visible;
}
/*controls parent box when hovered on children box*/
#navMenu li:hover {
background: #387cf7;
}
/*controls child box when hovered on child box*/
#navMenu ul li:hover ul li a:hover {
background: white;
}
<div id="navMenu">
<ul>
<li>Destinations
<ul>
<li>Asia </li>
<li>Africa </li>
<li>Europe </li>
<li>North America </li>
<li>South America </li>
<li>Antartica </li>
</ul>
</li>
<li>Holiday Types
<ul>
<li>Short Breaks </li>
<li>Beaches </li>
<li>Adventure </li>
<li>Walking </li>
<li>Continents </li>
<li>Safari </li>
<li>Cruise </li>
<li>Family </li>
<li>Ultimate </li>
</ul>
</li>
<li>When to go
<ul>
<li>Winter </li>
<li>Spring </li>
<li>Summer </li>
<li>Autumn </li>
</ul>
</li>
<li>Corporate </li>
<li>Special Offers </li>
<li>About Us </li>
<li>Blog </li>
<li>Contact </li>
</ul>
</div>
This solution may work for you:
Demo Fiddle
I see you're using visibility:hidden a lot, but In situations like this I find display: none to be easier to work with.
CSS:
#navMenu ul ul {
// current styles
left: 0px;
}

Creating three layer submenu and center depending width parent

I want to make a menu like this :
and here what I have done so far :
<nav class="container site-navigation clearfix">
<ul id="menu-main-menu" class="main-menu">
<li id="menu-item-7" class="current-menu-item current_page_item">
Home
</li>
<li id="menu-item-50" class="menu-item menu-parent-item">
Teaching
<div class="sub-menu-outer">
<div class="sub-menu-inner">
<ul class="sub-menu">
<li id="menu-item-75" class="menu-item">
Description
</li>
<li id="menu-item-84" class="menu-item">
Papers
</li>
<li id="menu-item-82" class="menu-item">
Tasks
</li>
<li id="menu-item-83" class="menu-item">
<a href="http://localhost/artech/teaching/log-in/">Log In
</a>
</li>
</ul>
</div>
</div>
</li>
<li id="menu-item-21" class="menu-item">
Creative Technology
</li>
<li id="menu-item-20" class="menu-item">
Blog</li>
<li id="menu-item-19" class="menu-item">Bio
</li>
<li id="menu-item-18" class="menu-item">
Contact
</li>
</ul>
</nav>
and the css :
ul{list-style: none; padding: 0; margin: 0;}
nav{
background: url(http://img29.imageshack.us/img29/3563/6s9a.png) repeat-x bottom left;
height: 44px;
}
#menu-main-menu > li{position: relative; float:left;}
#menu-main-menu > li:not(:first-child){
margin-left: 70px;
}
#menu-main-menu li a{color: #000000; line-height: 35px;}
#menu-main-menu .current-menu-item a,#menu-main-menu .current_page_item a, #menu-main-menu > li:hover a{
font-weight: 700;
}
#menu-main-menu > li:hover ul.sub-menu li a{
font-weight: 400;
}
#menu-main-menu > li:hover ul.sub-menu li:hover a{
font-weight: 700;
}
.sub-menu-outer{background: url(http://img12.imageshack.us/img12/5050/3g1y.png) repeat-y top right #FFFFFF;
} /* two line stripe y*/
.sub-menu-inner{
background: url(http://img12.imageshack.us/img12/5050/3g1y.png) repeat-y top left;
} /* two line stripe y*/
.sub-menu{
background: url(http://img29.imageshack.us/img29/3563/6s9a.png) repeat-x bottom left;
} /* one line stripe x*/
.sub-menu > li{
padding: 5px 15px;
text-align: center;
}
#menu-main-menu > li.menu-parent-item .sub-menu-outer {
display: none;
float: left;
position: absolute;
left: 0;
top: 0;
margin-top: 35px;
}
#menu-main-menu > li.menu-parent-item:hover > .sub-menu-outer{
display: block;
z-index: 1000;
}
http://jsfiddle.net/JY8k5/4/
I have the follow problems that couldn't solve my self :
The right and left y-stripes has to start form the begging of parent li and ending at the end of the sub-menu without covering (I have a white background) the parent's li word / page link.
The x-stripe at the bottom of the sub-menu has to be over the left and right stripes as the foto shows
The sub-menu has to be centered base the widht of parent
Is it possible to solve all this only with css or I have to use jquery. I try a lot especially with the positions but couldn't achieve the desired results.
Any help is very appreciate.
I manage to solve it somehow. I change my html markup to :
<li id="menu-item-22" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-parent-item menu-item-22">
Teaching
<div class="sub-menu-wrapper" style="margin-left: -75px;"> // This style has been put by jquery
<ul class="sub-menu">
<li id="menu-item-75" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-75">
Description
</li>
// more li's here
</ul>
</div>
</li>
the css :
.sub-menu-wrapper{
background: url(../img/stripe.png) repeat-x bottom left #FFFFFF;
padding-bottom: 9px;
}
.sub-menu-wrapper ul.sub-menu{
background: url(../img/double-stripe.png) repeat-y top right;
}
.sub-menu-wrapper ul.sub-menu > li{
padding: 5px 15px;
text-align: center;
background: url(../img/double-stripe.png) repeat-y top left;
}
.sub-menu-wrapper ul.sub-menu li:first-child{
padding-top: 36px;
}
#menu-main-menu > li.menu-parent-item .sub-menu-wrapper {
display: none;
width: 115%;
min-width: 150px;
float: left;
position: absolute;
left: 50%;
top: -28px;
margin-top: 35px;
z-index: 40;
}
#menu-main-menu > li.menu-parent-item:hover > .sub-menu-wrapper{
display: block;
z-index: 10;
}
#menu-main-menu > li.menu-parent-item a{
position: relative;
z-index: 50;
}
and lastly the js :
$(".menu-parent-item").hover(function(){
var subMenu = $(this).children(".sub-menu-wrapper");
var parentWidth = $(this).width();
var subMenuWidth = parentWidth * 1.15; // because .sub-menu-wrapper width is 115%
var margin = 0;
if(subMenuWidth <= 150){
margin = -75;
}else{
margin = (( subMenuWidth / 2 )) *(-1);
}
subMenu.css("margin-left", margin);
});
I couldn't find a css way (except to add a div with min-width and fake a min-margin) to center the submenu so I did it with jquery.

CSS dropdown menu problems

I've tryed to implement a simple dropdownmenu without using links ( ).
It's list based. My list elements-width are with procentual values that all together comes to 100%. My last element breaks out in a new line thats what I dont understand. Maybe it has something to do with my margin..
Thanks in advance.
Here is a link to my code:
Fiddle
HTML
<div class="dropDown-menu-container">
<ul class="dropDownMenu">
<li style="width: 20%;">
Initiating
<ul>
<li>punkt</li>
<li>punkt</li>
</ul>
</li>
<li style="width: 20%;">
Planning
<ul></ul>
</li>
<li style="width: 40%;">
Monitoring and Controlling
<ul></ul>
</li>
<li style="width: 20%;">
Closing
<ul></ul>
</li>
</ul>
CSS
.dropDown-menu-container {
position:relative;
width:100%;
float:none;
clear:both;
display:inline;
text-align:center;
}
ul {
position:relative;
float:left;
width:100%;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
text-align:center;
height:50px;
margin:4px;
box-shadow:0px 0px 2px 2px grey;
background-color:grey;
position: relative;
float: left;
}
ul li:hover {
background-color:lightgrey;
}
li ul {
display: none;
}
li {
position: absolute;
height:50px;
margin-bottom:5px;
top:0px;
}
li:hover ul {
display: block;
top:32px;
}
li:hover li {
float: none;
font-size: 11px;
}
Kind regards!
You're not including your margins in your calculations
Set your width to calc(20% - 8px)
Fiddle: http://jsfiddle.net/bjPrK/16/
The total of your element area is the sum of margin, padding and border.
See http://www.w3.org/TR/CSS2/box.html
You must include the four pixels of each margin in your calculation.

Make <li> fit the width of the <ul> using CSS

I'm trying to make the <li> fit the width of the <ul> but even with width:auto it doesn't work at all, and I don't know why. I tried to use display:inline-block but this is the same. I don't know how many tabs I will have so this is why I am not using a percentage directly.
I would like to display the list inline when I display the page on a desktop and display one li per line when I am on a smartphone (with media queries).
I have this:
<ul id='menu'>
<li class="button"><a class='current' href='http://'>Home</a></li>
<li class="button"><a href='http://'>Products</a></li>
<li class="button"><a href='http://'>Support</a></li>
<li class="button"><a href='http://'>Contact</a></li>
<li class="button"><a href='http://'>Contact</a></li>
</ul>
and my CSS looks like this:
ul#menu
{
margin:0;
padding:0;
list-style-type:none;
width:100%;
position:relative;
display:block;
height:30px;
font-size:12px;
font-weight:bold;
font-family:Arial, Helvetica, sans-serif;
/*border-bottom:1px solid #000000;
border-top:1px solid #000000;*/
}
li.button {
background:transparent url(../images/nav_bg.png) repeat-x top left;
height:30px;
width:auto;
}
ul#menu li
{
display:inline-block;
margin:0;
padding:0;
width:auto;
}
ul#menu li a
{
display:inline-block;
color:#999999;
text-decoration:none;
font-weight:bold;
padding:8px 20px 0 20px;
width:auto;
}
ul#menu li a:hover
{
color:#FFFFFF;
height:22px;
background:transparent url(../images/nav_bg.png) 0px -30px no-repeat;
}
ul#menu li a.current
{
display:inline-block;
height:22px;
background:transparent url(images/nav_bg.png) 0px -30px no-repeat;
margin:0;
}
I've found this way to deal with single-line full-width ul where an undefined number of li elements need to be spaced out evenly:
ul {
width: 100%;
display: table;
table-layout: fixed; /* optional */
}
ul li {
display: table-cell;
width: auto;
text-align: center;
}
Basically, it emulates a table. Works in Gecko, Webkit, IE8+.
For IE7 and downwards you should use some inline-block hackery :)
JSFiddle
Since the li count can change, I can only think of accomplishing this with javascript/jquery as you suggested. Just divide 100 by the # of li's and set the width on each one.
var width = Math.floor(100 / $("ul#menu li").size());
$("ul#menu li").css('width', width + "%");
You will probably have to play with the width depending on padding and what not.
As a side note, If you haven't already, I recommend getting a tool like firebug, which will let you edit css and execute js on the fly. It is infinitely useful for fine tuning appearances.
If you want to fill the width of the <ul> with the five <li>s, you will have to give those <li>s a width of 20% each.
Note that you need to change some other details of the CSS if you want to make this work; e.g. with a display:inline-block you make the spaces between the <li> count, so the total width of the <ul> content will be more than 100% wide. I'd suggest removing the display:inline-block and giving them float:left.
Edit: Or do you want them to be distributed proportionally according to their contents? That would be a different challenge.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body{
margin:0 auto;
}
.main{
width:650px;
border:1px solid red;
padding:5px;
}
ul {
padding:0;
margin:0;
width: 100%;
border-bottom: 0;
}
li{
display: table-cell;
width: 1%;
float: none;
border:1px solid green;
margin:2px;
padding:10px;
text-align:center;
}
</style>
</head>
<body>
<div class="main">
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
<li>Link 5</li>
</ul>
</div>
</body>
</html>
#menu {
padding: 0;
margin: 0;
border: 1px solid red;
position: absolute;
}
#menu li {
list-style-type: none;
float: left;
position: relative;
padding-right: 10px;
}
#menu li a {
text-decoration: none;
}
<ul id="menu">
<li>1A1CASĂ </li>
<li>H1TML-CSS </li>
<li>J1VASCRIPT </li>
<li>PHP </li>
<li>TESTE </li>
<li>CONTACT </li>
</ul>
Wow stumbled upon a very old question here.
For anyone also seeing this and scrolling down here, in 2022 this is easily doable via flexbox.
#menu {
display: flex;
gap: 1rem;
}
li {
list-style-type: none;
}
<ul id='menu'>
<li class="button"><a class='current' href='http://'>Home</a></li>
<li class="button"><a href='http://'>Products</a></li>
<li class="button"><a href='http://'>Support</a></li>
<li class="button"><a href='http://'>Contact</a></li>
<li class="button"><a href='http://'>Contact</a></li>
</ul>
try below css:
style.css (line 87)
ul#menu li {
float: left;
margin: 0;
padding: 6px 0;
width: 11.1%;
}
style.css (line 113)
ul#menu li a.current {
background: url("images/nav_bg.png") no-repeat scroll 0 -30px transparent;
height: 22px;
margin: 0;
}
style.css (line 95)
ul#menu li a {
color: #999999;
font-weight: bold;
padding: 8px 20px 0;
text-decoration: none;
width: auto;
}
see screen shot:

Resources