I have custom navbar, not any bootstrap or something else.
I tryed one tab is left and dropdowns are middle and one tab is right side.
But right side tab isnt inside navbar.
I dont understand why it is going out of navbar if it is in ul tag. Maybe someone can explain that.
HTML code:
<div id="nav">
<div id="nav_wrapper">
<ul>
<div id="left">
<li>
item #1
</li>
</div>
<div id="mid">
<li> dropdown #1
<ul>
<li>
dropdown #1 item #1
</li>
<li>
dropdown #1 item #2
</li>
<li>
dropdown #1 item #3
</li>
</ul>
</li>
<li> dropdown #2
<ul>
<li>
dropdown #2 item #1
</li>
<li>
dropdown #2 item #2
</li>
<li>
dropdown #2 item #3
</li>
</ul>
</li>
<li> dropdown #3
<ul>
<li>
dropdown #3 item #1
</li>
<li>
dropdown #3 item #2
</li>
<li>
dropdown #3 item #3
</li>
</ul>
</li>
</div>
<div id="right">
<li>
item #2
</li>
</div>
</ul>
</div>
<!-- Nav wrapper end -->
Style code:
body {
padding: 0;
margin: 0;
font-family: Arial;
font-size: 17px;
}
#nav {
background-color: #222;
}
#left{
float: left;
}
#mid{
margin-left: auto;
margin-right: auto;
text-align: center
}
#right{
float: right;
}
#nav ul {
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
min-width: 200px;
}
#nav ul li {
display: inline-block;
}
#nav ul li:hover {
background-color: #333;
}
#nav ul li a, visited {
color: #CCC;
display: block;
padding: 15px;
text-decoration: none;
}
#nav ul li:hover ul {
display: block;
}
#nav ul ul {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-top: 0;
margin-left: -5px;
z-index: 1;
}
#nav ul ul li {
display: block;
}
#nav ul ul li a:hover {
color: #699;
}
Added html and style code here.
Problem is right side isnt in navbar.
I think in divs is problem.
Pls try
#nav_wrapper ul{
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display:flex;
}
and now you DON'T have to give float:left and float:right to the #left and #right divs; and your right div will be aligned on the right end.
OR
Add the following codes to your existing styles, to align your third item on the right end.
#nav{
background-color: #222;
overflow:hidden;
}
#mid{
float:left;
}
Related
In CSS, one submenu (Link 1, Link2, Link3) is available in this link. https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_dropdown_navbar
I'm trying to create submenu (link 4.1, link4.2) under the above submenu as shown in below image.
how can I get this submenu. .
I've tried below. But this is overlapping. I'm newbie to CSS. please share your ideas
<div class="dropdown">
<button class="dropbtn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<div class="dropdown">Link 1</div>
<div class="dropdown-content">
Link 2
Link 3
</div>
Link 2
Link 3
</div>
</div>
This can be done by simple html/css work so just to give an idea here is a simple example:
ul {
list-style: none;
padding: 0;
margin: 0;
background: #000;
}
ul li {
display: block;
position: relative;
float: left;
background: #000;
}
li ul {
display: none;
}
ul li a {
display: block;
padding: 1em;
text-decoration: none;
white-space: nowrap;
color: #fff;
}
ul li a:hover {
background: #001;
}
li:hover>ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
}
li:hover a {
background: #000;
}
li:hover li a:hover {
background: #000;
}
ul ul ul {
left: 100%;
top: 0;
}
<ul>
<li>Home</li>
<li>First level Menu
<ul>
<li>Second Level</li>
<li>Second Level with third level
<ul>
<li>Third level</li>
<li>Third level</li>
</ul>
</li>
</ul>
</li>
</ul>
I have a menu bar on a hover it should display a submenu. I am displaying the sub menu but it moving entire main menu to side. I want the submenu out of the main menu, next to the main menu.
my HTML code
<div class="MenuBar">
<ul>
<li><img src="#"><br>text1</li>
<div id="submenu">
this is a test div
</div>
<li><img src="#"><br>text2</li>
<li><img src="#"><br>text3</li>
</ul>
CSS
#submenu {
display: none;
}
.MenuBar ul li a:hover #submenu {
display: block;
position: relative;
top: 20px;
}
I think this is what you are after. I have added classes to the lists, changed your id submenu to class and added submenu items to all lists.
.MenuBar ul li .submenu {
display: none;
}
.MenuBar ul li.men1:hover .submenu {
display: inline-block;
position: relative;
top: 20px;
}
.MenuBar ul li.men2:hover .submenu {
display: inline-block;
position: relative;
top: 20px;
}
.MenuBar ul li.men3:hover .submenu {
display: inline-block;
position: relative;
top: 20px;
}
<div class="MenuBar">
<ul>
<li class="men1">text1
<div class="submenu">
hovered 1st
</div></li>
<li class="men2">text2
<div class="submenu">
hovered 2nd
</div></li>
<li class="men3">text3<div class="submenu">
hovered 3rd
</div></li>
</ul>
Let me know if this was what you were after.
you can use following CSS for this:
if you want to show submenu in bottom of parent menu
.MenuBar ul li {
position: relative;
}
.MenuBar ul li:hover #submenu {
display: block;
position: absolute;
top: 100%;
left: 0px;
}
or if you want to show submenu in right of parent menu
.MenuBar ul li {
position: relative;
}
.MenuBar ul li:hover #submenu {
display: block;
position: absolute;
top: 0;
left: 100%;
}
Place the submenu div outside your lists. If you throw that inside a bunch of list item and play with display property, it will affect the list structure. Place that div outside the list item, position the submenu div with css so it always alignment to the respective menu item and them add your hover effect.
Change Html Like this:
<li>
<img src="#"><br>text1
<div id="submenu"><-----------------submenu must be child li
this is a test div
</div>
</li>
And Css Like This :
.MenuBar ul li a:hover + #submenu {<--------------use + selector
display: block;
position: relative;<-----Remove This
top: 20px;<------Remove This
margin-top: 20px;<----------Add This
margin-bottom: 10px;<-------Add This
}
Full Code:
#submenu {
display: none;
}
img {
width: 20px;
}
ul {
list-style: none;
}
.MenuBar ul li a:hover + #submenu {
display: block;
margin-top: 20px;
margin-bottom: 10px;
}
<div class="MenuBar">
<ul>
<li>
<a href="#">
<img src="https://www.seeklogo.net/wp-content/uploads/2012/12/apple-logo-eps-logo-vector-400x400.png"><br>text1
</a>
<div id="submenu">
this is a test div
</div>
</li>
<li>
<a href="#">
<img src="https://www.seeklogo.net/wp-content/uploads/2012/12/apple-logo-eps-logo-vector-400x400.png"><br>text2
</a>
</li>
<li>
<a href="#">
<img src="https://www.seeklogo.net/wp-content/uploads/2012/12/apple-logo-eps-logo-vector-400x400.png"><br>text3
</a>
</li>
</ul>
</div>
I asked previously a question about how to make a dropdown menu by css. Now I've got it to work beautifully. But now I need to make it react to on click. The menu I'm trying to create will have 2 sets of nested list items. I'm using pseudo selecter :focus on the first level list items. But of course I lose the focus part when I'm trying to display the nested list item. Is it possible in some way to keep the first level list item to stay focused while the user goes deeper in the menu?
My html code is like this
<header class="Header">
<!-- Head navigation-->
<div>
<img src="images/cart_logo_webb_design.svg" alt="cart">
<img src="images/search_logo_webb_design.svg" alt="search glass">
</div>
<div> <img src="images/k_logo_webb_design.svg" alt="CompanyLogo"> </div>
<div>
<nav id="MainNavigation">
<img src="images/menu_logo_webb_design.svg" alt="Menu icon">
<ul id="dropDownMenu">
<li>
<a class="Sub_Menu_Link" href="#" title="Woman">Woman
</a>
<li>
<a class="Sub_Menu_Link" href="#" title="Womanplus">+
</a>
<ul>
<li>1 </li>
<li>2 </li>
<li>3 </li>
<li>4 </li>
<li>5 </li>
</ul>
</li>
</li>
<li> <a class="Sub_Menu_Link" href="#" title="Man">Man</a>
<li>
<a class="Sub_Menu_Link" href="#" title="Manplus">+
</a>
<ul>
<li>1 </li>
<li>2 </li>
<li>3 </li>
<li>4 </li>
<li>5 </li>
</ul>
</li>
</li>
<li><a class="Sub_Menu_Link" href="#" title="Sale">Sale</a></li>
</ul>
</nav>
</div>
</header>
header {
position: fixed;
display: block;
background: white;
z-index: 1;
width: 100%;
top: 0;
}
.Header img {
width: 36px;
height: 40px;
}
header div {
float: right;
width: 33.33%;
margin: 0;
}
header div:first-of-type a {
padding: 0%;
}
header div:after {
content: "";
visibility: hidden;
display: block;
clear: both;
}
nav {
position: relative;
left: 0;
}
nav > ul {
margin: 0;
padding: 0 0px;;
float: left;
line-height: 40px;
}
nav a {
positon: absolute;
left: 0;
}
nav ul ul {
padding: 20px;
}
nav ul a {
list-style: none;
text-decoration: none;
}
nav ul ul li a {
display: inline-block;
}
nav > ul:after {
content: "";
visibility: hidden;
display: block;
clear: both;
}
.Sub_Menu_Link {
display: inline-block;
padding: 10px 0px;
line-height: 40px;
}
.Sub_Menu_Link:hover {
color: yellow;
}
nav ul {
background: #E9E9E9;
position: relative;
width: 100%;
}
nav ul ul li a:hover {
color: yellow;
}
nav ul ul {
display: none;
}
nav ul a:focus {
background: red;
}
nav ul a:focus ~ ul {
display: block;
}
nav > a:hover {
background-color: red;
}
nav > a:focus {
background-color: green;
}
nav ul {
display: none;
}
nav > a:focus ~ ul {
display: block;
}
It is not possible to do it simply with the :focus selector. In CSS, you cannot select the parent of an element, so as to keep the visibility with focus on a child. As an example:
element:focus -parent { /* this doesn't exist */ }
That simply does not exist as of right now. And you also cannot have focus on multiple elements, which adds on to the issue.
There are two ways that I can think of solving your problem:
Using the JavaScript event onclick instead of a CSS-only approach;
Maintaining the CSS-only approach and using input:checked instead of :focus for your triggers. It's known as The Checkbox Hack.
I have made a navigation menu bar and also two dropdown menus with 3 items each. My problem is that, below this menu, I have a slider, so when I hover my dropdown, two of the three items are hidden behind the slider.
How can I solve this?
My HTML:
<div id="nav">
<div id="nav_wrapper">
<ul>
<li>item #1
</li>
<li> item #2
</li>
<li> dropdown #1
<ul>
<li>dropdown #1 item #1
</li>
<li>dropdown #1 item #2
</li>
<li>dropdown #1 item #3
</li>
</ul>
</li>
<li> dropdown #2
<ul>
<li>dropdown #2 item #1
</li>
<li>dropdown #2 item #2
</li>
<li>dropdown #2 item #3
</li>
</ul>
</li>
<li> item #3
</li>
</ul>
</div>
</div>
My CSS:
#nav {
background-color: #222;
}
#nav_wrapper {
width: 960px;
margin: 0 auto;
text-align: left;
}
#nav ul {
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
min-width: 200px;
}
#nav ul li {
display: inline-block;
}
#nav ul li:hover {
background-color: #333;
}
#nav ul li a, visited {
color: #CCC;
display: block;
padding: 15px;
text-decoration: none;
}
#nav ul li:hover ul {
display: block;
}
#nav ul ul {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-top: 0;
margin-left: -5px;
}
#nav ul ul li {
display: block;
}
#nav ul ul li a:hover {
color: #699;
}
I think the problem is on your z-index properties.
You need to set on #nav and #slider elements position and z-index properties.
#nav {
position: relative;
z-index: 2;
}
#slider{
position: relative;
z-index: 1;
}
That means the #nav menu will be front slider when you set a z-index property large than z-index on #slider. Have you attention that z-index doesn't work if you not set element position property like relative or absolute.
You can look this link for example - http://css-tricks.com/almanac/properties/z/z-index/
Okay, so I created a drop down menu.
Before I added the ul and li tags, it centered fine. Now it won't center. I tried adding left/right as auto, text-align center and even going into the div tag itself and putting align center, nothing works. So I added extra space to some of the menu items, but overall nothing looks properly spaced.
My second issue is that on the drop downs, there appears to be some extra left side spacing and I cannot figure out why it is there or how to get rid of it. Any help would be appreciated. Thank you!
Here is my HTML:
<div id="menu" align="center">
<ul>
<!-- main ul tag -->
<li>Home
</li>
<!-- close home li tag -->
<li class="aboute">About Ebenezer
<ul>
<!-- About Ebenezer menu -->
<li class="aboute">Our History
</li>
<li class="aboute">Our Pastor
</li>
<li class="aboute">Services
</li>
</ul>
<!-- close About Ebenezer menu -->
</li>
<!-- close About Ebenezer li tag -->
<li class="min">Ministries
<ul>
<!-- Ministries menu -->
<li>Women
</li>
<li>Men
</li>
<li>Youth
</li>
</ul>
<!-- close Ministries menu -->
</li>
<!-- close Ministries li tag -->
<li class="min">Community
<ul>
<!-- Community menu -->
<li>Backpack Buddies
</li>
<li>Outreach
</li>
</ul>
<!-- close Community menu -->
</li>
<!-- close Community li tag -->
<li class="min">Events
<ul>
<!-- Events menu -->
<li>Calendar
</li>
<li>Events
</li>
</ul>
<!-- close Events menu -->
</li>
<!-- close Events li tag -->
<li class="photos">Photos
</li>
<!-- close Photos li tag -->
<li class="non-list">Contact
</li>
<!-- close Contact li tag -->
</ul>
<!-- end of main ul tag -->
</div>
<!-- end of menu -->
Here is my CSS:
#menu {
height: 40px;
width: 1104px;
padding-top: 2px;
background-color: #0c495c;
margin-right: auto;
margin-left: auto;
font-family: choco;
font-size: 38px;
color: #FFFFFF;
text-align: center;
}
#menu ul {
padding: 0px;
margin:0px 0px 0px 0px;
text-align: center;
}
#menu ul li {
float: left;
position: relative;
background-color: #0c495c;
list-style-type: none;
width: 150px;
padding: 0px;
}
#menu ul li.non-list {
float: left;
position: relative;
background-color: #0c495c;
list-style-type: none;
width: 100px;
}
#menu ul li.aboute {
float: left;
position: relative;
background-color: #0c495c;
list-style-type: none;
width: 195px;
margin-left: -10px;
padding: 0px;
left: 15px;
}
#menu ul li.min {
left: 15px;
}
#menu ul li.photos {
float: left;
position: relative;
background-color: #0c495c;
list-style-type: none;
width: 160px;
}
#menu ul li a {
color: #FFF;
text-decoration: none;
display: block;
}
#menu ul ul {
position: absolute;
visibility: hidden;
}
#menu ul li:hover ul {
visibility: visible;
}
#menu ul li ul li a:hover {
color: #f3b830;
}
#menu ul li a:hover {
color: #f3b830;
}
You can fix the spacing issue between menu items by specifying a height for the <li> and pulling the submenus down by applying top equal to the height set for <li>
JSFiddle
It's better to avoid tags and properties such as align for styling purpose and do the styling using css
try it mate, i think its fine now, Im set a width as auto or 100%, remove some margin, left, and add small padding ..
<html><head><style>
#menu {
height: 40px;
width: 1104px;
padding-top: 2px;
background-color: #0c495c;
margin-right: auto;
margin-left: auto;
font-family: choco;
font-size: 38px;
color: #FFFFFF;
text-align: center;
}
#menu ul {
padding: 0px;
margin:0px 0px 0px 0px;
text-align: center;
}
#menu ul li {
float: left;
position: relative;
background-color: #0c495c;
list-style-type: none;
width: 150px;
padding: 0px;
}
#menu ul li.non-list {
float: left;
position: relative;
background-color: #0c495c;
list-style-type: none;
width: 100px;
}
#menu ul li.aboute {
float: left;
position: relative;
background-color: #0c495c;
list-style-type: none;
width: auto;
/* margin-left: -10px; */
padding: 0px;
/* left: 15px; */
}
#menu ul li.min {
left: 15px;
}
#menu ul li.photos {
float: left;
position: relative;
background-color: #0c495c;
list-style-type: none;
width: 160px;
}
#menu ul li a {
color: #FFF;
text-decoration: none;
display: block;
font-size: 30px;
width: auto;
padding: 0 5px;
}
#menu ul ul {
position: absolute;
visibility: hidden;
}
#menu ul li:hover ul {
visibility: visible;
}
#menu ul li ul li {
display: block;
width: 100% !important;
}
#menu ul li ul li a:hover {
color: #f3b830;
}
#menu ul li a:hover {
color: #f3b830;
}
</style>
</head><body><div id="menu" align="center">
<ul>
<!-- main ul tag -->
<li>Home
</li>
<!-- close home li tag -->
<li class="aboute">About Ebenezer
<ul>
<!-- About Ebenezer menu -->
<li class="aboute" style="
/* display: block; */
/* width: 100%; */
">Our History
</li>
<li class="aboute">Our Pastor
</li>
<li class="aboute">Services
</li>
</ul>
<!-- close About Ebenezer menu -->
</li>
<!-- close About Ebenezer li tag -->
<li class="min">Ministries
<ul>
<!-- Ministries menu -->
<li>Women
</li>
<li>Men
</li>
<li>Youth
</li>
</ul>
<!-- close Ministries menu -->
</li>
<!-- close Ministries li tag -->
<li class="min">Community
<ul>
<!-- Community menu -->
<li>Backpack Buddies
</li>
<li>Outreach
</li>
</ul>
<!-- close Community menu -->
</li>
<!-- close Community li tag -->
<li class="min">Events
<ul>
<!-- Events menu -->
<li>Calendar
</li>
<li>Events
</li>
</ul>
<!-- close Events menu -->
</li>
<!-- close Events li tag -->
<li class="photos">Photos
</li>
<!-- close Photos li tag -->
<li class="non-list">Contact
</li>
<!-- close Contact li tag -->
</ul>
<!-- end of main ul tag -->
</div>
<!-- end of menu --></body></html>