Trying to center navigation bar with CSS - html

Hello all I'm fairly new to CSS and learning a lot everday, but I'm having some issues centering my "megamenu" navigation bar. I've searched all over and so far none of the things I've tried seem to work with this, it's still mostly left aligned. I've got it set up right now here: https://www.shrinkabulls.com/megamenu/test.html
The code is below. Any help would be greatly appreciated. Thank you!
HTML:
<!-- ...:::: Start Header Section:::... -->
<header class="header-section d-lg-block d-none">
<!-- Start Bottom Area -->
<div class="header-bottom sticky-header">
<div class="container">
<!-- Header Main Menu -->
<div class="main-menu">
<nav>
<ul>
<li>
Home
</li>
<li class="has-dropdown">
Available Bulldogs <i class="fa fa-angle-down"></i>
<!-- Sub Menu -->
<ul class="sub-menu">
<li>Puppies</li>
<li>Adults</li>
<li>French Bulldogs</li>
<li>Stud Service</li>
<li>Past Puppies</li>
</ul>
</li>
<li class="has-dropdown has-megaitem">
Bulldog Info <i class="fa fa-angle-down"></i>
<!-- Mega Menu -->
<div class="mega-menu">
<ul class="mega-menu-inner">
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<a class="mega-menu-item-title">General</a>
<ul class="mega-menu-sub">
<li>Is a bulldog right for you?</li>
<li>Buying a Bulldog Puppy</li>
<li>Naming Your Bulldog</li>
<li>Pricing/Home Approval</li>
<li>Bulldogs and Children</li>
<li>Bulldogs and Cats</li>
<li>Breeding</li>
<li>Showing</li>
<li>Bulldog Merchandise</li>
<li>SCAM Alert</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<a class="mega-menu-item-title">Care</a>
<ul class="mega-menu-sub">
<li>Health/Vet</li>
<li>Nutrition</li>
<li>Supplements</li>
<li>Teeth Cleaning</li>
<li>Spay/Neuter</li>
<li>Heat Stroke</li>
<li>Overweight Bulldogs</li>
<li>Newborn Bulldogs</li>
<li>Pet Insurance</li>
<li>Clothes for Bulldogs</li>
</ul>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<a class="mega-menu-item-title">Breed</a>
<ul class="mega-menu-sub">
<li>History</li>
<li>Standard</li>
<li>Colors</li>
<li>Rare Colors</li>
<li>AKC Color Chart</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<a class="mega-menu-item-title">Training</a>
<ul class="mega-menu-sub">
<li>Crate Training</li>
<li>House Training</li>
<li>Training With Treats</li>
<li>Obedience Training</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<a class="mega-menu-item-title">Links</a>
<ul class="mega-menu-sub">
<li>Links</li>
<li>Sitemap</li>
</ul>
</li>
</li>
</ul>
</div>
</li>
<li class="has-dropdown">
Media <i class="fa fa-angle-down"></i>
<!-- Sub Menu -->
<ul class="sub-menu">
<li>Celebrities With Bulldogs</li>
<li>In The Press</li>
<li>Bulldog Actors</li>
<li>Photos</li>
<li>Videos</li>
</ul>
</li>
<li class="has-dropdown has-megaitem">
Our Dogs <i class="fa fa-angle-down"></i>
<!-- Mega Menu -->
<div class="mega-menu">
<ul class="mega-menu-inner">
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<ul class="mega-menu-sub">
<li>Int Ch Ace</li>
<li>Blue Legacy</li>
<li>Home Brew/JAX</li>
<li>Blue Moon</li>
<li>Ace Jr</li>
<li>Prince</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<ul class="mega-menu-sub">
<li>Ivy</li>
<li>Mystic</li>
<li>Titan</li>
<li>Tundra</li>
<li>Katana</li>
<li>Winston</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<ul class="mega-menu-sub">
<li>Blue Legend</li>
<li>The Boys</li>
<li>Spike</li>
<li>Chocolate Reese</li>
<li>Oscar</li>
<li>Blue Tux</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<ul class="mega-menu-sub">
<li>Dreama</li>
<li>Blue Eyed</li>
<li>Standard Color</li>
<li>Lilac Crave</li>
<li>Chocolate Crave</li>
<li>Black Crave</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<ul class="mega-menu-sub">
<li>Blue Crave</li>
<li>Blue Merle</li>
<li>Exotics</li>
</ul>
</li>
</li>
</ul>
</div>
</li>
<li class="has-dropdown">
About Us <i class="fa fa-angle-down"></i>
<!-- Sub Menu -->
<ul class="sub-menu">
<li>About Shrinkabulls</li>
<li>Awards</li><li>
<li>Contact</li>
</ul>
</li>
</ul>
</nav>
</div> <!-- Header Main Menu Start -->
</div>
</div> <!-- End Bottom Area -->
</header> <!-- ...:::: End Header Section:::... -->
CSS:
.main-menu {
position: relative;
}
.main-menu nav > ul > li {
position: relative;
display: inline-block;
}
.main-menu nav > ul > .has-dropdown {
margin-right: 5px;
}
.main-menu nav > ul > .has-dropdown:last-child {
margin-right: 0;
}
.main-menu nav > ul > .has-megaitem {
position: static;
}
.main-menu nav > ul > li > a {
display: block;
line-height: 24px;
padding: 10px 10px;
font-size: 20px;
text-transform: capitalize;
font-weight: 500;
color: #993b00;
}
.main-menu nav > ul > li > a:hover, .main-menu nav > ul > li > a.active {
background: #993b00;
color: #FFF;
}
.sub-menu > li > a,
.mega-menu-sub > li > a {
font-size: 18px;
display: block;
line-height: 35px;
text-transform: capitalize;
color: #000;
position: relative;
transition: all 0.3s ease 0s;
}
.sub-menu > li > a::after,
.mega-menu-sub > li > a::after {
position: absolute;
content: "";
top: 50%;
left: 0;
transform: translate(0px, -50%);
height: 5px;
width: 5px;
border-radius: 50%;
background: #993b00;
visibility: hidden;
opacity: 0;
transition: all 0.3s ease 0s;
}
.sub-menu > li > a:hover,
.mega-menu-sub > li > a:hover {
color: #993b00;
transform: translateX(10px);
}
.sub-menu > li > a:hover::after,
.mega-menu-sub > li > a:hover::after {
transform: translate(-10px, -50%);
visibility: visible;
opacity: 1;
}
.sub-menu {
position: absolute;
min-width: 230px;
padding: 25px 20px;
background: #ece2a5;
box-shadow: 0 3px 11px 0 rgba(0, 0, 0, 0.1);
transform: perspective(600px) rotateX(-20deg);
transform-origin: 0 0 0;
left: 0;
right: auto;
opacity: 0;
visibility: hidden;
transition: 0.5s;
z-index: 99;
top: 100%;
text-align: left;
}
.mega-menu {
position: absolute;
min-width: 100%;
padding: 25px 30px 30px 30px;
background: #ece2a5;
box-shadow: 0 3px 11px 0 rgba(0, 0, 0, 0.1);
transform: perspective(600px) rotateX(-20deg);
transform-origin: 0 0 0;
left: 0;
right: 0;
opacity: 0;
visibility: hidden;
transition: 0.5s;
z-index: 99;
top: 100%;
text-align: left;
}
.mega-menu-inner {
display: flex;
justify-content: space-between;
}
.mega-menu-item-title {
font-size: 20px;
line-height: 24px;
text-transform: uppercase;
font-weight: 700;
display: block;
margin-bottom: 13px;
color: #333;
}
.mega-menu-item-title:hover {
color: #261146;
}
.mega-menu-sub > li {
display: block;
}
.main-menu nav > ul > li:hover .sub-menu,
.main-menu nav > ul > li:hover .mega-menu {
opacity: 1;
visibility: visible;
transform: perspective(600px) rotateX(0deg);
}

It seems to me that the whole menu is not centered... why don't you try to add
.main-menu > nav > ul {
display: flex;
justify-content: center;
}
if this is not what you are looking for, please clarify!
Edit: I'm glad that worked, I corrected the css so the outcome you mention no long happens.
If you are going to keep working with css, maybe try some methodology or convention to name elements to avoid that something like this happens to you in the future BEM for instance is great or you can read something about atomic design.

What exactly are you trying to center? If it is the menu text, just use the
text-align
CSS attribute (https://developer.mozilla.org/en-US/docs/Web/CSS/text-align).
for example, in class header-bottom, you would have the following (text-align:center added to bottom):
.header-bottom {
background: #ece2a5;
position: relative;
box-shadow: 0 3.4px 2.7px rgb(0 0 0 / 1%), 0 8.7px 6.9px rgb(0 0 0 / 1%), 0 17.7px 14.2px rgb(0 0 0 / 1%), 0 36.5px 29.2px rgb(0 0 0 / 1%), 0 100px 80px rgb(0 0 0 / 2%);
text-align: center;
}
If it is something else you are trying to center, please explain in more detail, and I will edit this answer accordingly.

Related

Sub-submenu should open on hover

'data2' should be shown only on hover of SubSubmenu1, But it opens while hovering on SubMenu1 itself (along with data1 and subsubmenu1 dropdown). Can anyone guide me how to make it(data2) open only when hovered on SubSubmenu1. Thank you.
<div class="collapse navbar-collapse" id="myNavbarToggler4">
<ul class="navbar-nav">
<!-- menu item-->
<li class="nav-item"><a class="nav-link" href="indexpage">Mainmenuitem1</a></li>
<!-- menu item-->
<li class="has-dropdown">
Mainmenuitem2
<ul>
<li class="dropdown-submenu">
<!-- submenus -->
<a style="background-color: grey; margin-right: 100px" href="#" class="dropdown-toggle"
data-toggle="dropdown">SubMenu1</a>
<div id="SM1" style="margin-right:100px;" aria-labelledby="navbarDropdown">
<ul class="dropdown">
<li class="dropdown-item">
<input type="checkbox" id="data1" data-id=0 checked>
<label for="data1">data1</label>
</li>
<li class="dropdown-subsubmenu">
<!-- with submenu -->
<a style="background-color: grey; margin-right: 100px" href="#" class="dropdown-toggle"
data-toggle="dropdown">SubSubMenu1</a>
<div id="SubSubMenudata" style="margin-right:100px;" aria-labelledby="navbarDropdown">
// this dropdown opens when I hover on SubMenu1.
// Should open only when I hover on SubSubMENU1
<ul style="background-color: grey;" class="dropdown">
<li class="dropdown-item">
<input type="checkbox" id="d2" data-id=0 checked>
<label for="d2">data2</label>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
</ul>
</li>
</ul>
</div>
Below is the CSS.
ul ul li:hover ul,
ul li:hover > ul {
opacity: 1;
visibility: visible;
}
.dropdown {
z-index: 1002;
visibility: hidden;
opacity: 0;
position: absolute;
top: 14px;
}
Your code needs some improvement - I've chopped out some lines to make clear which needs you to reorganize it again. The functionally should be working now. Hope that's work!
ul ul li:hover ul,
ul li:hover > ul {
opacity: 1;
visibility: visible;
}
.dropdown {
z-index: 1002;
visibility: hidden;
opacity: 0;
position: absolute;
top: 14px;
}
ul.left_menu{
width:180px;
padding:0px;
margin:0px;
list-style:none;
}
ul.left_menu li{
margin:0px;
list-style:none;
}
ul.left_menu li.odd a{
width:166px;height:25px;display:block; border-bottom:1px #e4e4e4 dashed;
text-decoration:none;color:#504b4b;padding:0;
line-height:25px;
}
.smenu{
display:none
}
ul.left_menu li.odd:hover .smenu
{
display:block;
color: #FFB03B;
}
ul.left_menu li.even:hover .smenu
{
display:block;
color: #FFB03B;
}
<ul class="left_menu">
<div class="collapse navbar-collapse" id="myNavbarToggler4">
<ul class="navbar-nav">
<!-- menu item-->
<li class="nav-item"><a class="nav-link" href="indexpage">Mainmenuitem1</a></li>
<!-- menu item-->
<li class="has-dropdown">
Mainmenuitem2
<ul>
<li >
<!-- submenus -->
<a style="background-color: grey; margin-right: 100px" href="#" class="dropdown-toggle"
>SubMenu1</a>
<ul >
<li class="even">SubSubMenu1
<!-- with submenu -->
<ul class="smenu">
<li >
<a>data2</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</ul>
I havent tested this with your code. so it might not work perectly for you.
but below is a link to a thing called "onmouseover Events".
this is using javascript to apply the css on whats called "mouseover".
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onmouseover
Documentation: https://www.w3schools.com/jsref/event_onmouseover.asp
see if maybe you can use this :)
Below is an CSS only example aswell if you dont want to use the java script example i posted.
Just click the "Run Snippet" button to test it.
* {
font-family: sans-serif;
}
#horizontalmenu ul {
list-style: none;
padding: 0;
}
#horizontalmenu>ul>li {
float: left;
position: relative;
border: 1px solid #555555;
border-radius: 3px;
background-color: #383838;
}
#horizontalmenu>ul>li>a {
text-decoration: none;
padding: 5px 10px;
display: block;
color: white;
}
#horizontalmenu>ul>li>a:hover {
background-color: rgb(104, 104, 104);
}
#horizontalmenu>ul>li>ul {
background-color: rgb(148, 148, 148);
display: none;
width: 150px;
top: 100%;
left: 0;
position: absolute;
}
#horizontalmenu>ul>li>ul>li {
position: relative;
width: 100%;
display: block;
}
#horizontalmenu>ul>li>ul>li>a {
text-decoration: none;
padding: 5px 10px;
display: block;
color: black;
}
#horizontalmenu>ul>li>ul>li>a:hover {
background-color: rgb(73, 73, 73);
}
#horizontalmenu>ul>li:hover>ul {
display: block;
}
#horizontalmenu>ul>li>ul>li>ul {
display: none;
position: absolute;
left: 100%;
top: 0;
width: 150px;
}
#horizontalmenu>ul>li>ul>li>ul>li>a {
text-decoration: none;
padding: 5px 10px;
display: block;
color: black;
background-color: #797979;
}
#horizontalmenu>ul>li>ul>li:hover ul {
display: block;
}
<div id="horizontalmenu">
<ul>
<!-- list start -->
<li>
Menu 1
<ul>
<li>
text
</li>
<li>
text
</li>
<li>
text >
<ul class="horizontal">
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
</ul>
</li>
<li>
text
</li>
</ul>
</li>
<li>
Menu 2
<ul>
<li> text</li>
<li> text</li>
<li> text</li>
</ul>
</li>
</ul>
</div>

Auto-Height a responsive menu

I'm trying to make a mobile menu with the structure of ul > li > ul which each sub ul having its height based of the number of li.
But when entering a sub-sub tiny ul of a big sub ul makes the sub-sub tiny ul overflow vertically which is showing the content of its parent :
How can I prevent the sub-sub tiny ul to be overflow vertically ?
$(document).ready(function(){
let menu = $('nav')
// open submenu
menu.find('a').on('click', function(){
let parent = $(this).parent()
parent.toggleClass('active')
})
// close submenu
menu.find('.back').on('click', function(){
let parent = $(this).parent().parent()
parent.toggleClass('active')
})
})
:root {
font-size: 10px;
}
* {
box-sizing: border-box;
}
nav {
position: fixed;
width: 300px;
box-shadow: 0 0 5px rgba(0, 0, 0, .2);
overflow: hidden;
}
nav a:hover {
color: blue;
}
nav > ul {
height: auto;
}
ul {
list-style: none;
padding-inline-start: 0;
padding: 0 1.5rem;
margin: 0;
width: 100%;
background: #FFF;
}
ul > li:not(:last-child) {
border-bottom: 1px solid #AAA;
}
ul > li > a {
display: flex;
justify-content: space-between;
padding: 1.2rem 1.5rem;
font-size: 1.5rem;
line-height: 1.5em;
font-weight: bold;
text-transform: uppercase;
font-family: sans-serif;
cursor: pointer;
}
ul > li:not(.back) > ul ~ a::after {
content: '►';
}
ul > li > ul {
position: absolute;
top: 0;
left: 0;
transform: translateX(100%);
transition: .3s;
overflow-x: hidden;
z-index: 2;
height: 100%;
}
ul > li.back {
margin: 0 -1.5rem;
border-bottom-width: 0;
z-index: 1;
}
ul > li.back > a {
background: #DDD;
font-size: 1rem;
justify-content: flex-start;
}
ul > li.back > a::before {
content: '◄';
margin-right: .5rem;
}
ul > li.see-all > a {
padding: .5rem 0;
font-size: 1.3rem;
text-align: center;
text-transform: inherit;
justify-content: center;
}
ul > li.active > ul {
transform: translateX(0);
}
ul.dark {
padding: 0;
}
ul.dark > li:not(:last-child) {
border-bottom: 1px solid #FFF;
}
ul.dark > li > a {
background: #AAA;
padding: 1.5rem 3rem;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav>
<ul>
<li>
<ul>
<li class="back">
<a>Return</a>
</li>
<li>
<ul>
<li class="back">
<a>Return</a>
</li>
<li>
<ul>
<li class="back">
<a>Return</a>
</li>
<li>
<a>Sub-sub-category 1</a>
</li>
<li>
<a>Sub-sub-category 2</a>
</li>
</ul>
<a>Sub-category 1</a>
</li>
<li>
<a>Sub-category 2</a>
</li>
<li>
<a>Sub-category 3</a>
</li>
<li>
<a>Sub-category 4</a>
</li>
<li>
<a>Sub-category 5</a>
</li>
</ul>
<a>Category 1</a>
</li>
<li>
<a>Category 2</a>
</li>
<li>
<a>Category 3</a>
</li>
<li class="see-all">
<a>See all products</a>
</li>
</ul>
<a>Products</a>
</li>
<li>
<ul>
<li class="back">
<a>Return</a>
</li>
<li>
<a>Fiesta</a>
</li>
</ul>
<a>Events</a>
</li>
</ul>
<ul class="dark">
<li>
<a>Stores</a>
</li>
<li>
<a>Account</a>
</li>
<li>
<a>Contact</a>
</li>
</ul>
</nav>
Thanks for feeback

How to make sub sub menu work in my navigation?

Im having some problems with CSS, sub sub (third, fourth level) menus don't work and can't make it work I already tried everything I could think off. Anybody have the time to look at my code, please. I played with the code and tried all sorts of thing just nothing works.
I tried with
.navigation-1 ul li ul li ul li
but can't find the problem. I guess my css skills are not that good, lol :P
.navigation-1{
float: left;
width: auto;
margin-right: 0px;
}
.navigation-1 ul > li{
float: left;
width: auto;
position: relative;
}
.navigation-1 li:last-child{
margin-right: 0px;
}
.navigation-1 ul > li > a{
display: inline-block;
padding: 26px 30px;
font-size: 15px;
text-transform: capitalize;
/*font-family: 'Exo', sans-serif;*/
}
.navigation-1 > ul > li:after,
.navigation-1 > ul > li:before{
position: absolute;
content: "";
top:50%;
left: 0px;
bottom: 0px;
height: 10px;
width: 2px;
margin: 15px auto 0px;
right: 0px;
opacity: 0;
}
.navigation-1 > ul > li:before{
padding: 0px 5px;
border-left: 2px solid #2f3539;
border-right: 2px solid #2f3539;
opacity: 0;
}
.navigation-1 > ul > li:after{
border-right: 2px solid #2f3539;
height: 15px;
width: 2px;
opacity: 0;
}
.navigation-1 ul li ul{
position: absolute;
left: 0px;
right: 0px;
top:100%;
width: 195px;
background: #171e22;
visibility: hidden;
opacity: 0;
overflow: hidden;
z-index: 9999;
}
.navigation-1 ul li ul li{
float: left;
width: 100%;
}
.navigation-1 > ul > li.active:after,
.navigation-1 > ul > li.active:before,
.navigation-1 > ul > li:hover:after,
.navigation-1 > ul > li:hover:before{
opacity: 1;
}
nav.navigation-1 ul li:hover ul{
visibility: visible;
opacity: 1;
}
nav.navigation-1 ul li ul li a{
border-bottom: 1px solid #2f3539;
color: #fff;
display: inline-block;
padding:9px 15px;
position: relative;
width: 100%;
}
.navigation-1 ul li ul li:hover a{
background: #dc1937;
border-color: #dc1937;
color:#fff !important;
}
<nav class="navigation-1">
<ul>
<li class="active">home
<ul class="sub-menu children">
<li>Home Light</li>
</ul>
</li>
<li>artist
<ul class="sub-menu children">
<li>artist</li>
<li>artist 02</li>
<li>artist 03</li>
<li>dj</li>
</ul>
</li>
<li class="menu-item ">
event
<ul class="sub-menu children">
<li>
event list
</li>
<li>
event list 02
</li>
<li>
event list 03
</li>
<li>
event detail
</li>
</ul>
</li>
<li class="menu-item ">music
<ul class="sub-menu children">
<li>
dj
</li>
<li>
video
</li>
<li>
video list
</li>
<li>
video detail
</li>
<li>
mp3 list
</li>
<li>
music artist albums
</li>
<li>
music albums
</li>
<li>
masonry gallary
</li>
</ul>
</li>
<li class="menu-item ">blog
<ul class="sub-menu children">
<li>
blog detail
</li>
<li>
blog left sidebar
</li>
<li>
blog right sidebar
</li>
<li>
blog full
</li>
<li>
blog medium
</li>
<li>
blog small
</li>
<li>
masonry small
</li>
</ul>
</li>
<li class="menu-item ">
page
<ul class="sub-menu children">
<li>
shop
</li>
<li>
shop items
</li>
<li>
shop listing
</li>
<li>
headers
</li>
</ul>
</li>
<li>contact us</li>
</ul>
</nav>
Here is the original HTML code (without sub sub menus, as I already have my navigation managed through my CMS)
Thank you
R

Menu different in chrome browser

for some reason my menu bar (its fixed) is in 2 lines in chrome browser and normal in all other browsers. Any idea why or how to fix it? I tried to figure it out but i didnt fix it. Is it a problem with browser default block height or what? I need to make it work on chrome and on all other browsers too.
JsFiddle: https://jsfiddle.net/wkupr9L6/1/
HTML:
<script>
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 65) {
$("nav").css("opacity", "0.2");
}
else {
$("nav").css("opacity", "1");
}
});
</script>
</head>
<body>
<!--MENU BAR!-->
<nav class="navig">
<span class="nadpis"> RPO </span>
<ul class="nav">
<li class="prve">Dátumy
<ul>
<li>1-7/7/2016
<ul>
<li>1/7/2016</li>
<li>2/7/2016</li>
<li>3/7/2016</li>
<li>4/7/2016</li>
<li>5/7/2016</li>
<li>6/7/2016</li>
<li>7/7/2016</li>
</ul>
</li>
<li>8-14/7/2016
<ul>
<li>8/7/2016</li>
<li>9/7/2016</li>
<li>10/7/2016</li>
<li>11/7/2016</li>
<li>12/7/2016</li>
<li>13/7/2016</li>
<li>14/7/2016</li>
</ul>
</li>
<li>15-21/7/2016
<ul>
<li>15/7/2016</li>
<li>9/7/2016</li>
<li>10/7/2016</li>
<li>11/7/2016</li>
<li>12/7/2016</li>
<li>13/7/2016</li>
<li>14/7/2016</li>
</ul>
</li>
</ul>
</li>
<li class="druhe">&#9776
<ul>
<li> FLV
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> FLC
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> QUA
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> HFX
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> PDT
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul></li>
<li> RSH
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> BUR
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> SUHRN </li>
<li> INCI </li>
<li> JIRA </li>
<li> CHGT </li>
<li> TASK </li>
<li> VRS </li>
</div>
</ul>
</li>
</ul>
</nav>
CSS:
body, nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav {
display: inline-block;
position: fixed;
width: 100%;
text-align: center;
background-color: #111;
vertical-align: top;
top: -1px;
opacity: 1;
transition: 0.3s;
}
nav:hover {
opacity: 1!important;
background-color: #111;
transition: 0.3s;
}
.nav a {
display: block;
background: #111;
color: #fff;
text-decoration: none;
padding: 0.7em 1.7em;
text-transform: uppercase;
font-size: 85%;
letter-spacing: 3px;
position: relative;
}
.nav{
vertical-align: top;
display: inline-block;
}
.nav li {
position: relative;
}
.nav > li {
float: left;
margin-right: 1px;
}
.nav li:hover > a {
transition: 0.3s;
background-color:#3a3939;
color: #40d23b;
}
.nav ul {
position: absolute;
white-space: nowrap;
z-index: 1;
left: -99999em;
background-color: #000;
border: 2px solid #81D4FA;
border-top: none;
}
.nav > li:hover > ul {
left: auto;
min-width: 100%;
}
.nav > li li:hover > ul {
left: 100%;
top:-1px;
}
.nav > li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
}
.nav li li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
right: 10px;
}
.prve{
max-width:125px;
min-width: 90px;
border: 2px solid #81D4FA;
border-bottom: none;
border-top: none;
}
.druhe {
max-width: 14px;
min-width: 110px;
border-right: 2px solid #81D4FA;
}
span {
float:left;
margin-left: 3px;
}
span a{
text-decoration: none;
color:#2670CF;
background-color:#111;
font-family: 'Helvetica Neue', sans-serif;
font-size: 30px;
font-weight: bold;
}
Thanks for help
This doesn't seem like a browser issue. You have .nav set to display: inline-block; but nothing on the two inner <li> elements to force them onto the same line.
I added this:
.nav > li {
display: inline-block;
}
And it works for me in Chrome. See here:
https://jsfiddle.net/tobyl/wkupr9L6/6/

Bootstrap dropdown menu (in navigation) no JavaScript

I wonder if it is possible to make the following work:
#keepwidth {
width: 1000px;
}
.row.top-menu > ul {
padding: 0;
}
.row.top-menu > ul > li {
display: inline-block;
}
.row.top-menu > ul > li > a {
display: inline-block;
background-color: #009ec3;
color: #fff;
min-width: 123px;
text-align: center;
text-transform: uppercase;
border: 2px #009ec3 solid;
border-radius: 3px;
margin: 0;
}
.row.top-menu > ul > li > a:hover {
background-color: #90d2ec;
color: #666;
text-decoration: none;
}
.row.top-menu > ul > li.dropdown:hover ul {
display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div id="keepwidth">
<div class="row top-menu">
<ul>
<li>
asdas
</li>
<li class="dropdown">
Hover here <span class="caret"></span>
<ul class="dropdown-menu">
<li>
temp
</li>
</ul>
</li>
<li>
sadsad
</li>
<li>
asdasda
</li>
<li>
sadasdasdsa
</li>
<li>
sadasdsadsa
</li>
<li>
sadasdsasdasdsa
</li>
</ul>
</div>
</div>
I do not wish to make use of JavaScript and I do not wish to move the dropdown menu element around (e.g. margin-top: 0 or margin: 0) and I want to make the dropdown appear when hovering both the dropdown menu itself and the button refering to it.
Since you're using Bootstrap, you'll need to follow their CSS conventions as explained here in order to get predictable behavior:
https://jsfiddle.net/Bendrick92/mgny3g87/
#keepwidth {
width: 1000px;
}
.navbar-nav > li > a {
display: inline-block;
background-color: #009ec3;
color: #fff;
min-width: 123px;
text-align: center;
text-transform: uppercase;
border: 2px #009ec3 solid;
border-radius: 3px;
margin: 0;
}
.navbar-nav > li > a:hover {
background-color: #90d2ec;
color: #666;
text-decoration: none;
}
.dropdown:hover .dropdown-menu {
display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div id="keepwidth">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
asdas
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" role="button">
Hover here <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
temp
</li>
</ul>
</li>
<li>
sadsad
</li>
<li>
asdasda
</li>
<li>
sadasdasdsa
</li>
<li>
sadasdsadsa
</li>
<li>
sadasdsasdasdsa
</li>
</ul>
</div>
</div>