I was just doing some tests with my navbar and when I wanted to put an image right before username, this happend. I don't really know what is the problem, I usually do server-side scripting but not these design. This active class on dropdown menu, as planned, needed to be together with the image, but actually it's only going to the half. If someone can give me example of what things I could put on my CSS file because there lies the problem.
Here is the image
.navbar-image {
width: 32px;
height: 32px;
position: absolute;
top: 10px;
left: -19px;
border-radius: 50%;
}
.nav-img {
position: relative;
padding-left: 50px;
}
<li class="dropdown">
<a href="#" class="dropdown-toggle nav-img" data-toggle="dropdown" role="button" aria-expanded="false">
<img src="/uploads/avatars/{{ Auth::user()->avatar }}" class='navbar-image'>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><i class='fa fa-btn fa-sticky-note'></i>Posts</li>
<li><i class='fa fa-btn fa-user'></i>Profile</li>
<li role="separator" class="divider"></li>
<li><i class="fa fa-btn fa-sign-out"></i>Log out</li>
</ul>
</li>
Try
.dropdown, .dropdown-toggle, .dropdown-menu {
display: inline-block;
}
.dropdown-toggle, .dropdown-menu {
float: right;
}
.navbar-image {
width: 32px;
height: 32px;
border-radius: 50%;
}
Here are the fixes of your menu image:
.dropdown { position: relative; }
.navbar-image {
position: absolute;
width: 32px;
height: 32px;
top: 10px; /*** Set value as per your required ***/
right: 10px; /*** Set value as per your required ***/
border-radius: 50%;
}
Try this code:
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
.navbar-image {
width: 32px;
height: 32px;
border-radius: 50%;
margin-right: 5px;
}
<nav class="navbar navbar-default">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<img src="//placehold.it/80x80/?text=%20" class='navbar-image'>
User Name <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><i class='fa fa-btn fa-sticky-note'></i>Posts</li>
<li><i class='fa fa-btn fa-user'></i>Profile</li>
<li role="separator" class="divider"></li>
<li><i class="fa fa-btn fa-sign-out"></i>Log out</li>
</ul>
</li>
</ul>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
Related
I'm working on a left nav. I want the red bar to appear before menu items when hovering. It works good for the Home item and its sub items but the other root items cause the red bar to span the entire width of the page, from top to bottom, when hovering.
$(document).foundation();
.vertical.dropdown.menu [href] > i {
display: block;
}
.vertical.dropdown.menu [href] {
display: block;
text-align: center;
}
.left-bar {
position: fixed;
top: 0;
left: 0;
width: 150px;
height: 100%;
color: #333;
background: #FFFFFF;
}
.left-bar .vertical.menu.nested {
padding: 0;
}
.left-bar [href] > i {
display: block;
}
.left-bar [href] {
display: block;
text-align: left;
padding: 0;
color: #333;
}
.left-bar [href]:hover {
background: #9B9B9BFF;
}
.left-bar .vertical.menu > li {
position: relative;
background: #FFFFFF;
color: #333;
border: 0;
}
.left-bar .top-level-item [href]:hover::before {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 5px;
background-color: red;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.0/css/foundation.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.1/js/foundation.min.js"></script>
<ul class="vertical dropdown menu left-bar" data-dropdown-menu>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-home zmdi-hc-3x"></i>
<span>Home</span>
</a>
<ul class="vertical menu nested">
<li><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 1</li>
<li><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 2</li>
<!-- ... -->
</ul>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-account zmdi-hc-3x"></i>
<span>Account</span>
</a>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-settings zmdi-hc-3x"></i>
<span>Settings</span>
</a>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-help-outline zmdi-hc-3x"></i>
<span>Help</span>
</a>
</li>
<!-- ... -->
</ul>
How to fix it so that the red bar only spans the height of the menu item?
I made a change in CSS, added a comment there.There was issue in CSS selector based on DOM structure
.left-bar.vertical.menu li instead of .left-bar .vertical.menu > li , I removed the space and > , so that all li are now having position relative
$(document).foundation();
.vertical.dropdown.menu [href] > i {
display: block;
}
.vertical.dropdown.menu [href] {
display: block;
text-align: center;
}
.left-bar {
position: fixed;
top: 0;
left: 0;
width: 150px;
height: 100%;
color: #333;
background: #FFFFFF;
}
.left-bar .vertical.menu.nested {
padding: 0;
}
.left-bar [href] > i {
display: block;
}
.left-bar [href] {
display: block;
text-align: left;
padding: 0;
color: #333;
}
.left-bar [href]:hover {
background: #9B9B9BFF;
}
/* I made a change here */
.left-bar.vertical.menu li {
position: relative;
background: #FFFFFF;
color: #333;
border: 0;
}
.left-bar .top-level-item [href]:hover::before {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 5px;
background-color: red;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.0/css/foundation.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.1/js/foundation.min.js"></script>
<ul class="vertical dropdown menu left-bar" data-dropdown-menu>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-home zmdi-hc-3x"></i>
<span>Home</span>
</a>
<ul class="vertical menu nested">
<li><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 1</li>
<li><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 2</li>
<!-- ... -->
</ul>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-account zmdi-hc-3x"></i>
<span>Account</span>
</a>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-settings zmdi-hc-3x"></i>
<span>Settings</span>
</a>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-help-outline zmdi-hc-3x"></i>
<span>Help</span>
</a>
</li>
<!-- ... -->
</ul>
I made a border left for the red; set to white initially.
I made changes:
Cut out all the CSS not needed including all the position related
stuff
Used classes instead of some [href] I consider "fragile"
Changed to specific background-color to be clear
Set a 0 border, then added the specifics for the left one
Used rem instead of px since typical browsers use a 16px= 1rem size base; and you can force if needed to support those that do not do so.
You can decide on the sub-item if you want the container to continue to have the border and do some things related to that with CSS as here: How to style the parent element when hovering a child element?
or perhaps with some simple JavaScript to help.
$(document).foundation();
.nav-item {
width: 10rem;
background-color: #FFFFFF;
text-align: center;
color: #333;
border: 0;
border-left-width: 0.25rem;
border-left-style: solid;
border-left-color: #FFFFFF;
}
.nav-item:hover {
border-left-color: #FF0000;
}
.nav-item .nav-link:hover {
background-color: #9B9B9BFF;
}
.nav-link {
color: #333333;
}
.nav-link * {
display: block;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.0/css/foundation.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.1/js/foundation.min.js"></script>
<ul class="vertical dropdown menu left-bar" data-dropdown-menu>
<li class="top-level-item nav-item">
<a class="nav-link" href="#">
<i class="zmdi zmdi-home zmdi-hc-3x"></i>
<span>Home</span>
</a>
<ul class="vertical menu nested">
<li class="nav-item"><a class="nav-link" href="#"><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 1</a></li>
<li class="nav-item"><a class="nav-link" href="#"><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 2</a></li>
</ul>
</li>
<li class="top-level-item nav-item">
<a class="nav-link" href="#">
<i class="zmdi zmdi-account zmdi-hc-3x"></i>
<span>Account</span>
</a>
</li>
<li class="top-level-item nav-item">
<a class="nav-link" href="#">
<i class="zmdi zmdi-settings zmdi-hc-3x"></i>
<span>Settings</span>
</a>
</li>
<li class="top-level-item nav-item">
<a class="nav-link" href="#">
<i class="zmdi zmdi-help-outline zmdi-hc-3x"></i>
<span>Help</span>
</a>
</li>
</ul>
you have position absolute on top-level-item href before
put position relative on top-level-item instead of the li
.top-level-item {
position: relative;
}
Currently I'm making multilevel dropdown using bootstrap 3. I expect the child menu is visible outside the parent dropdown menu. This is what I've done
HTML, CSS and JavaScript:
$(document).ready(function(){
$('.dropdown-submenu a.test').on("click", function(e){
$(this).next('ul').toggle();
e.stopPropagation();
e.preventDefault();
});
});
.dropdown-submenu {
position: relative;
}
.dropdown-submenu >.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav id="navbar-collapse-1" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">Test</li>
<li class="dropdown">
Test 1<b class="caret"></b>
<ul role="menu" class="dropdown-menu col-xs-2" style="height: auto; max-height: 1000px; overflow-x: hidden;">
<li></li>
<li>Anting</li>
<li>Cincin</li>
<li>Diamond Jewelry</li>
<li>Dinar</li>
<li class="dropdown-submenu">
Fine Gold<span class="caret"></span>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Toko abc</a></li>
<li><a tabindex="-1" href="#">Toko cde</a></li>
</ul>
</li>
<li>Gelang</li>
<li>Kalung</li>
<li>Liontin</li>
<li>Pin & Accessories</li>
</ul>
</li>
<li class="dropdown">Test 2</li>
</ul>
</nav>
and the result is look like this. the child menu is half hidden. I've been searching for the solution and none of them solve my problem. Thanks in advance
You use position: absolute; to your submenu and you can use toggleClass() to show and hide the menu. check below code.
$(document).ready(function(){
$('.dropdown-submenu a.test').on("click", function(e){
$(this).next('ul').toggleClass('show');
e.stopPropagation();
e.preventDefault();
});
});
.dropdown-submenu {
position: relative;
}
.dropdown-submenu >.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu{
position:relative;
}
.dropdown-menu.submenu{
display:none;
}
.dropdown-menu.submenu.show {
position: absolute;
top: 5px;
left: 50px;
display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav id="navbar-collapse-1" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">Test</li>
<li class="dropdown">
Test 1<b class="caret"></b>
<ul role="menu" class="dropdown-menu col-xs-2" style="height: auto; max-height: 1000px; overflow-x: hidden;">
<li></li>
<li>Anting</li>
<li>Cincin</li>
<li>Diamond Jewelry</li>
<li>Dinar</li>
<li class="dropdown-submenu">
Fine Gold<span class="caret"></span>
<ul class="dropdown-menu submenu">
<li><a tabindex="-1" href="#">Toko abc</a></li>
<li><a tabindex="-1" href="#">Toko cde</a></li>
</ul>
</li>
<li>Gelang</li>
<li>Kalung</li>
<li>Liontin</li>
<li>Pin & Accessories</li>
</ul>
</li>
<li class="dropdown">Test 2</li>
</ul>
</nav>
how to create a border bottom using pseudo selector ( :after) for this code
<li class="nav-list ">
<a href="#" class="nav-link mr-1">
<i class="fas fa-handshake"></i> loyalty Management
</a>
</li>
You can use code as below:
li{
position:relative;
}
.nav-list:after{
content: '';
position: absolute;
bottom: -4px;
height: 2px;
width: 100vh;
background: black;
left: 0;
}
<ul>
<li class="nav-list ">
<a href="#" class="nav-link mr-1">
<i class="fas fa-handshake"></i> loyalty Management
</a>
</li>
</ul>
Try this link Hope this Wil help Codepen
.nav-list {
position: relative;
list-style: none;
}
.nav-list a {
text-decoration: none;
font-size: 20px;
font-weight: 300;
color: #000000;
}
.nav-list a:after {
content: '';
position: absolute;
left: 30px;
bottom: -5px;
height: 2%;
width: 9%;
border-bottom: 2px solid #641F5E;
}
<li class="nav-list ">
<a href="#" class="nav-link mr-1">
<i class="fas fa-handshake"></i> loyalty Management
</a>
</li>
The dropdown-menu is not close to the drowpdown icon. Putting a margin doesn't help.
And how to make the outer color white to black?
.dropdown-toggle {
position: absolute;
display: inline-block;
margin-left: 90%;
top: -50px;
background-color: black;
height: 40px;
width: 40px;
padding-left: 14px;
padding-top: 10px;
}
.dropdown-menu {
min-width: 160px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
right: 0;
background-color: black;
}
.dropdown .dropdown-menu li {
background-color: black;
}
.dropdown .dropdown-menu a {
color: white;
background-color: black;
}
.dropdown .dropdown-menu ul {
top: 10px;
}
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="fa fa-bars white"></i>
</a>
<ul class="dropdown-menu">
<li>HOME</li>
<li>ABOUT</li>
<li>SERVICES</li>
<li>BLOG</li>
<li>CONTACT</li>
<li><i class="fa fa-search" title="fafa"></i></li>
</ul>
</li>
Well, try inline style, not advisable tho, but you can create a custom class on dropdown-menu and copy my inline style and target, also add important to the styles so it would override the default bootstrap style,and your question looks a little confusing in the sense that from the code snippet ran below it shows a different thing from the snapshot you shared, but I think I understand what you mean.
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="fa fa-bars white"></i>
</a>
<ul class="dropdown-menu" style="width:100px;position:absolute;margin-top:-20px;padding-top:20px;"> //adjust this until it fits your taste
<li>HOME</li>
<li>ABOUT</li>
<li>SERVICES</li>
<li>BLOG</li>
<li>CONTACT</li>
<li><i class="fa fa-search" title="fafa"></i></li>
</ul>
</li>
and for the color inspect element from your browser,
find the div from the style and element column in the inspector and change border-top to black like this <div style="border-top:1px solid #000;"></div> from your code on code editor. Happy coding.
This may be tricky to answer/explain properly but:
Building small website for school project. Using bootstrap. When screen is below 780px the nav bar turns into the mobile design with the button icon when clicked has the dropdown menu.
The issue is the menu is meant to push content under it down when its open but it is just going over my content on some page/ under a slideshow i have on main page and it is unclickable as the content sits over it.
I've tried to include all relevant code, it is a complete mess however. Because of all the HTML/CSS and bootstrap and jquery links it's too hard to post in a jfiddle.
Can anyone see anything that would be wrong??
Here is a screenshot of the problem:
http://imgur.com/c5WMDZi
HTML:
<!-- Start of nav bar -->
<div class="bottomHeader">
<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="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="dropdown">
Products<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
<li class="dropdown">
Services<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
<li class="dropdown">
Deals<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
<li>My Account</li>
<li class="dropdown searchDropDown">
Search<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li><form role="search">
<input type="text" class="form-control searchBox" placeholder="Search">
<button type="submit" class="btn btn-default">Submit</button>
</form>
</li>
</ul>
</li>
</ul>
<!-- SEARCH BUTTON -->
<div class="searchSection">
<form class="searchRight" role="search">
<input type="text" class="form-control searchBox" placeholder="Search">
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div> <!-- end bottom header div -->
</div> <!-- end header div -->
</header>
<!-- START OF PAGE CONTENT -->
<content>
<div class="background">
<div class="container2">
<div class="trial"> BOO<br>BOO<br>BOO<br>BOO<br>BOO<br>BOO<br>
</div>
</div>
</div>
</content>
</html>
CSS:
.headerBox {
background-color: #0076a3;
width: 100%;
margin: 0 auto;
height: 115px;
}
.topHeader {
background-color: transparent;
}
.dellImgBox {
padding-left: 42px;
background-color: transparent;
}
.socialMediaBox {
float: right;
margin-right: 53px;
padding-top: 5px;
}
.smImg {
background-color: transparent;
margin-right: 5px;
display: inline-block;
}
.smImgLeft {margin-left: 30px;}
.socialMediaBox a:hover {
background: transparent;
}
/******* Bottom Header ********/
.bottomHeader {
border: 0px solid black;
background-color: transparent;
height: 53px;
}
.navbar-default {
background-color: transparent;
border: 0px;
}
.navbar-header {
float: right;
}
.trial {
margin: 20px 20px;
border: 1px solid black;
min-height: 300px;
color: #444;
}
/* Have nav on right position & display DDmenu */
#media screen and (min-width: 772px) {
.container > .navbar-header,
.container-fluid > .navbar-header,
.container > .navbar-collapse,
.container-fluid > .navbar-collapse {
margin-right: 30px;
margin-left: 0;
margin-top: -13px;
}
ul.nav li.dropdown:hover > ul.dropdown-menu {
display: block;
}
}
#media screen and (max-width: 771px) {
.topHeader {display:none;}
.headerBox {height: 55px;}
ul.nav.navbar-nav {width: 260px;}
}
/* Hide Main Search input field # Xwidth */
#media screen and (max-width: 882px) {
.searchSection {display: none;}
.searchDropDown {display: block;}
}
#media screen and (min-width: 883px) {
.searchDropDown {
display: none!important;
}
}
In your CSS file you should remove height: 53px; and it will work.
.bottomHeader {
border: 0px solid black;
background-color: transparent;
height: 53px;
}
Change to this one:
.bottomHeader {
border: 0px solid black;
background-color: transparent;
}
That's because you have overrided navbar-default class and added background-color:transparent. Just comment it and you can find it on the top of all.
DEMO
.navbar-default {
/*background-color: transparent;*/
border: 0px;
z-index:100000;//Add this property
}