Problem
How to show second menu in center of page ?
Details
I have two menus.
The first menu show at the top of the page.
The second menu not show on center of page (this is my problem).
As fiddle below second menu display above first menu
actually i need to show second menu in center of page
my fiddle
second menu code
<div>
<nav class="main-nav">
<!--This in case we have more navs-->
<ul class="nav-list">
<li>Home</li>
<li>About</li>
<li>
Services
<ul class="dropdown">
<li>Web Design</li>
<li>Graphic Design</li>
<li>Video Production</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</div>
<div class="con">
<div>
<nav class="main-nav">
<!--This in case we have more navs-->
<ul class="nav-list">
<li>Home</li>
<li>About</li>
<li>
Services
<ul class="dropdown">
<li>Web Design</li>
<li>Graphic Design</li>
<li>Video Production</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</div>
<div class="container second-menu">
<ul>
<li>الرئيسيه</li>
<li>نبذه عن<i></i></li>
<li>اتصل بنا</li>
<li>اللغه</li>
<li> تسجيل دخول</li>
</ul>
</div>
</div>
$(function() {
var heightOfPage = $(window).height();
console.log(heightOfPage);
$(".con").css("height", heightOfPage);
$("li").has(".dropdown").hover(
function() {
$(this).find(".dropdown").slideDown();
},
function() {
$(this).find(".dropdown").slideUp();
}
);
.con{
position: relative;
}
.main-nav ul li{
display: inline-block;
position: relative;
background: #000;
}
.main-nav ul li a{
color: #fff;
text-decoration: none;
padding: 10px;
display: inline-block;
}
.dropdown ul{
padding: 0;
margin: 0;
}
.dropdown{
display: none;
position: absolute;
top: 40px;
left: -30px;
width: 200px;
}
dropdown ul li{
width: 200px;
}
.second-menu ul li{
display: inline-block;
background: red;
padding: 10px;
}
.second-menu ul li a{
color: #fff;
}
.second-menu{
position: absolute;
top: 50%;
}
JsFiddle Link
https://jsfiddle.net/y97coxjo/2/
All you need is to calculate the height of Document and set that height to a container making its position relative and the secondary menu position absolute with top 50%
To have element in the center of page, make it absolute (or static if You want it to stay in center even when scrolling) and position it vertically in center:
#block{
position: absolute;
width: 100%;
left: 0;
height: 50px; //example
top: 50%;
margin-top: -25px; //half of height
}
Then You can put the menu inside that #block.
Related
I'm having troubles adding a little space in my navigation bar. This is for my activity in school please help
here is a picture navbarpic
my html and css so far is
.nav .container ul li{
display: inline-block;
margin: 10px 18px;
position: relative;
}
.nav li{
border-right: 1px solid black;
}
<body>
<div>
<div class="nav">
<div class="container">
<ul>
<li >HOME</li>
<li>ABOUT US</li>
<li>OUR SERVICES</li></li>
</ul>
</div>
</div>
This is my code so far. I would appreciate any help for this . Thanks in advance :)
You can add few padding on the right side of the li element for the navigation items:
.nav .container ul li{
display: inline-block;
margin: 10px 18px;
position: relative;
}
.nav li{
border-right: 1px solid black;
padding-right: 5%;
}
<div>
<div class="nav">
<div class="container">
<ul>
<li >HOME</li>
<li>ABOUT US</li>
<li>OUR SERVICES</li>
</ul>
</div>
</div>
You can use "pseudo" element to make right border with position: absolute style. it will never break your layout and you can move any white from li.
Hope this will help you :)
.nav .container ul li{
display: inline-block;
margin: 10px 18px;
position: relative;
}
.nav li:after{
content: "";
position: absolute;
height: 100%;
right: -15px;
top: 0;
border-right: 1px solid black;
}
<div>
<div class="nav">
<div class="container">
<ul>
<li >HOME</li>
<li>ABOUT US</li>
<li>OUR SERVICES</li>
</ul>
</div>
</div>
I cannot seem to get the most simple, basic drop down menu to work. I'm learning as I go through trial and error. I apologize if it's something obvious!
Here's the HTML:
<body>
<div class="drop">
<ul class="drop_menu">
<ul>
<li>Home</li>
<li>About</li>
<ul>
<li>Biography</li>
<li>Statement</li>
<li>CV</li>
</ul>
<li>New Work</li>
<li>Archive</li>
<li>collaboration</li>
<li>News</li>
</ul>
</ul>
</div>
</body>
CSS:
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
ul li {
display: inline-block;
width: 10em;
height: 2em;
line-height: 2em;
position: relative;
border-bottom: 2px solid #ccc;
}
ul li:hover {
background-color: #ffa;
}
ul li ul {
display: none;
position: absolute;
top: 2em;
left: 0;
}
ul li:hover ul {
display: block;
}
For demostration: http://jsfiddle.net/7env3ust/
What am I doing wrong?
Your child ul must be inside li
<li>About
<ul>
<li>Biography
</li>
<li>Statement
</li>
<li>CV
</li>
</ul>
</li>
DEMO
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
ul li {
display: inline-block;
width: 10em;
height: 2em;
line-height: 2em;
position: relative;
border-bottom: 2px solid #ccc;
}
ul li:hover {
background-color: #ffa;
}
ul li ul {
display: none;
position: absolute;
top: 2em;
left: 0;
}
ul li:hover ul {
display: block;
background-color: red;
z-index: 2;
}
<body>
<div class="drop">
<ul class="drop_menu">
<li>Home
</li>
<li>About
<ul>
<li>Biography
</li>
<li>Statement
</li>
<li>CV
</li>
</ul>
</li>
<li>New Work
</li>
<li>Archive
</li>
<li>collaboration
</li>
<li>News
</li>
</ul>
</div>
</body>
For nested lists, your inner <ul> must be inside a <li>.
<ul>
<li>Home</li>
<li>About
<ul>
<li>Biography</li>
<li>Statement</li>
<li>CV</li>
</ul>
</li>
<li>New Work</li>
<li>Archive</li>
<li>collaboration</li>
<li>News</li>
</ul>
See this answer for more info.
Your ul is actually outside your li so its always shown, take a look at the fixed example.
Here is how it's supposed to look:
<li>About
<ul>
<li>Biography
</li>
<li>Statement
</li>
<li>CV
</li>
</ul>
</li>
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/
I have a drop down nav menu that I need to be centered within a div but text-align: center isn't working for me.
The site is at http://www.joekellywebdesign.com/churchsample1/index.html
HTML
<div id="navmenudiv">
<ul id="navmenu">
<li>Home</li>
<li>
About Us
<ul class="sub1">
<li>Introduction</li>
<li>Who We Are</li>
<li>Staff</li>
</ul>
</li>
<li>
Services
<ul class="sub1">
<li>Sunday Morning</li>
<li>Sunday Evening</li>
<li>Wednesday Evening</li>
</ul>
</li>
<li>Resources</li>
<li>Contact Us</li>
<li>News and Events</li>
</ul>
</div>
CSS
navmenudiv {
z-index:60;
margin: -30px 0;
height:50px;
background-color:#5340BF;
top:40;position:
relative;
text-align:center;
}
Here is an easy solution:
ul#navmenu li {
float:left; /* REMOVE */
display: inline-block; /* ADD */
}
Currently, the li are floating. By changing them to inline-block elements, they will center - given that you are already using text-align:center on the parent.
Updated CSS:
ul#navmenu li {
margin-right: 4px;
text-align: center;
width: 125px;
display: inline-block;
position: relative;
}
ul#navmenu li {
width: 125px;
text-align: center;
position: relative;
margin-right: 4px;
display: inline-block;
margin: 0 10px;
}
I am trying to implement a horizontal navigation menu with a horizontal dropdown menu. I am trying to figure out how to center the horizontal dropdown text so it sits in the center of the navigation container so the user doesn't have to move the mouse far left to reach the links.
<style type="text/css">
#nav-container {
padding: 4px;
width: 900px;
height: 60px;
background: #CCC;
}
#navbar {
margin:0;
padding:0;
}
#navbar li {
padding: 6px;
display: inline;
list-style: none;
}
#navbar li ul {
display: none;
position: absolute;
margin:0;
padding:0;
width: 900px;
}
#navbar li:hover ul {
display: block;
}
</style>
</head>
<body>
<div id="nav-container">
<ul id="navbar">
<li>Link
<ul>
<li>Hello</li>
<li>World</li>
</ul>
</li>
<li>Link
<ul>
<li>Peace</li>
<li>Love</li>
</ul>
</li>
<li>Link
<ul>
<li>Smiles</li>
<li>Cries</li>
</ul>
</li>
<li>Link
<ul>
<li>Homer</li>
<li>Peter</li>
</ul>
</li>
<li>Link
<ul>
<li>Giggity</li>
<li>Fapping</li>
</ul>
</li>
<li>Link
<ul>
<li>Napster</li>
<li>Myspace</li>
</ul>
</li>
</ul>
</div>
This is rough code just to show an example, here is a live example of the code.
Thanks
A combination of relative-absolute positioning should do the trick. I tried adding these two rules and that seemed to work:
#navbar li {
position: relative;
}
#navbar li ul {
position: absolute;
left: 0;
top: 24px; /* must me same as the height of parent li +/- a couple of pixels */
}
That seems to do the trick.