I have a navbar which is designed in Bootstrap 4 , I am trying to change the hamburger background-color of the navbar, and the rest of the navbar in some other color.
Here is the sketch of my current output and what I am trying to do:
I tried using z-index property but nothing seems to work. Can you give me any ideas?
.navbar {
padding-left: 80px;
height: 54px;
top: 40px;
flex-flow: row nowrap;
display: inline-flex;
border-bottom-right-radius: 200px;
border-top-right-radius: 200px;
background-color: #A6ACAF !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/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 class="navbar navbar-light animated fadeInLeft" style="background-color: #C0C0C0 ;">
<button class="navbar-toggler navbar-toggler-left" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="#navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="lines"></span>
<span class="lines"></span>
<span class="lines"></span>
</button>
<h1 class="navbar-brand mb-0 move-header">NavBrand</h1>
<div class="collapse animated fadeInLeft" id="navbarNav">
<ul class="navbar-nav">#yield('setActive') </ul>
</div>
</nav>
If you want to change the hamburger background-color try applying the style on .navbar-toggler or .navbar-toggler-left class and not .navbar
.navbar-toggler {
background-color: red;
}
Updated:
Left of the button is still grey - has nothing to do with the background-color. Bootstrap by default has the following styles on .navbar-toggler-left
.navbar-toggler-left {
position: absolute;
left: 1rem; //this is getting that left gap
}
Override the above left: 1rem; to your own value which is 0
.navbar-toggler {
background-color: red;
left: 0; //fix
}
Adjust width & height of the toggler accordingly if you want.
Related
Im trying to build a collapsible sliding left panel using bootstrap 5. Im almost there but having some issues.
If you have a look at the code here: https://jsfiddle.net/dizzy0ny/86wjas9L/108/
You will see i try to achieve this two different ways. one using javascript and one using Boostrap/CSS. The behavior are different.
i would like the panel to slide left. this works for the javascript code (Toggle1 button). But does not for toggle2 button. in the latter's case it slides up instead
regardless of method used the content shown does not resize to fit the entire page width then the panel is collapsed. And in other case when the window is smaller, if i expand the collapsed panel, a horizontal scrollbar appears as the chart does not resize to fit. Ive tried a few styling options to try and correct this - but have thus far failed.
lastly - anyway to have the content area's height adjusted to fit also so the vertical scroll bar does not show?
here is the html:
<head>
<!-- JQuery links -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/#fortawesome/fontawesome-free#6.1.2/css/fontawesome.min.css" integrity="sha384-X8QTME3FCg1DLb58++lPvsjbQoCT9bp3MsUU3grbIny/3ZwUJkRNO8NPW6zqzuW9" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/jquery#3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.14.0-beta2/css/bootstrap-select.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.14.0-beta2/js/bootstrap-select.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/data.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script src="https://code.highcharts.com/stock/modules/export-data.js"></script>
<script src="https://code.highcharts.com/stock/modules/accessibility.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<div class="collapse navbar-collapse" id="navbar">
<div class="navbar-nav">
Toggle1
Toggle2
<a class="nav-item nav-link" id="home" href="#">Home</a>
<a class="nav-item nav-link" id="menu1" href="#">Menu 1</a>
<a class="nav-item nav-link" id="menu2" href="#">Menu 2</a>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row flex-nowrap">
<div id="sidebar" class="col-auto px-1 collapse collapse-horizontal show border-end">
<!--left collapsible nav bar-->
<div id="sidebar-nav" class="min-vh-100">
<form>
<div>
<div class="mb-3">
<select id="cot_contract" name="cot_contract" class="form-control selectpicker" data-live-search="true">
<option>Some Item Number 1</option>;
<option>Some Item Number 2</option>';
<option>Some Item Number 3</option>';
</select>
</div>
<div class="mb-3">
<input type="text" class="form-control" id="input1" name="input1" placeholder="Enter some text" />
</div>
</div>
</form>
</div>
</div>
<!--main content area-->
<main class="col ps-md-2 pt-2">
<div id="container"></div>
</main>
</div>
</div>
</body>
Here is the CSS:
#sidebar {
min-width: 250px;
max-width: 250px;
background: #7386D5;
color: #fff;
transition: all 0.3s;
padding: 5px;
align-items: stretch;
}
#sidebar.active {
margin-left: -250px;
}
#container {
height: 100%;
width: 100%;
}
and finally the javacript:
#sidebar {
min-width: 250px;
max-width: 250px;
background: #7386D5;
color: #fff;
transition: all 0.3s;
padding: 5px;
align-items: stretch;
}
#sidebar.active {
margin-left: -250px;
}
#container {
height: 100%;
width: 100%;
}
Thanks much
Update:
Finally got all of this to work. the final issue of re-sizing the content and dealing with the vertical scroll bar always showing:
added d-flex h-100 flex-column to top level container for the row
containing the nav panel and content.
added body/html height 100%
main content column needs a display of 'content'.
to fix the vertical scroll bar always showing - moved nav into top
level div as another row. added 'h-100' 2nd row (containing the
collapsing pane and content).
Updated and working jsfiddle: https://jsfiddle.net/dizzy0ny/86wjas9L/513/
Man i hate css.
According to documentation from W3School, it's possible to do the sidebar the same without jQuery in a more pure way.
function openNav() {
document.getElementById("mySidebar").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
}
function closeNav() {
document.getElementById("mySidebar").style.width = "0";
document.getElementById("main").style.marginLeft= "0";
}
Highcharts.chart('container', {
series: [{
data: [2, 5, 2, 3, 6, 5]
}]
});
.sidebar {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidebar a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
}
.sidebar a:hover {
color: #f1f1f1;
}
.sidebar .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
.openbtn {
font-size: 20px;
cursor: pointer;
background-color: #111;
color: white;
padding: 10px 15px;
border: none;
}
.openbtn:hover {
background-color: #444;
}
#main {
transition: margin-left .5s;
padding: 16px;
}
/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
#media screen and (max-height: 450px) {
.sidebar {padding-top: 15px;}
.sidebar a {font-size: 18px;}
}
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="mySidebar" class="sidebar">
×
</div>
<div id="main">
<button class="openbtn" onclick="openNav()">☰ Open Sidebar</button>
<div id="container"></div>
</div>
Demo: https://jsfiddle.net/BlackLabel/kned9yuv/
----- EDIT
To adjust the chart to your container you can use chart.reflow(), every time when you resize the window.
Demo: https://jsfiddle.net/BlackLabel/kned9yuv/3/
Expected: I am trying to get the same as in the following image.
Actual: But what I got is as in the following image
Here's my HTML:
<div class="heading-container d-flex flex-row justify-content-start">
<h1 class="main-heading"> Finding Nemo </h1>
<button class="button"> Watch Now </button>
</div>
And CSS:
.heading-container {
margin-top: 20px;
}
.main-heading {
color: #ffffff;
font-family: "Roboto";
font-size: 24px;
font-weight: bold;
}
.button {
background-color: #ffffff;
color: #ff8348;
border-width: 0px;
border-radius: 10px;
height: 32px;
width: 110px;
font-size: 13px;
}
I see you're using bootstrap, you can just add align-right to the class of your button:
<button class="button float-right"> Watch Now </button>
Can you please check the below code? Hope it will work for you. You just need to replace justify-content-start with justify-content-between bootstrap class in
heading-container. It will display the child items with space between the lines.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="heading-container d-flex flex-row justify-content-between">
<h1 class="main-heading"> Finding Nemo </h1>
<button class="button"> Watch Now </button>
</div>
I would like the button to change color on hover when hovering anywhere in the nav bar (.topNav). In my current code, the change happens only when hover over the button (.top, .middle, .bottom classes). I got this to work using span, but that was changing all the spans in the .topNav class.
html...
<nav class="navbar-default"
<div class="topNav">
<div class="navbar-header">
<button type="button" class="navbar-toggle button_container collapsed"
[ngClass]="{'active': !menuCollapsed}" (click)="toggleMenu()">
<span class="top"></span>
<span class="middle"></span>
<span class="bottom"></span>
</button>
</div>
....other content
</div>
</nav>
SCSS...
.top, .middle, .bottom {
background: white;
transition: 0.25s;
}
.topNav:hover, .button_container:hover, .top:hover, .middle:hover,
.bottom:hover {
background: black;
transition: 0.25s;
}
Here you go:
.topNav{
background: red;
}
.topNav:hover>.navbar-header>button {
background: black;
transition: 0.25s;
}
<nav class="navbar-default"><!-- OOPS YOU FORGOT TO CLOSE THIS TAG -->
<div class="topNav">
<div class="navbar-header">
<button type="button" class="navbar-toggle button_container collapsed"
[ngClass]="{'active': !menuCollapsed}" (click)="toggleMenu()">
<span class="top"></span>
<span class="middle"></span>
<span class="bottom"></span>
</button>
</div>
....other content
</div>
</nav>
You forgot to close the nav tag.
.topNav:hover>.navbar-header>button means when you hover over .topNav select a specfic child element ( the button ). Then do stuff with that ( paint it black )
header a:hover{
color:#BFEFFF;
font-weight:bold;
}
Try something like this in the CSS code.
I use this on my webpage: http://www.kunalkolhe.com/
I have heard from experienced developers that using CSS for extensive projects is not a good Idea though.
FYI... I got this to work with two solutions...
1) Using the navbar-header class and span. Previously when I tried this same solution with the .button_container class (instead of navbar-header), it did not work. I still do not understand why.
Code using span...
.navbar-header span {
background: white;
transition: 0.25s;
}
.topNav:hover>.navbar-header span {
background: black;
transition: 0.25s;
}
2) Code using the three classes...
.top, .middle, .bottom {
background: white;
transition: 0.25s;
}
.topNav:hover>.navbar-header>button>.top, .topNav:hover>.navbar-header>button>.middle, .topNav:hover>.navbar-header>button>.bottom {
background: black;
transition: 0.25s;
}
I'm trying to vertically align a title header, an alert and two buttons.
My goal is to make the width of the alert bigger even if its content is short. My problem is that since I uses span for the alert, I need to put display: inline-block in its style but by doing that, the alignment with the header gets misaligned. BTW, I'm using Bootstrap.
Here's the image of what I want to happen:
Here's my HTML:
<h1>
<span>This will be a very long title</span>
<span class="alert custom">
This is notification!
</span>
<span class="pull-right">
<button class="btn button-round">O</button>
<button class="btn button-round">X</button>
</span>
</h1>
Here's my CSS:
.button-round {
border-radius: 50%;
color: white;
background: green;
}
.custom{
font-size: 12px;
vertical-align: middle;
background: green;
color: white;
}
Here's a jsfiddle of my current code:
JSFiddle of my current code
To make this easy, you should use flex :
.button-round {
border-radius: 50%;
color: white;
background: green;
margin: auto
}
.custom {
font-size: 12px;
vertical-align: middle;
background: green;
color: white;
/* added */
flex: 1;
margin: 0 0.25em;
}
h1 {
display: flex;
}
/* end added */
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->
<h1>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<span>This will be a very long title</span>
<span class="alert custom">
This is notification!
</span>
<span class="pull-right">
<button class="btn button-round">O</button>
<button class="btn button-round">X</button>
</span>
</h1>
https://jsfiddle.net/fczbe58L/1/
I'd like to add one of those buttons that are shown when on mobile device in order to open the collapsed menu in the navbar, but haven't been able so far, here's the less code and html
.navbar-toggle-always{
.navbar-toggle;
#media (min-width: 768px){
display: block!important;
}
.zero-margins;
}
html
<div class="pull-left ">
<button type="button" class="navbar-toggle-always collapsed" data-toggle="collapse" data-target="#left" aria-expanded="false" aria-controls="navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
upon further inspection I've noticed that the element is not hidden, it's just transparent, for some reason if I add
#media (min-width: 768px){
display: block!important;
background-color:pink;
}
i see it fine, but withouth the icon-bar bars or the borders. I'll keep working on it
and this is how I would like to show it:
After some tests I managed to obtain the desired results:
here's the less code:
.navbar-inverse {
.navbar-toggle-always {
border-color: #navbar-inverse-toggle-border-color;
&:hover,
&:focus {
background-color: #navbar-inverse-toggle-hover-bg;
}
.icon-bar-always {
background-color: #navbar-inverse-toggle-icon-bar-bg;
}
}
}
.navbar-toggle-always{
.navbar-toggle;
#media (min-width: 768px){
display: block!important;
background-color: transparent;
border:1px solid #333333;
}
.zero-margins;
.icon-bar-always {
.icon-bar;
border:1px solid #fff;
display: block;
border-radius: 1px;
}
.icon-bar-always + .icon-bar-always {
margin-top: 4px;
}
}
make sure you have at least 768px on the bottom right panel to see it:
http://jsfiddle.net/vyzwfovr/
Why not just add d-block class to toggler?
<button class="navbar-toggler d-block" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
I'm not sure if you want to add another one or is it enough to change the existing one. I case, you want to change the existing one, on a default/clean bootstrap install, this show do it:
.navbar-toggle {
display: block;
}
.navbar-collapse.collapse {
display: none !important;
}
In a normal bootstrap install, there is this line of css found in their generic css file:
.navbar-toggle { display:none; }
In order to get the button to always show, in your custom CSS you just need to add this line of code. If you have your stylesheet applied after theirs, it will overwrite it.
.navbar-toggle { display:block; } // the !important isn't necessary
The colors of the toggle and icon-bar are defined along with navbar-default as well as with navbar-inverse. So if you are trying to display them on a custom div, the colors are also removed along with the navbar-default/inverse color scheme.
Add this to your css:
.navbar-toggle {
background-color: transparent;
}
.icon-bar {
background-color:#333;
}
Add a custom class to your navbar-toggle, like navbar-toggle-visible and then add this rule to your css
#media (min-width: 768px) {
.navbar-toggle-visible {
display: inline;
}