Bootstrap li item remeins highlighted in white after visited - html

I am facing the problem when the Bootstrap item is remaining white background color after being visited. Here is the Html
.my-mail{
background-color: transparent;
cursor:pointer ;
}
.nav-mail:hover:not(.active){
border-left: #007f7e 1px solid;
border-right: #007f7e 1px solid;
color: #007f7e;
/*background-color: transparent;*/
cursor: pointer;
}
.nav-mail:active{
color: white;
cursor: text;
/*background-color: transparent;*/
border-left: transparent 1px solid;
border-right: transparent 1px solid;
border-left: none;
}
.nav-mail:visited{
/*color: white;*/
cursor: text;
background-color: transparent;
border-left: transparent 1px solid;
border-right: transparent 1px solid;
}
.nav-logo:hover{
cursor: pointer;
}
.nav-mail-icon{
font-size: 15px;
background-color: transparent;
cursor: pointer;
}
a:active {
background-color: transparent;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav id="navbar" class="navbar navbar-fixed-top">
<div class="container-fluid" >
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="nav-logo" href="#1"><img class="img-responsive header-logoIMG center-block" src="Images/header/LOGO.png"></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navigation" id="myList">
<li class="nav-btn active">Home</li>
<li class ="nav-btn">About Us</li>
<li class ="nav-btn">Our projects</li>
<li class ="nav-btn">Cooperation</li>
<li class ="nav-btn">Services</li>
<li class ="nav-btn">Contacts</li>
<li class = "nav-item my-mail"><i class="glyphicon glyphicon-envelope nav-mail-icon"></i></li>
</ul>
</div>
</div>
</nav>
In the code above instead of MyEmail link I have my real email. This is the only item that remains highlighted after being visited. I am sure it has something to do with the bootstrap navbar as I have another element with same link mailto and it works fine.
If you have any Ideas what is wrong, please help.
If youll follow the example:https://jsfiddle.net/borovec/aq9Laaew/272810/
you can see that there is a same problem if youll open the menu and press on any item except home, it will remain the white background color.
Thanks in advance!

Try this
.nav >li>a:focus {
background-color: transparent;
}

I think you just need to set css for :focus
like..
li a:focus {
background-color: rgba(0,0,0,0) !important;
border:none !important;
}

Related

Why Navbar Collapse isn't working for me using Bootstrap? [duplicate]

This question already has answers here:
Navbar dropdown (collapse) is not working in Bootstrap 5
(11 answers)
Closed 1 year ago.
I'm having a problem with Bootstrap, navbar collapse button doesn't work I tried everything possible and followed every mentioned step on the Tutorial I was watching. How can I make it work for me without changing the Signup and Login buttons?
Please help me.
Here's my html code:
body{
background-color: #F7F7F7;
font-family: Montserrat-Medium;
}
ul{
list-style-type:none;
}
.navbar-brand{
color: black;
font-family: Montserrat-Medium;
margin-left: 150px;
text-align: center;
}
.nav-brand-text{
}
.nav-signup{
background-color: #5E99EF;
color: white;
border: none;
padding: 16px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin-top: 4px;
border-radius: 46px;
}
.nav-signup:hover{
background-color: #4E83CF;
color: #EAEAEA;
}
.nav-login{
border: 5px solid black;
border-color: #5E99EF;
color: #5E99EF;
padding: 11px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin-top: 4px;
border-radius: 46px;
white-space: nowrap;
}
.nav-login:hover{
color: #4E83CF;
background-color: #EAEAEA;
}
.nav-items-row{
margin-right: 150px;
}
<body>
<nav class="navbar navbar-expand-md navbar-fixed-top navbar-light bg-white shadow-sm p-4 mb-5">
<div class="container-fluid">
<div class="nav-header">
<button type="button" class="navbar-toggler position-absolute start-1" data-toggle="collapse" data-target=".navbar-submenu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="col-md">
<a class="navbar-brand" href="#">
<img src="res/logo.png" width="40" height="40" class="" alt=""></img><b> Tbadel.ma</b>
</a>
</div>
</div>
<div class="collapse navbar-collapse navbar-submenu">
<ul class="nav nav-items-row position-absolute end-0">
<ul class="col-md">
<li>S'identifier</li>
</ul>
<ul class="col-md">
<li>Se connecter</li>
</ul>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.9.1/dist/umd/popper.min.js" integrity="sha384-SR1sx49pcuLnqZUnnPwx6FCym0wLsk5JZuNx2bPPENzswTNFaQU1RDvt3wT4gWFG" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/js/bootstrap.min.js" integrity="sha384-j0CNLUeiqtyaRmlzUHCPZ+Gy5fQu0dQ6eZ/xAww941Ai1SxSY+0EQqNXNE6DZiVc" crossorigin="anonymous"></script>
</body>
In bootstrap5 there is some changes in tag like: data-toggle change to data-bs-toggle
and data-target to data-bs-target
So when use data-bs-target target id of div instead of class.
body{
background-color: #F7F7F7;
font-family: Montserrat-Medium;
}
ul{
list-style-type:none;
}
.navbar-brand{
color: black;
font-family: Montserrat-Medium;
margin-left: 150px;
text-align: center;
}
.nav-brand-text{
}
.navbar-toggler {
z-index: 1;
}
.nav-signup{
background-color: #5E99EF;
color: white;
border: none;
padding: 16px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin-top: 4px;
border-radius: 46px;
}
.nav-signup:hover{
background-color: #4E83CF;
color: #EAEAEA;
}
.nav-login{
border: 5px solid black;
border-color: #5E99EF;
color: #5E99EF;
padding: 11px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin-top: 4px;
border-radius: 46px;
white-space: nowrap;
}
.nav-login:hover{
color: #4E83CF;
background-color: #EAEAEA;
}
.nav-items-row{
margin-right: 150px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<body>
<nav class="navbar navbar-expand-md navbar-fixed-top navbar-light bg-white shadow-sm p-4 mb-5">
<div class="container-fluid">
<div class="nav-header">
<button type="button" class="navbar-toggler position-absolute start-1 collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#navbar-submenu" aria-expanded="false">
<span class="navbar-toggler-icon"></span>
</button>
<div class="col-md">
<a class="navbar-brand" href="#">
<img src="res/logo.png" width="40" height="40" class="" alt=""><b> Tbadel.ma</b>
</a>
</div>
</div>
<div class="collapse navbar-collapse" id="navbar-submenu">
<ul class="nav nav-items-row position-absolute end-0">
<ul class="col-md">
<li>S'identifier</li>
</ul>
<ul class="col-md">
<li>Se connecter</li>
</ul>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.9.1/dist/umd/popper.min.js" integrity="sha384-SR1sx49pcuLnqZUnnPwx6FCym0wLsk5JZuNx2bPPENzswTNFaQU1RDvt3wT4gWFG" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/js/bootstrap.min.js" integrity="sha384-j0CNLUeiqtyaRmlzUHCPZ+Gy5fQu0dQ6eZ/xAww941Ai1SxSY+0EQqNXNE6DZiVc" crossorigin="anonymous"></script>
</body>

Bootstrap navbar collapse opens in the wrong place

Navbar collapsed menu fits perfectly to the navbar in Safari browser and occupy full width of the viewport. However, in other browsers collapsed navbar is getting smaller and sticks to the very top of the page. Looks like it is not connected to the navbar itself and drops down from another reference point. Is this a browser prefix issue or something entirely wrong with my bootstrap structure?
.navbar {
height: 60px;
padding: 0;
margin: 0;
border-bottom: .1px solid black;
background: #ffffff;
}
.navbar-nav {
margin-top: 1.5em;
}
.navBut {
margin: 20px 0;
}
.navButBut {
border: 1px solid red;
}
.navbar-toggle {
border-color: black !important;
color: snow;
height: 30px;
width: 45px;
padding: 2px 5px 0;
margin: 15px 8% 15px 0;
}
.navbar-toggle:hover {
background-color: transparent !important;
}
.dropbut {
font-size: 1.5em;
color: black;
}
.fa-korvue {
color: #962715;
font-size: 3.5em;
line-height: -45%;
float: left;
margin: 5px 8% 0 12%;
}
.link_icon, .link_icon:link, .link_icon:visited, .link_icon:active {
color: #1e1e20;
padding: 0;
margin-right: 20px;
font-family: 'Arsenal', sans-serif;
font-size: 1.2em;
text-decoration: none;
outline: 0;
cursor: pointer;
background: transparent;
}
#collapse_menu {
margin-top: 1.2em;
}
#collapse_menu li a {
padding: 3px 8px;
margin-right: 5px;
border-radius: 3px;
}
#collapse_menu li a:hover {
background-color: rgba(0, 0, 0, 0.2) !important;
}
.hidden-xs {
margin-right: 18px;
}
#phone_handset {
color: black;
font-size: 1.7em;
vertical-align: 10%;
text-decoration: none;
outline: 0;
transition: 1s;
}
#phone_num {
display: inline;
margin-right: 4em;
vertical-align: 20%;
font-size: 1.3em;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<header>
<nav class="navbar navbar-fixed-top">
<div class="container-fluid">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="fa fa-th dropbut"></span>
</button>
<i class="fab fa-korvue"></i>
<div class="collapse navbar-collapse" id="myNavbar">
<ul id="collapse_menu" class="nav navbar-nav text-center">
<li><a class="link_icon scroll" name="1" href="#top_page_scroll">Начало</a></li>
<li><a class="link_icon scroll" name="2" href="#about_me_scroll">Обо мне</a></li>
<li><a class="link_icon scroll" name="3" href="#portfolio_scroll">Услуги</a></li>
<li><a class="link_icon scroll" name="4" href="#pricing_scroll">Цены</a></li>
<li><a class="link_icon scroll" name="5" href="#contact_me_scroll">Регистрация</a></li>
</ul>
<div class="navbar-nav navbar-right vertical-align">
<a id="phone_handset" class="fas fa-phone-volume hidden-xs" href="#"></a>
<a id="phone_num" class="link_icon hidden-xs" href="#">110-223-456-78</a>
</div>
</div>
</div>
</nav>
</header>
I finally fixed this issue. If you wrap navbar-toggle with <div class=“navbar-header”> then everything starts to work as expected. Now collapsed navbar occupies full width and sits in the right place. Thank #fnostro for the valuable tips.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<header>
<nav class="navbar navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="fa fa-th dropbut"></span>
</button>
<i class="fab fa-korvue"></i>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul id="collapse_menu" class="nav navbar-nav text-center">
<li><a class="link_icon scroll" name="1" href="#top_page_scroll">Начало</a></li>
<li><a class="link_icon scroll" name="2" href="#about_me_scroll">Обо мне</a></li>
<li><a class="link_icon scroll" name="3" href="#portfolio_scroll">Услуги</a></li>
<li><a class="link_icon scroll" name="4" href="#pricing_scroll">Цены</a></li>
<li><a class="link_icon scroll" name="5" href="#contact_me_scroll">Регистрация</a></li>
</ul>
<div class="navbar-nav navbar-right vertical-align">
<a id="phone_handset" class="fas fa-phone-volume hidden-xs" href="#"></a>
<a id="phone_num" class="link_icon hidden-xs" href="#">110-223-456-78</a>
</div>
</div>
</div>
</nav>
</header>

bootstrap css searchbox not fit in navigation bar

In my jsp page I want to put searchbox in the navigation bar items.
So I have done below code,click in the link(jsfiddle code).
jsfiddlecode link
But the problem is,search bar is not fit into the navigation bar itmes,when it is in mobile view. why it is not fit into the navigation bar??
You can place the button and the search form inside the navbar-header div so it won't become mixed in with the mobile navbar when the toggle button is clicked since it's currently included inside the nav links. Then you just need to adjust the placement of the toggle button.
*I also adjusted your navbar-nav since it's overlapping the search button at certain widths.
See working example Snippet.
$('#buttonsearch').click(function() {
$('#formsearch').slideToggle("fast", function() {
$('#content').toggleClass("moremargin");
});
$('#searchbox').focus()
$('.openclosesearch').toggle();
});
body {
padding-top: 70px;
}
.searchbardiv {
display: block;
position: fixed;
background: #7D1935;
top: 50px;
right: 0px;
width: 100%;
max-width: 100%;
padding: 10px;
margin: 0px;
}
#formsearch {
display: none;
}
.buttonsearch {
position: fixed;
color: white;
top: 15px;
right: 10px;
background-color: transparent;
border: 0px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.buttonsearch:hover {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
border: 0px;
}
.buttonsearch:focus {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
outline: none;
border: 0px;
}
.glyphicon.glyphicon-search {
font-size: 18px;
}
#searchbox {
box-shadow: none;
padding: 8px 14px;
}
#searchbox:hover {
box-shadow: none;
}
.form-control:focus {
border-color: #ccc;
}
#media (min-width: 768px) {
.navbar .navbar-nav {
margin-right: 10px;
}
}
#media (max-width: 767px) {
.navbar .navbar-toggle {
margin-right: 50px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">MyCompany</a>
<button type="button" class="buttonsearch" id="buttonsearch">
<i class="glyphicon glyphicon-search openclosesearch"></i>
<i class="glyphicon glyphicon-remove openclosesearch" style="display:none"></i>
</button>
<form role="search" method="get" class="searchbardiv" id="formsearch">
<div class="input-group">
<input type="text" id="searchbox" class="form-control" name="s" id="s">
<div class="input-group-btn">
<button class="btn btn-default" id="searchsubmit" type="submit">
<strong>Search</strong>
</button>
</div>
</div>
</form>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">
Home
</li>
<li>
link1
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="well">
Content
</div>
</div>
You can write media css for phone ..just add
#media (max-width: 767px) {
#buttonsearch{
margin-right:20%;
}
}
It will do margin-right to Landscape phone , portrait tablet to phone

make clickable area of <a> fill containing <div>

In the demonstration below, clicking the arrow in the small blue box opens a menu. But only clicking directly on the arrow itself will trigger the menu. How can I make a click anywhere in the small blue box open the menu?
I tried putting the <a> tag first, but the menu disappeared.
body {
margin-top: 50px;
}
ul.dropdown-menuoption {
top: auto;
background: #337ab7;
border-width: 0;
}
.prSemTA {
background: #337ab7;
border-radius: 3px;
font-size: 15px;
padding: 3px 5px 3px 4px
}
.prSemTA a {
color: #FFF;
text-decoration: none;
}
.prSemTA a:hover {
color: #333;
text-decoration: none;
}
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" rel="stylesheet"/>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div style="float:left;padding-left:5px;">
<div class="pull-left prSemTA">
<a href="" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<i class="glyphicon glyphicon-chevron-down"></i>
</a>
<ul class="dropdown-menu dropdown-menuoption">
<li> <i class="glyphicon glyphicon-comment"></i> xxx</li>
<li><i class="glyphicon glyphicon-heart"></i> xxx</li>
<li><i class="glyphicon glyphicon-edit"></i> xxx</li>
<li><i class="glyphicon glyphicon-remove"></i> xxxx</li>
</ul>
</div>
</div>
View on JSFiddle
You can try below code:
.prSemTA {
background: #337ab7;
border-radius:3px;
font-size:15px;
}
.prSemTA a {
color: #FFF;
text-decoration: none;
display:block;
padding:3px 5px 3px 4px
}
Working Demo

How to add arrow bootstrap navbar brand

How do you add an arrow using css to the navbar brand (see image example)
The arrow should not be visible when in mobile view.
The following doesn't work - clearly I'm not the best at css.
.navbar-default {
.navbar-brand {
position: relative;
float: left;
margin-right:30px;
color: #navbar-default-brand-color;
&:hover,
&:focus {
color: #navbar-default-brand-hover-color;
background-color: #navbar-default-brand-hover-bg;
}
&:after {
content: " ";
display: block;
width: 0;
height: 0;
border-top: 19px solid transparent;
border-bottom: 19px solid transparent;
border-left: 12px solid #brand-secondary;
position: absolute;
top: 50%;
margin-top: -19px;
left: 100%;
z-index: 3;
}
&:before {
content: " ";
display: block;
width: 0;
height: 0;
border-top: 19px solid transparent;
border-bottom: 19px solid transparent;
border-left: 12px solid white;
position: absolute;
top: 50%;
margin-top: -19px;
margin-left: 1px;
left: 100%;
z-index: 3;
}
#media (max-width: #grid-float-breakpoint) {
}
}
}
the html is as follows
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button class="navbar-toggle collapsed" aria-controls="navbar" aria-expanded="false" data-target="#navbar" data-toggle="collapse" type="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Bootstrap</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">
Getting started
</li>
<li>
CSS
</li>
<li>
Components
</li>
<li>
Javascript
</li>
<li>
Customize
</li>
</div>
</div>
</nav>
Update: I've managed to get it working using the before and after css. How do I overide this css with the media query i.e whats the css that goes inside the media query to remove it on a mobile device?
have created a small fiddle with example code of how to do this for list items. It can be edited slightly and re-applied to your code to achieve the desired affect.
It's all about the :before and :after selectors.
http://jsfiddle.net/dgc6ajbL/