Absolute and relative positioning in menu - html

We all have hard times with positioning absolute divs :S
In my case its horizontal sub-menus with this css:
ul.children{
display:none;
position:absolute;
}
ul.children li{
position:relative;
height:60px;
float:none;
}
li.page_item_has_children:hover > ul.children{
display:inline;
}
As you can see on the picture whole submenu moves to the left for 50% of the parents width...
I tried everything and created just a bigger mess xD
So if anyone can help me out with this I will be very thankful :)
HTML:
<li class="page_item page-item-2 page_item_has_children">
About
<ul class='children'>
<li class="page_item page-item-39">
About</li>
<li class="page_item page-item-41">
Contact us</li>
</ul>
</li>
I can't change html cause its wordpress theme :S

Try something like this:
ul {
list-style-type: none;
padding: 0;
}
.page_item_has_children {
position: relative;
}
ul.children {
display: none;
position: absolute;
top: 100%;
left: 0;
padding: 0;
min-width: 200px; /* or whatever makes sense */
}
ul.children li {
height: 60px;
}
.page_item_has_children:hover > ul.children {
display: block;
}
The important piece here is to make sure the 'page_item_has_children' element is relatively positioned and that the child 'ul' is absolutely positioned.
JS Fiddle

Update
ul.children {
display: none;
}
ul.children li {
position: relative;
height: 60px;
float: none;
}
li.page_item_has_children:hover > ul.children {
display: inline;
}
li {
float: left;
list-style-type: none;
width: 5em;
}
<ul>
<li class="page_item page-item-2 page_item_has_children">
About
<ul class='children'>
<li class="page_item page-item-39">
About</li>
<li class="page_item page-item-41">
Contact us</li>
</ul>
</li>
<li class="page_item page-item-2 page_item_has_children">
More info
<ul class='children'>
<li class="page_item page-item-39">
Item 1</li>
<li class="page_item page-item-41">
Item 2</li>
<li class="page_item page-item-41">
Item 3</li>
</ul>
</li>
</ul>

Related

how to stretch a UL across the browser window

I have an UL that acts as my navigation bar on my web page. currently it is all the way to the left of the screen. I would like it to be centered and have the background color stretch all the way to the left and right, Like below. what would I need to change to stretch the UL across the page like the top example image?
Here is what it looks like currently:
Here is my code:
.parent {
display: block;
position: relative;
float: left;
line-height: 30px;
background-color: #1D3567;
}
.parent a {
margin: 10px;
color: #FFFFFF;
text-decoration: none;
}
.parent:hover>ul {
display: block;
position: absolute;
}
.child {
display: none;
}
.child li {
background-color: #1D3567;
line-height: 30px;
border-bottom: #CCC 1px solid;
border-right: #CCC 1px solid;
width: 100%;
}
.child li a {
color: #FFFFFF;
}
ul {
list-style-type: none;
margin: 0;
padding: 0px;
min-width: 15em;
}
ul ul ul {
left: 100%;
top: 0;
margin-left: 1px;
}
li:hover {
background-color: #95B4CA;
}
.parent li:hover {
background-color: #95B4CA;
}
<ul id="nav_ul">
<li class="parent">Home</li>
<li class="parent">Outlook Web</li>
<li class="parent">Production
<ul class="child">
<li class="parent">Hennig South</li>
<li class="parent">Hennig Enclosure Systems</li>
<li class="parent">Hennig South</li>
<li class="parent">Factory Andon</li>
<li class="parent">Web Docs</li>
</ul>
</li>
<li class="parent">IT
<ul class="child">
<li>Knowledge Base</li>
<li>Submit a Ticket</li>
<li class="parent">Archived Links</li>
</ul>
</li>
<li class="parent">Office Directories
<ul class="child">
<li>Hennig</li>
<li>AME</li>
</ul>
</li>
<li class="parent">Hennig Parts</li>
<li class="parent">Factory Andon</li>
<li class="parent">Business Cards</li>
<li class="parent">Reports
<ul class="child">
<li class="parent">Global Shop<span class="expand">»</span>
<ul class="child">
<li>Inventory Report</li>
<li>Sales Report</li>
<li>Quotes Report</li>
<li>Work Order Report</li>
<li>Part Where Used Report</li>
</ul>
</li>
<li class="parent">Ndustrios<span class="expand">»</span>
</li>
</ul>
</li>
</ul>
Make your ul a flex container in which you align the children centered, and apply the background-color to this element instead of the li children by adding this rule:
#nav_ul {
width: 100%;
display: flex;
justify-content: center;
background-color: #1D3567;
}
.parent {
position: relative;
float: left;
line-height: 30px;
background-color: #1D3567;
}
.parent a {
margin: 10px;
color: #FFFFFF;
text-decoration: none;
}
.parent:hover>ul {
display: block;
position: absolute;
}
.child {
display: none;
}
.child li {
line-height: 30px;
border-bottom: #CCC 1px solid;
border-right: #CCC 1px solid;
width: 100%;
}
.child li a {
color: #FFFFFF;
}
ul {
list-style-type: none;
margin: 0;
padding: 0px;
min-width: 15em;
}
#nav_ul {
width: 100%;
display: flex;
justify-content: center;
background-color: #1D3567;
}
ul ul ul {
left: 100%;
top: 0;
margin-left: 1px;
}
li:hover {
background-color: #95B4CA;
}
.parent li:hover {
background-color: #95B4CA;
}
<ul id="nav_ul">
<li class="parent">Home</li>
<li class="parent">Outlook Web</li>
<li class="parent">Production
<ul class="child">
<li class="parent">Hennig South</li>
<li class="parent">Hennig Enclosure Systems</li>
<li class="parent">Hennig South</li>
<li class="parent">Factory Andon</li>
<li class="parent">Web Docs</li>
</ul>
</li>
<li class="parent">IT
<ul class="child">
<li>Knowledge Base</li>
<li>Submit a Ticket</li>
<li class="parent">Archived Links</li>
</ul>
</li>
<li class="parent">Office Directories
<ul class="child">
<li>Hennig</li>
<li>AME</li>
</ul>
</li>
<li class="parent">Hennig Parts</li>
<li class="parent">Factory Andon</li>
<li class="parent">Business Cards</li>
<li class="parent">Reports
<ul class="child">
<li class="parent">Global Shop<span class="expand">»</span>
<ul class="child">
<li>Inventory Report</li>
<li>Sales Report</li>
<li>Quotes Report</li>
<li>Work Order Report</li>
<li>Part Where Used Report</li>
</ul>
</li>
<li class="parent">Ndustrios<span class="expand">»</span>
</li>
</ul>
</li>
</ul>

Using Flexbox to make a navbar with a dropdown menu [duplicate]

We all have hard times with positioning absolute divs :S
In my case its horizontal sub-menus with this css:
ul.children{
display:none;
position:absolute;
}
ul.children li{
position:relative;
height:60px;
float:none;
}
li.page_item_has_children:hover > ul.children{
display:inline;
}
As you can see on the picture whole submenu moves to the left for 50% of the parents width...
I tried everything and created just a bigger mess xD
So if anyone can help me out with this I will be very thankful :)
HTML:
<li class="page_item page-item-2 page_item_has_children">
About
<ul class='children'>
<li class="page_item page-item-39">
About</li>
<li class="page_item page-item-41">
Contact us</li>
</ul>
</li>
I can't change html cause its wordpress theme :S
Try something like this:
ul {
list-style-type: none;
padding: 0;
}
.page_item_has_children {
position: relative;
}
ul.children {
display: none;
position: absolute;
top: 100%;
left: 0;
padding: 0;
min-width: 200px; /* or whatever makes sense */
}
ul.children li {
height: 60px;
}
.page_item_has_children:hover > ul.children {
display: block;
}
The important piece here is to make sure the 'page_item_has_children' element is relatively positioned and that the child 'ul' is absolutely positioned.
JS Fiddle
Update
ul.children {
display: none;
}
ul.children li {
position: relative;
height: 60px;
float: none;
}
li.page_item_has_children:hover > ul.children {
display: inline;
}
li {
float: left;
list-style-type: none;
width: 5em;
}
<ul>
<li class="page_item page-item-2 page_item_has_children">
About
<ul class='children'>
<li class="page_item page-item-39">
About</li>
<li class="page_item page-item-41">
Contact us</li>
</ul>
</li>
<li class="page_item page-item-2 page_item_has_children">
More info
<ul class='children'>
<li class="page_item page-item-39">
Item 1</li>
<li class="page_item page-item-41">
Item 2</li>
<li class="page_item page-item-41">
Item 3</li>
</ul>
</li>
</ul>

UL list items stacking from the bottom instead of top

I have an ul that isn't stacking properly (or is, but not to my desired outcome.)
http://jsfiddle.net/rrrpy1rk/
html:
<ul id="footer_site_map">
<li class="footer_parent">About
<ul class="footer_of_children">
<li class="footer_children">Our Veterinarians
</li>
<li class="footer_children">Our Staff
</li>
</ul>
</li>
<li class="footer_parent">Preventative Medicine
<ul class="footer_of_children">
<li class="footer_children">Puppies
</li>
<li class="footer_children">Kittens
</li>
<li class="footer_children">Adult Care
</li>
<li class="footer_children">Senior Care
</li>
<li class="footer_children">Rabbits
</li>
</ul>
</li>
<li class="footer_parent">Surgical
<ul class="footer_of_children">
<li class="footer_children">Spaying
</li>
<li class="footer_children">Neutering
</li>
<li class="footer_children">Orthopedic Surgery
</li>
<li class="footer_children">Soft Tissue Surgery
</li>
<li class="footer_children">Declawing Cat
</li>
</ul>
</li>
<li class="footer_parent">Medical
<ul class="footer_of_children">
<li class="footer_children"> Complete Medical Assessment
</li>
<li class="footer_children">Cardiology
</li>
<li class="footer_children">Flea Treatment
</li>
<li class="footer_children">Dentistry
</li>
<li class="footer_children">Radiology
</li>
<li class="footer_children">Laboratory
</li>
</ul>
</li>
</ul>
CSS:
#footer_site_map {
position:absolute;
padding:0;
margin:0;
top: 20px;
left: 0;
width:100%;
}
.footer_parent {
position: relative;
width: 180px;
height:20px;
padding: 0 5px;
display: inline-block;
}
.footer_parent a {
color: #FFF;
text-decoration: none;
font-family: MyriadProSemibold;
font-size: 120%;
}
.footer_children {
padding: 5px 0;
width: 200px;
}
.footer_children a {
color: #FFF;
list-style-type: none;
text-decoration: none;
font-family: ralewayregular !important;
font-size: 100%;
}
.footer_of_children {
padding: 0;
margin:0;
}
As seen from the fiddle the parent ul li's are stacking on top of the children ul li's. I need it to go the other way around.
Is there some easy fix, or should I re-structure it.
If you look at the fiddle, you may need to drag the bar to increase the size of the Result.
Addding vertical-align: top; to your .footer_parent fixes the issue:
.footer_parent {
position: relative;
width: 180px;
height: 20px;
padding: 0 5px;
display: inline-block;
vertical-align: top;
}

100% height doesn't work on dropdown menu

Check live- http://uposonghar.com/testsite/
When i add more items to the menus - the menu container does not expand and items get outside the menu.
Screenshot-
Code-
<LI id=navPreretire><A title="Pre Retirement Procedures" href="http://pencproc/" target=_blank><SPAN class=singleLine>Pre Retirement Procedures</SPAN> </A>
<!--Mega menu drop-down part1, the div have to stay like that-->
<div class="dropdown">
<!--until here-->
<Ul>
<div class="dropdown_3rd_lvl1"><li >Plan Benifit Payment Procedures
<ul>
<li >Communications</li>
<li >Manage Payments</li>
<li >Manage Pension Benefits</li>
<li >Reports</li>
</UL></li></div>
<div class="dropdown_3rd_lvl2"><li >Pension Services Procedures
<ul>
<li >Communications</li>
<li >Manage Group Benefits</li>
<li >Manage Payments</li>
<li >Manage Pension Benefits</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
</UL></li></div>
</ul>
<!--Menu ends-->
</div>
<!--Menu ends-->
</LI>
CSS-
.dropdown{
display: none;
BACKGROUND-COLOR: #886d53;
clear: both;
}
.dropdown>ul>li{
clear: both;
float: left;
}
#menu li:hover .dropdown{
position: absolute;
display: block;
height:100%;
min-width: 430px;
margin: 38px auto;
padding-top: 5px;
}
.dropdown ul li{
clear: both;
}
#menu .dropdown ul li:hover{
clear: both;
}
Remove unnecessary height, position:absolute.
#menu li:hover .dropdown {
/*height: 200px;*/
}
#menu ul ul {
height: auto;
}
.dropdown_3rd_lvl1 {
/*position: absolute;*/
/*left: 0*/
/*margin-left: -30px;*/
float: left;
}
.dropdown_3rd_lvl2 {
/*position: absolute;*/
/*margin-left: 170px;*/
float: left;
}
The problem is, at least partly, due to your #menu ul, which applies a height: 38px to the bar, but also gets applied to the ul descendant a few layers deeper.
The entire menu bar seems a bit too complex for what you are trying to achieve, and could be done in a much simpler way.

How to position a drop down list nav bar inside header in html css

I am having trouble stacking up the elements inside the nav bar next to each other.
Here's how it looks:
I want the nav elements to be side by side of each other.
Here's HTML code
HTML:
<div id="navbar">
<ul>
<li>COMPANY
<ul>
<li>OVERVIEW</li>
<li>CEO MESSAGE</li>
<li>LEADERSHIP</li>
<li>INVESTORS</li>
<li>AFFILIATION</li>
<li>CONTACT</li>
</ul>
</li>
<li>PRODUCTS
<ul>
<li>OVERVIEW</li>
<li>PRODUCTS</li>
<li>APPLICATION</li>
<li>USAGE</li>
</ul>
</li>
<li>PARTNER PROGRAM
<ul>
<li>PARTNER PROGRAM</li>
<li>BECOME A PARTNER</li>
</ul>
</li>
<li>LEARN ABOUT WGIG
<ul>
<li>OVERVIEW</li>
<li>VIDEOS</li>
<li>INDUSTRY ARTICLES</li>
<li>WHITE PAPERS</li>
</ul>
</li>
<li>MEDIA CENTER
<ul>
<li>LATEST NEWS</li>
<li>PRESS RELEASES</li>
<li>MEDIA COVERAGE</li>
<li>EVENTS</li>
<li>AFFILIATION</li>
<li>MEDIA KIT</li>
</ul>
</li>
</ul>
</div>
Here's the CSS
CSS:
#navbar {
position: relative;
margin-left: 25%;
border: 5px solid green ;
width: 55%;
height: 100%;
}
#navbar ul {
display: inline-block;
border-radius: 10px;
position: absolute;
}
#navbar li {
list-style: none;
position: relative;
display: inline-block;
float: left;
}
#navbar ul li a {
text-decoration: none;
text-align: center;
color:lime;
height:30px;
width:40px;
display: block;
}
#navbar ul ul {
display:none;
position:absolute;
}
#navbar ul li:hover ul {
display:block;
}
The first <ul> should be relatively positioned. Setting your <a> at a fixed 40px wide isn't such a great idea (nor is it necessary) as most of the text within is more than 40px. Also: your menu items will wrap (stack) unless you set a min-width on their container.
See here: http://jsfiddle.net/RKRWQ/1/