Horizontal main menu with bootstrap and joomla - css

I want to create a horizontal main menu for joomla with bootstrap.
The content is being loaded dynamically by joomla. The styling is done via bootstrap and which overrides it in a separate css file.
It needs to collapse properly for smartphones.
Everything should be done without jquery, if possible.
Task 1
The menu needs to display the submenu items in a horizontal line, the beginning of the main menu, on the left side.
It should be displayed on hover over the parent item. I also added a hover on the submenu itself, so that it stays open if you hover over the submenu items.
But the submenu needs to be replaced if you hover over another parent item.
Task 2
On hover over the parent items, the backgorund needs to display a certain color, so that you can see where are you hovering.
Below the box there needs to be a little triangle in the same color.
Problems
The triangle is not being displayed on all the items.
The box with the parent item shifts the text to the left, since it is adding some space, because of the triangle. The triangle is being added with :hover:after and content: ''.
I got the triangle and the box working, if I change the position of the items to relative. But then the sub-menu is being displayed relative to the parent item and not at the beginning of the menu.
How can I fix that? Is there a way to make the box and the triangle relative and the sub-menu absolute to the menu?
Here is the code on codeply.
Preview
Code
HTML:
<div class="col-xs-15 col-sm-9 col-md-12 mainmenu">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false"></button>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div id="navbar">
<!-- class="nav-collapse collapse" -->
<!-- begin joomla insert main menu -->
<ul class="nav navbar-nav">
<li class="item-101">
Home
</li>
<li class="item-116 deeper parent"><span class="nav-header">Item 1</span>
<ul class="submenu">
<li class="item-151">
SubItem 1
</li>
<li class="item-103">
SubItem 2
</li>
</ul>
</li>
<li class="item-117 deeper parent"><span class="nav-header">Item2</span>
<ul class="submenu">
<li class="item-254 divider">
<span class="separator">SubItem 1</span>
</li>
</ul>
</li>
<li class="item-118"><span class="nav-header">Item 3</span></li>
<li class="item-119 deeper parent"><span class="nav-header">Item 4</span>
<ul class="submenu">
<li class="item-158">
SubItem 1
</li>
<li class="item-169">
SubItem 2
</li>
</ul>
</li>
<li class="item-120">
Item 5
</li>
<li class="item-121"><span class="nav-header">Item 6</span></li>
<li class="item-157">
Item 7
</li>
</ul>
<!-- end joomla insert main menu -->
</div>
</div>
</nav>
</div>
</div>
CSS:
.navbar.navbar-default{
padding-left: 0px;
padding-right: 0px;
margin: 0px;
z-index: 1;
position: absolute;
}
.navbar.navbar-default > div.container-fluid {
/* remove padding */
padding-left: 0px;
padding-right: 0px;
margin: 0px;
}
.mainmenu {
/* remove padding */
padding-left: 0px;
padding-right: 0px;
margin: 0px;
}
ul.nav.navbar-nav {
font-size: 15px;
text-transform: uppercase;
margin-top: 0px;
margin-left: 0px;
}
.submenu {
padding: 0px;
z-index: 1000;
left: 0px;
display: none;
right: 0px;
float: left;
position: absolute;
margin: 0px;
width: 100%;
}
.submenu > li {
list-style: none;
margin: 4px;
margin-right: 4px;
padding: 0px;
white-space: nowrap;
left: 0px;
right: 0px;
float: left !important;
position: relative;
top: 4px;
text-transform: none;
overflow: hidden;
color: #41291c;
}
.submenu > li:first-child {
margin-left: 0px;
padding-left: 0px;
}
.submenu > li:last-child {
margin-right: 0px;
}
.submenu > li > a {
margin: 0px;
color: #41291C;
}
.submenu > li > a:hover {
text-decoration: none;
color: #41291c;
}
.submenu > li > span {
list-style: none;
margin: 0px;
padding: 0px;
}
.nav.navbar-nav > li {
padding-top: 8px;
padding-left: 11px;
padding-right: 11px;
padding-bottom: 4px;
position: static !important;
height: 29px !important;
white-space: nowrap;
float: left;
display: inline-block;
}
.nav.navbar-nav > li:first-child {
padding-left: 0px;
}
.nav.navbar-nav > li:hover {
background-color: #ded6ad;
}
.nav.navbar-nav > li:hover > .submenu {
/* let the menu appear on hover */
display: block;
}
.nav.navbar-nav > li.active > a{
color: #00aad2;
}
.nav.navbar-nav > li > a {
/* including submenus */
font-size: 15px;
text-transform: uppercase;
margin-top: 0px;
padding: 0px;
color: #222;
}
.nav.navbar-nav > li.active > a {
/* current active */
font-size: 15px;
text-transform: uppercase;
background-color: #ffffff;
color: #00aad2;
}
.nav.navbar-nav > li.active > a:hover {
/* current active on hover*/
background-color: #ffffff;
color: #00aad2;
}
.nav-header{
font-size: 15px;
text-transform: uppercase;
line-height: 17px;
box-sizing: border-box;
cursor: pointer;
}
.nav-header:hover > ul.submenu {
display: block !important;
}
.submenu:hover{
display: block;
}
.nav.navbar-nav > li:hover:after {
/* adds the triangle */
z-index: -1;
width: 0;
height: 0;
border-style: solid;
border-width: 5px 3px 0 3px;
border-color: #ded6ad transparent transparent transparent;
bottom: 0px;
left: 50%;
transform: translateX(-50%);
position: relative;
float: left;
margin: 0px !important;
margin-right: -26px;
padding: 0px !important;
box-sizing: border-box;
display: block;
content: "";
}

Related

How to do margin-top only in Firefox browser

I have menu bar which need to be margin-top: 150px;
But visually in Firefox looking different as on Chrome.
Header code: https://codepen.io/bugerman21/pen/rNxvyOv
Chrome:
Correct display
Firefox:
Incorrect display
HTML:
<nav>
<ul class="nav">
<li class="category"><span>Category <i class="fas fa-sort-down"></i></span>
<ul>
<li>Qwerty 1</li>
<li>Qwerty 2</li>
<li>Qwerty 3</li>
<li>Qwerty 4</li>
</ul>
</li>
<li>Cuntact us</li>
<li>FAQ</li>
</ul>
CSS:
* {
margin: 0;
pading: 0;
}
.nav li ul {
position: absolute;
margin-top: 150px;
min-width: 150px;
list-style-type: none;
display: none;
}
How to do margin-top only for the Firefox browser?
Unsuccessful attempt:
#-moz-document url-prefix() {
.nav li ul {
margin-top: 150px;
}
}
Here ya go buddy, sorry I left for the day yesterday but see the changes made and I left outlines on the elements to give a better visual reference. As it is now it will display as expected on all browsers even old internet explorer. Although you could accomplish the same thing cleaner overall, this at least gets you back on track. Cheers and welcome to StackOverflow! :)
PS : since the nav menu items don't have a fixed height you might want to consider making that something static so you can change the top: 56px to a value that places the drop down consistently no matter the width of the screen. If you make the example full screen you'll see what I mean.
header {
display: flex;
margin: 0;
padding: 0 20px;
justify-content: space-between;
align-items: center;
background-color: silver;
}
.header {
grid-area: header;
background-color: #1f1f1f;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
}
/*---------- Logo ----------*/
.logo {
font-family: 'Gentium Book Basic', serif;
font-size: 2.5em;
color: #808080;
}
/*---------- Nav menu ----------*/
.nav {
list-style-type: none;
display: flex;
justify-content: flex-start;
margin: 0;
}
.nav > li {
text-decoration: none;
font-family: 'Roboto', sans-serif;
color: #ffffff;
transition: background-color .25s ease;
}
.nav a {
display: block;
padding: 20px;
color: #ffffff;
font-size: 1em;
}
.category {
padding: 0 20px;
display: flex;
align-items: center;
position: relative;
overflow: visible;
border: red 1px solid;
}
/*---------- Sub menu ----------*/
.nav li ul {
position: absolute;
top: 56px;
left: 0;
min-width: 150px;
margin: 0;
padding: 0;
list-style-type: none;
display: none;
border: green 1px solid;
}
.nav li > ul li {
border-bottom: 1px solid #ffffff;
background-color: #1f1f1f;
}
.nav li > ul li a {
text-transform: none;
}
.nav li:hover > ul {
display: block;
}
.nav > li:hover {
background-color: #404040;
/* box-shadow: -5px 5px #1f1f1f; */
}
.nav li ul > li:hover {
background-color: #404040;
}
/*---------- Search & Profile----------*/
.search_and_profile {
display: flex;
align-items: center;
}
.search_and_profile > p {
margin: 0;
color: #ffffff;
}
.search-container button {
float: right;
padding: 6px 10px;
background: #e0e0e0;
font-size: 17px;
border: none;
cursor: pointer;
}
.search-container input[type=text] {
padding: 6px;
font-size: 17px;
border: none;
}
<header class="header">
<span class="logo">Qwerty</span>
<nav>
<ul class="nav">
<li class="category"><span>Category <i class="fas fa-sort-down"></i></span>
<ul>
<li><a href=#>Qwerty 1</a></li>
<li>Qwerty 2</li>
<li>Qwerty 3</li>
<li>Qwerty 4</li>
</ul>
</li>
<li>Cuntact us</li>
<li>FAQ</li>
</ul>
</nav><!-- .nav -->
<div class="search_and_profile">
<div class="search-container">
<form action="#">
<input type="text" placeholder="Search.." name="search">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div><!-- .search-container -->
</div><!-- .search_and_profile -->
</header>
It will work for me, additionally i included color too to make sure.
Also you try this option too
#media screen and (-moz-images-in-menus:0) {
/* your style */
}
* {
margin: 0;
pading: 0;
}
.nav li ul {
position: absolute;
margin-top: 150px;
min-width: 150px;
list-style-type: none;
display: none;
}
/* Added */
#-moz-document url-prefix('') {
.nav li ul {
margin-top: 150px;
color: orange;
}
}
<div class="nav">
<ul>
<li>Home</li>
<li>About
<ul>
<li>Some text</li>
<li>Some more text</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>

How to fix the position of one element in flux?

I have left side side bar and right side content. I used flex box to separate them. It works fine. But when scrolling the content the side bar on the left side also scrolls along with the content. I wan to fix the side bar in the same position.
This is the Side bar html
<nav id="sidebar">
<ul class="list-unstyled components">
<li>
<a href="#usersMenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle"
>Users</a
>
<ul class="collapse list-unstyled" id="usersMenu">
<li>
<a routerLink="/admins">Admins</a>
</li>
<li>
<a routerLink="/sellers">Sellers</a>
</li>
<li>
<a routerLink="/customers">Customers</a>
</li>
<li>
<a routerLink="/delivery-boys">Delivery Boys</a>
</li>
</ul>
</li>
<li>
<a routerLink="/shop/categories">Categories</a>
</li>
<li>
<a routerLink="/shop/brands">Brands</a>
</li>
<li>
<a routerLink="/shop/products">Products</a>
</li>
<li>
<a routerLink="/shop/orders">Orders</a>
</li>
<li>
<a routerLink="/shop/deliveries">Deliveries</a>
</li>
</ul>
</nav>
This is the Side bar css
a,
a:hover,
a:focus {
color: inherit;
text-decoration: none;
transition: all 0.3s;
}
#sidebar {
min-width: 250px;
max-width: 250px;
background: #1d5ea8;
color: #fff;
transition: all 0.3s;
height: 100%;
margin-top: 56px;
}
#sidebar.active {
margin-left: -250px;
}
#sidebar ul.components {
padding: 20px 0;
border-bottom: 1px solid #1d5ea8;
}
#sidebar ul p {
color: #fff;
padding: 10px;
}
#sidebar ul li a {
padding: 10px;
font-size: 1.1em;
display: block;
}
#sidebar ul li a:hover {
color: #7386d5;
background: #fff;
}
#sidebar ul li.active > a,
a[aria-expanded='true'] {
color: #fff;
background: #1d5ea8;
}
a[data-toggle='collapse'] {
position: relative;
}
.dropdown-toggle::after {
display: block;
position: absolute;
top: 50%;
right: 20px;
transform: translateY(-50%);
}
ul ul a {
font-size: 0.9em !important;
padding-left: 30px !important;
background: #1d5ea8;
}
This is the app-component.html
<div class="wrapper">
<app-side-nav-bar *ngIf="checkLogin()"></app-side-nav-bar>
<app-horizontal-nav-bar *ngIf="checkLogin()"></app-horizontal-nav-bar>
<div id="content">
<router-outlet></router-outlet>
<app-footer *ngIf="checkLogin()"></app-footer>
</div>
</div>
This is the wrapper and content css
.wrapper {
display: flex;
width: 100%;
align-items: stretch;
}
#content {
width: 100%;
min-height: 100vh;
transition: all 0.3s;
}
Image 1
Image 2
You have to set #content to overflow-y: auto so that the scroll bar scrolls inside the content section and not the whole body.

How to format drop down menu with a sticky nav bar (no jQuery)

I'm trying to build a personal website with a sticky nav bar that also has a drop down menu under some of the items. The nav bar is "sticking" but the drop down menu won't appear. I have found that the issues revolve around setting the position of drop down content to absolute and the overflow of the the ul that creates the "nav bar" to hidden. (P.S. I'm relatively new to CSS, so I apologize ahead of time).
So far, I have tried changing the position of the drop down content to "fixed," but this only works properly until you scroll down. Once you scroll down (as aspected) it remains the same distance down and does not adjust to the nav bar's new location. In addition, I have changed the nav bar's overflow to visible. The drop down works correctly, but the formatting of the nav bar is completely messed up. Essentially, all of these changes have made the problem "better," but only creates new issues with them.
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
position: -webkit-sticky;
/* Safari */
position: sticky;
width: 100%;
top: 0px;
}
li {
float: left;
}
li a,
.dropbtn {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover,
.dropdown:hover .dropbtn {
background-color: rgb(228, 40, 40);
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}
<header>
<h1><a id="myNameTop" href="/">JK</a></h1>
</header>
<ul>
<li class="nav-item"><a class="nav-link" href="/resume">Resumé</a></li>
<li class="dropdown nav-item">
<a class="dropbtn" href="/code">Code</a>
<div class="dropdown-content">
GitHub
Embeded JavaScript Projects
</div>
</li>
<li class="nav-item"><a class="nav-link" href="/graphicDesign">Graphic Design</a></li>
<li class="nav-item"><a class="nav-link" href="/contact">Contact</a></li>
</ul>
Currently, I hover over the nav bar item and the drop down item does not come down at all (no matter if I scrolled or not).
I want to see the drop down menu when I hover.
The problem is you're hiding the overflow of ul.
You added overflow: hidden to the <ul> so that its background extended under all it's <li>s, because the <li>s have float:left, for no particular reason.
I suggest "floating" the <li>s using either display:inline-block on them or display:flex on their parent. And, obviously, removing the offending overflow:hidden.
ul {
list-style-type: none;
margin: 0;
padding: 0;
/* overflow: hidden; */
background-color: #333;
position: -webkit-sticky;
/* Safari */
position: sticky;
width: 100%;
top: 0px;
}
li {
/* float: left; */
display: inline-block;
}
li a,
.dropbtn {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover,
.dropdown:hover .dropbtn {
background-color: rgb(228, 40, 40);
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}
body {
margin: 0;
min-height: 200vh;
}
<header>
<h1><a id="myNameTop" href="/">JK</a></h1>
</header>
<ul>
<li class="nav-item"><a class="nav-link" href="/resume">Resumé</a></li>
<li class="dropdown nav-item">
<a class="dropbtn" href="/code">Code</a>
<div class="dropdown-content">
GitHub
Embeded JavaScript Projects
</div>
</li>
<li class="nav-item"><a class="nav-link" href="/graphicDesign">Graphic Design</a></li>
<li class="nav-item"><a class="nav-link" href="/contact">Contact</a></li>
</ul>

overflow:scroll stops hover states from activating

link to codepen
I'm trying to make it so there is a max-height (or height) set to this very long list, and for the rest to scroll. I was able to easily achieve that with
height:800px;
overflow:scroll;
The Problem I have is that the "#subcategory" items stop displaying on hover when I apply overflow:scroll
Any ideas are greatly appreciated!
Basic HTML Structure
<!-- Start Auto Transport -->
<li id="topCategory">Auto Transport
<ul id="subContainer">
<li id="subCategory">Auto Insurance</li>
<li id="subCategory">Auto Payment</li>
<li id="subCategory">Gas</li>
<li id="subCategory">Parking</li>
<li id="subCategory">Public Transportation</li>
<li id="subCategory">Service Parts</li>
<!-- add new becomes text field, user enters text then it becomes added as category -->
<li class="hideNewCategory">
<a class="mmNewCat" data-number="1" href="#"><i class="icon ion-plus-circled"></i>Add New Category</a>
<input id="mmCat1" class="mmCatInpt" type="text" placeholder="Enter New Category" maxlength="25"></input>
</li>
</ul>
</li>
<!-- End Auto Transport -->
<!-- Start Bills Utilities -->
<li id="topCategory">Bills & Utilities
<ul id="subContainer">
<li id="subCategory">Domain Names</li>
<li id="subCategory">Fraud Protection</li>
<li id="subCategory">Home Phone</li>
<li id="subCategory">Hosting</li>
<li id="subCategory">Mobile Phone</li>
<li id="subCategory">Television</li>
<li id="subCategory">Utilities</li>
<!-- add new becomes text field, user enters text then it becomes added as category -->
<li class="hideNewCategory">
<a class="mmNewCat" data-number="2" href="#"><i class="icon ion-plus-circled"></i>Add New Category</a>
<input id="mmCat2" class="mmCatInpt" type="text" placeholder="Enter New Category" maxlength="25"></input>
</li>
</ul>
</li>
<!-- End Bills Utilities -->
relevant CSS
ul li:hover #topContainer{
display: block;
}
ul li a {
display: block;
color: $blue;
text-decoration: none;
font-family: verdana;
font-size: 14px;
}
#topContainer{
list-style: none;
color: $blue;
width: 260px;
height: auto;
background: $white;
opacity: 0.9;
position: absolute;
z-index: 1000;
height:800px;
overflow:scroll;
}
#topCategory {
float: none;
width: auto;
height: 20px;
text-align: left;
margin-left: 15px;
}
#topCategory a:hover {
color: $white;
background-color: $blue;
}
#topCategory:hover #subContainer {
display: block;
}
#topCategory a {
font-size: 16px;
position: relative;
bottom: 41px;
margin-top: 46px;
margin-left: -15px;
padding: 20px 0 20px 20px;
border-bottom:1px solid $grey-10;
}
#topCategory a:hover {
color: $white;
}
#subContainer {
list-style: none;
color: $blue;
display: none;
font-size: 12px;
min-width: 230px;
width: 150px;
height: auto;
background: $white;
opacity: 0.9;
margin: -107px 0 0 245px; position: absolute;
z-index: 1000;
white-space:nowrap;
}
#subContainer a{
border-bottom:1px solid $grey-10;
margin-top: 41px;
}
#subCategory {
float: none;
width: auto;
height: 20px;
text-align: left;
margin-left: 10px;
}
#subCategory:hover {
background: none;
}
.active {
background: $white;
}
#subCategory {
float: none;
// hover length
width:215px;
// hover length
text-align: left;
height: 25px;
margin-left: 15px;
margin-right: -43px;
}
Subcategory should be a Class name not an Id element, change that and things will look cleaner.
.subcategory {
}
<div class="subcategory"></div>

div`s display block inside li element makes it have empty space

I have following code:
<div class="settingsMenu" style="top: 135px; left: 149px; display: block;">
<ul>
<li class="download" onclick="downTemplate('template1')">Download</li>
<li class="delete" onclick="showConfirmationDialog ($(this))">
Delete
<div class="deleteItemConfirmation">
<div class="confirmationText">Are you sure?</div>
<div class="buttons"><button onclick="deleteTemplate ('template1')">Yes</button> <button onclick="hideConfirmationDialog();">No</button></div>
</div>
</li>
<li class="info">Info</li>
</ul>
</div>
CSS:
.settingsMenu{
position: absolute;
top: 0;
left: 0;
display: none;
background-color: #FFFFFF;
border: 1px solid #b5044a;
border-radius: 5px;
width: 150px;
padding: 10px 0;
margin: 0;
z-index: 200;
}
.settingsMenu ul{
list-style-type: none;
width: 100%;
margin: 0px;
padding: 0;
}
.settingsMenu ul li {
color: #000000;
cursor: pointer;
float: left;
font-size: 14px;
font-weight: normal;
font-family: Arial;
height: 18px;
max-width: 100px;
margin: 5px 20px;
padding: 0;
display: block;
padding-left: 30px;
}
.settingsMenu ul li.edit{
background: url("../img/edit-context-menu-icon.svg") no-repeat scroll center left white;
}
.settingsMenu ul li.delete{
background: url("../img/delete-context-menu-icon.svg") no-repeat scroll center left white;
}
.settingsMenu ul li.info{
background: url("../img/info-context-menu-icon.svg") no-repeat scroll center left white;
}
Problem is: while div.deleteItemConfirmation has "display: none;" everything is displaying correctly, when it`s display property becomes "display: block;" strange space appears before text of
<li>Delete</li>
Try changing
<li class="delete" onclick="showConfirmationDialog ($(this))">
Delete
To
<li class="delete" onclick="showConfirmationDialog ($(this))">Delete
Could this help you out:
<ul>
<li>
one</li><li>
two</li><li>
three</li>
</ul>
or
<ul>
<li>one</li
><li>two</li
><li>three</li>
</ul>
or with comments...
<ul>
<li>one</li><!--
--><li>two</li><!--
--><li>three</li>
</ul>
I took the idea from http://css-tricks.com/fighting-the-space-between-inline-block-elements/ and helped me in a few similar situations.

Resources