Margin-left on my expanded toggle button using Bootstrap4 - html

I have made a responsive navbar with bootstrap 4. I have aligned it in the center on tablet and mobile view (on the left on desktop).
However, when I expand it, the button takes a margin-left that I can't erase. I have tried margin-left 0px on the nav, many divs and on the button but it doesn't work it always keep the margin-left. I have also tried placing a !important and being more specific with my classes.
I would really appreciate your help.
You can see my whole page here: https://codepen.io/MiaSalazar/pen/GxBgRe
/*menu principal lateral*/
ul .no-list {
padding-bottom: 2px;
}
.menu-principal {
text-align: right;
padding-bottom: 5px;
padding-left: 0px;
font-size: 15px;
list-style-type: none;
-webkit-transition: width 4s; /* Safari */
transition: width 4s;
}
.navbar-dark .navbar-nav .nav-link:hover {
color: #b47068;
}
.navbar-dark .navbar-nav .show > .nav-link,
.navbar-dark .navbar-nav .active > .nav-link,
.navbar-dark .navbar-nav .nav-link.show,
.navbar-dark .navbar-nav .nav-link.active {
color: #b47068;
}
.navbar-dark .navbar-nav .nav-link {
color: #a59391;
}
.nav-menu {
text-decoration: none;
padding-right: 20px;
padding-left: 20px;
padding-top: 5px;
padding-bottom: 5px;
font-family: "Merriweather";
font-weight: 200;
float: right;
border-right: 2px solid #a59391;
line-height: 1.5;
letter-spacing: 1px;
}
.nav-menu-last {
border-right: 0px;
}
nav a:hover {
color: #b47068;
text-decoration: none;
}
.list-inline li {
display: inline;
width: auto;
}
.linea2 {
display: block;
}
.navbar-expand-lg .navbar-nav .nav-link {
padding-right: 1.7rem;
padding-left: 1.5rem;
padding-bottom: 0.5rem;
}
.navbar-toggler {
border-width: 0px;
background-color: #b47068;
}
.navbar-expand-lg .navbar-nav .nav-link:hover {
font-size: 20px;
}
#media screen and (max-width: 991px) {
.nav-menu {
border-right: 0px;
margin: auto;
}
.linea2 {
display: inline;
}
.nav-menu {
padding-top: 10px;
}
.xs-center {
display: flex;
justify-content: center;
padding-top: 20px;
}
.navbar-toggler:focus {
outline: none;
}
.ml-auto,
.mx-auto {
margin-left: 0px;
}
div .navbar-collapse .collapse show {
padding-top: 5px;
}
div nav button .toggle-center{
margin-left: 0px;
}
}
<!--Menu-->
<nav class="navbar navbar-expand-lg menu-principal navbar-toggleable-sm navbar-dark navbar-right d-flex" role="navigation">
<button class="navbar-toggler navbar-toggler-right ml-auto toggle-center " type="button" data-toggle="collapse" data-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">
<ul class="navbar-nav no-list">
<li class="nav-item list-inline ">
<a class="nav-link nav-menu" href="#"><span class="linea1">1</span><span class="linea2"> 1</span> </a> </li>
<!--dropdown-->
<li class="nav-item dropdown list-inline">
<a class="nav-link dropdown-toggle nav-menu" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="linea1">1</span><span class="linea2"> 2</span> </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Cosa 1</a>
<a class="dropdown-item" href="#">Cosa 2</a>
<a class="dropdown-item" href="#">Cosa 3</a>
</div>
</li>
<!--dropdown final-->
<li class="nav-item list-inline ">
<a class="nav-link nav-menu " href="#"><span class="linea1">1</span><span class="linea2"> 3</span> </a> </li>
<li class="nav-item list-inline ">
<a class="nav-link nav-menu nav-menu-last" href="#"><span class="linea1">1</span><span class="linea2"> 4</span> </a> </li>
</ul>
</div>
</nav>
<!--<fin-menu-->
<!--FIN HEADER-->

I checked the issue in codepen. In the mobile view give "margin: 0 auto;" to your button. Your issue will be fixed.

Related

Change the nav-item background color not working

I want to change the background color of the active nav-item and of any nav-item hovered to "chartreuse" (just a color to test).
I've tried love of things but it's not working, why?
Not even using !important.
https://codepen.io/ogonzales/pen/abNQXLg
CSS:
/* NAVBAR TOP */
#top-navbar {
background-color: #1f1f1f;
}
.navbar-nav > .active > a {
color: aqua;
background-color: chartreuse;
}
.nav-item > a:hover {
color: aqua;
}
#navbarCollapse {
margin-left: 1%;
}
#navbarCollapse ul li {
display: inline-block;
}
.nav-link {
margin: 5px;
width: 100px;
}
/* start update */
nav ul {
margin-bottom: 0;
}
.navbar-light .navbar-toggler-icon {
background-image: none;
font-size: 25px;
height: auto;
width: auto;
padding: 3px;
}
#navbarCollapse ul {
padding-top: 10px
}
#navbarCollapse ul li a {
margin: 0;
padding: 5px 10px;
}
nav {
position: relative
}
nav form {
position: absolute;
top: 7px;
right: 15px;
}
Target the active nav-item like this:
.nav-item.active > a{
}
Then you can add css styling into it.
Before you weren't selecting the element properly.
What you desired:
.nav-item.active > a {
color: aqua;
}
.nav-item > a:hover {
background-color: chartreuse;
}
See codepen: https://codepen.io/koder613/pen/ZEWNEgw?editors=1100
To change the background color of the active nav-item. Call the navbar-nav class as it is in your ul tag as shown.
<div class="collapse navbar" id="navbarCollapse">
<!-- Call the navbar-nav class in the ul tag -->
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/">Inicio</a>
</li>
<li class="nav-item">
<a href="/iglesias/" class="nav-link" >Iglesias</a>
</li>
<li class="nav-item">
<a href="/doctrina/" class="nav-link" >Doctrina</a>
</li>
</ul>
</div>
And the following will show the "chartreuse" color when you hover over the nav-items.
.nav-item > a:hover { color: aqua; background-color: chartreuse; }
I added active class on your second li to show how it looks like.
But more or less you should set your changing color in active class like:
.active{
background-color: red;
}
.active:hover > a{
color: yellow !important;
}
Like this both color will change when mouse is going hover your li with active class. And You add important where you want to make it stronger.
Pretty much duplicate of: Changing the color of active nav-item
$(document).ready(function() {
"use strict";
$('ul > li').click(function(e) {
e.preventDefault();
$('ul > li').removeClass('active');
$(this).addClass('active');
});
});
/* NAVBAR TOP */
#top-navbar {
background-color: #1f1f1f;
}
.navbar-nav > .active > a {
color: aqua;
background-color: chartreuse;
}
.active{
background-color: red;
}
.nav-item.active:hover > a{
color: yellow !important;
}
.nav-item > a:hover {
color: aqua;
}
#navbarCollapse {
margin-left: 1%;
}
#navbarCollapse ul li {
display: inline-block;
}
.nav-link {
margin: 5px;
width: 100px;
}
/* start update */
nav ul {
margin-bottom: 0;
}
.navbar-light .navbar-toggler-icon {
background-image: none;
font-size: 25px;
height: auto;
width: auto;
padding: 3px;
}
#navbarCollapse ul {
padding-top: 10px
}
#navbarCollapse ul li a {
margin: 0;
padding: 5px 10px;
}
nav {
position: relative
}
nav form {
position: absolute;
top: 7px;
right: 15px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header>
<!--MENU SUPERIOR-->
<!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-light fixed-top" id="top-navbar">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<!-- <span class="navbar-toggler-icon"><i class="fas fa-bars"></i></span> -->
<span class="navbar-toggler-icon">
<i class="fas fa-bars" style="color:#fff; font-size:28px;"></i>
</span>
</button>
<a class="navbar-brand mr-auto mt-0" href="/"><img src="/static/img/logos/elim-palmera-la-central-fondo-blanco.png" width="25px"
height="30px"></a>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul>
<li class="nav-item">
<a class="nav-link" href="/">Inicio</a>
</li>
<li class="nav-item active">
<a href="/iglesias/" class="nav-link" >Iglesias</a>
</li>
<li class="nav-item">
<a href="/doctrina/" class="nav-link" >Doctrina</a>
</li>
</ul>
</div>
<form class="form-inline ml-auto mt-3">
<span class="text-white">Hola, ogonzales.</span>
Salir
</form>
</div>
</nav>
</header>

Dropwdown arrow over text in navbar

I'm trying to have a dropdown on a navbar item. It works, but the arrow is over the text of the menu item.
Codepen:
https://codepen.io/ogonzales/pen/QWjmorP
Code
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark" style="height: 70px;">
<a class="navbar-brand" href="#">Fixed navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
More
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/support/">Support and Consulting</a>
<a class="dropdown-item" href="/test-driven-development/">What is Test-Driven Development?</a>
<a class="dropdown-item" href="/testimonials/">Testimonials</a>
</div>
</li>
</ul>
<form class="form-inline ml-auto">
Log in
Sign up
</form>
</div>
</nav>
Bonus
I'd like also to put every navbar item more to the right. I know I can do this with CSS, but is there a Boostrap class am I missing?
You ul tag was not closed, I fixed that and answered your bonus question as well.
The reason it was on the over the text because, both the dropdown and the link were within same block, so you have to specify the width for those to fit-in inline, I have just provided 100px under .nav-link{...} and you are free to change that as per you requirement.
To move contents towards right you can have width property for the yellow block(check in my snipppet/fiddle) OR you can provide flex option for the block and use 'justify-content:space-between;`.
View in full screen due to media-query you have used.
.nav-link{
border:1px solid yellow;
margin:5px;
width:100px;
}
fiddle to playground.
$(document).ready(function() {
$('#sidebarCollapse').on('click', function() {
$('#sidebar').toggleClass('active');
});
});
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
font-size: 14px;
}
#media (min-width: 768px) {
html {
font-size: 16px;
}
}
body {
margin-bottom: 60px;
/* Margin bottom by footer height */
font-family: 'Poppins', sans-serif;
background: #fafafa;
padding-top: 70px;
}
.container {
max-width: 960px;
}
.pricing-header {
max-width: 700px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
/* Set the fixed height of the footer here */
line-height: 60px;
/* Vertically center the text there */
background-color: #f5f5f5;
}
/* NAVBAR TOP */
#top-navbar ul li.active>a a[aria-expanded="true"] {
color: #1f1f1f;
background: #12b556;
}
#top-navbar a:visited {
color: #fff;
}
#top-navbar a:link {
color: #fff;
}
#top-navbar a.subitem:link {
color: #1f1f1f;
}
/* ==== */
/* SIDEBAR */
/* ---------------------------------------------------
SIDEBAR STYLE
----------------------------------------------------- */
.wrapper {
display: flex;
align-items: stretch;
}
#sidebar {
min-width: 250px;
max-width: 250px;
background: #1f1f1f;
color: #fff;
transition: all 0.3s;
}
#sidebar.active {
min-width: 80px;
max-width: 80px;
text-align: center;
}
#sidebar.active .sidebar-header h3,
#sidebar.active .CTAs {
display: none;
}
#sidebar.active .sidebar-header strong {
display: block;
}
#sidebar ul li a {
text-align: left;
}
#sidebar.active ul li a {
padding: 20px 10px;
text-align: center;
font-size: 0.85em;
}
#sidebar.active ul li a i {
margin-right: 0;
display: block;
font-size: 1.8em;
margin-bottom: 5px;
}
#sidebar.active ul ul a {
padding: 10px !important;
}
#sidebar.active .dropdown-toggle::after {
top: auto;
bottom: 10px;
right: 50%;
-webkit-transform: translateX(50%);
-ms-transform: translateX(50%);
transform: translateX(50%);
}
#sidebar .sidebar-header {
padding: 20px;
background: #1f1f1f;
}
#sidebar .sidebar-header strong {
display: none;
font-size: 1.8em;
}
#sidebar ul.components {
padding: 20px 0;
border-bottom: 1px solid #47748b;
}
#sidebar ul li a {
padding: 10px;
font-size: 1.1em;
display: block;
}
#sidebar ul li a:hover {
color: #12b556;
background: #fff;
}
#sidebar ul li a i {
margin-right: 10px;
}
#sidebar ul li.active>a.sidebar-link a[aria-expanded="true"] {
color: #fff;
background: #12b556;
}
a[data-toggle="collapse"] {
position: relative;
}
#navbarCollapse {
border: 1px solid red;
}
.nav-link {
border: 1px solid yellow;
margin: 5px;
width: 100px;
}
.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: #12b556;
}
ul.CTAs {
padding: 20px;
}
ul.CTAs a {
text-align: center;
font-size: 0.9em !important;
display: block;
border-radius: 5px;
margin-bottom: 5px;
}
a.download {
background: #fff;
color: #12b556;
}
a.article,
a.article:hover {
background: #12b556 !important;
color: #fff !important;
}
a.sidebar-link:visited {
color: #fff;
}
a.sidebar-link:link {
color: #fff;
}
/* ---------------------------------------------------
CONTENT STYLE
----------------------------------------------------- */
#content {
width: 100%;
padding: 20px;
min-height: 100vh;
transition: all 0.3s;
}
/* ---------------------------------------------------
MEDIAQUERIES
----------------------------------------------------- */
#media (max-width: 768px) {
#sidebar {
min-width: 80px;
max-width: 80px;
text-align: center;
margin-left: -80px !important;
}
.dropdown-toggle::after {
top: auto;
bottom: 10px;
right: 50%;
-webkit-transform: translateX(50%);
-ms-transform: translateX(50%);
transform: translateX(50%);
}
#sidebar.active {
margin-left: 0 !important;
}
#sidebar .sidebar-header h3,
#sidebar .CTAs {
display: none;
}
#sidebar .sidebar-header strong {
display: block;
}
#sidebar ul li a {
padding: 20px 10px;
}
#sidebar ul li a span {
font-size: 0.85em;
}
#sidebar ul li a i {
margin-right: 0;
display: block;
}
#sidebar ul ul a {
padding: 10px !important;
}
#sidebar ul li a i {
font-size: 1.3em;
}
#sidebar {
margin-left: 0;
}
#sidebarCollapse span {
display: none;
}
}
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<title>{% block title %}DjangoX{% endblock title %}</title>
<meta name="description" content="A framework for launching new Django projects quickly.">
<meta name="author" content="">
<link rel="shortcut icon" type="image/x-icon" href="{% static 'images/favicon.ico' %}">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link href="https://use.fontawesome.com/releases/v5.12.0/css/all.css" rel="stylesheet">
<link rel="stylesheet" href="{% static 'css/base.css' %}">
<link rel="stylesheet" href="{% static 'css/price.css' %}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#sidebarCollapse').on('click', function() {
$('#sidebar').toggleClass('active');
});
});
</script>
</head>
<body>
<!--MENU SUPERIOR-->
<!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark" style="height: 70px;">
<a class="navbar-brand" href="#">Fixed navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
More
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/support/">Support and Consulting</a>
<a class="dropdown-item" href="/test-driven-development/">What is Test-Driven Development?</a>
<a class="dropdown-item" href="/testimonials/">Testimonials</a>
</div>
</li>
</ul>
<form class="form-inline ml-auto">
Log in
Sign up
</form>
</div>
</nav>
<!-- FIN MENU SUPERIOR-->
<div class="wrapper">
<!-- Sidebar -->
<nav id="sidebar">
<div class="sidebar-header">
<img src="static\images\elim-logo.png" alt="Ministerios Elim" width="50%" height="50%">
<strong>ELIM</strong>
</div>
<ul class="list-unstyled components">
<li class="">
<a class="sidebar-link" href="#capitulo1" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">
<i class="fas fa-home"></i> Capítulo 1
</a>
<ul class="collapse list-unstyled" id="capitulo1">
<li>
<a class="sidebar-link" href="#">Introducción</a>
</li>
<li>
<a class="sidebar-link" href="#">¿Qué es la salvación?</a>
</li>
<li>
<a class="sidebar-link" href="#">¿Se pierde la salvación?</a>
</li>
</ul>
</li>
</ul>
</nav>
<!-- Page Content -->
<div id="content">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<button type="button" id="sidebarCollapse" class="btn btn-info">
<i class="fas fa-align-left"></i>
<span>Toggle Sidebar</span>
</button>
</div>
</nav>
<hr><br>
<main role="main" class="container">
<div class="row">
<div class="col-md-8">
{% block content %} {% endblock content %}
</div>
<div class="col-md-4 float-right" id="LocalSide">
<form class="search-form" action="/search/" method="post">
<input type="hidden" name="csrfmiddlewaretoken" value="KTlYgVaxnAYKzLle9WWDNIoE0MDSvAVldfbsnKbfpAStWafCb1MVMgwLdArZUEiP">
<div class="form-group">
<input type="search" class="form-control search-course" placeholder="Buscar curso" name="search_term" required="">
<input type="hidden" value="3" name="course_id">
</div>
</form>
<h2 class="local-side-heading">In this Section:</h2>
<nav class="local-nav">
<ol data-local-nav-list=""></ol>
</nav>
<a class="pcta" href="/payments/tdd-flask/" data-a-buy-course-cta="tdd-flask">
<span class="label label-success">
<span class="pcta-label">Get the</span>
<span class="pcta-hook">full course</span>
<span class="sr-only">for</span>
<span class="pcta-badge" aria-hidden="true">Now Only</span>
</span>
<span class="pcta-price">$30</span>
</a>
↑ Back to top
</div>
</div>
</main>
<footer class="footer">
<div class="container">
<span class="text-muted">Footer...</span>
</div>
</footer>
</div>
</div>
In your code ".dropdown-toggle::after" right value is the problem, change into this code it will work.
.dropdown-toggle::after {
display: block;
position: absolute;
top: 50%;
right: -7px;
transform: translateY(-50%);
}
Just remove the below manual css u have designed. bcz it is overriding bootstrap's default css which is not appropiate
.dropdown-toggle::after {
display: block;
position: absolute;
top: 50%;
right: 20px;
transform: translateY(-50%);
}

How to hover splitted button in Bootstrap 4 navbar

For a Bootstrap 4 website I've made a navbar with splitted dropdown buttons. The leftside of the dropdown button is a normal link and the rightside is a caret button to show the submenu.
For some reason I cannot find a working CSS way to have the hover effect only on the rightside (caret) and not on the leftside (link). Is there a CSS way (without Javascript) to do this?
Thanx in advance.
You'll find the jsfiddle on https://jsfiddle.net/bnsthp57/
Update
The hover is working! The updated snippet below is ready to use. Tested on Internet Explorer 11, Crhome 79, Opera 66, Edge 44, and Firefox 72.
#topnav .navbar-nav {
font-size: 0rem;
}
#topnav .nav-link {
display: inline-block;
padding: 0.625rem 1rem;
font-size: 1rem;
}
#topnav .dropdown-link {
padding: 0.625rem 0.25rem;
}
#topnav .dropdown-toggle {
padding-left: 0.25rem;
}
#media (max-width: 767.98px) {
#topnav .navbar-nav {
padding-top: 0.5rem;
}
#topnav .nav-link:first-child,
#topnav .dropdown-link {
display: block;
width: calc(100% - 50px);
padding: 0.625rem 1rem;
border-right: 1px solid #88d;
}
#topnav .dropdown-toggle {
display: block;
width: 50px;
padding: 0.625rem 0.5rem;
position: absolute;
top:0; right:0;
text-align: center;
}
}
#media (min-width: 768px) {
#topnav .nav-link {
border-right: 1px solid rgba(0, 0, 0, 0.1);
}
#topnav .dropdown-link,
#topnav .nav-item:last-child a.nav-link {
border-right: 0;
}
#topnav .dropdown-menu {
margin-top: 0;
}
#topnav .dropdown-toggle:hover + .dropdown-menu,
#topnav .dropdown-menu:hover {
display: block; /* open submenu on hover */
}
#topnav .dropdown-menu:not(:hover) {
display: none; /* close submenu on not hover */
}
}
/* navbar theme */
#navbar,
#navbar .navbar-toggler {
color: #fff;
background-color: #1c8cbc;
border-color: #1f90bb #1f90bb #145e7a;
}
#navbar .navbar-toggler-icon {
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3e%3cpath stroke='rgba(255, 255, 255, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
#topnav .nav-link {
color: #fff;
background-color: transparent;
font-weight: 600;
}
#topnav .nav-link:hover {
background-color: rgba(0, 0, 0, 0.1);
}
#topnav .dropdown-menu,
#topnav .dropdown-item,
#topnav .dropdown-item:focus {
color: #fff;
background-color: #0c7cac;
}
#topnav .dropdown-item.active {
color: #ff6;
background-color: #0c7cac;
font-weight: 600;
}
#topnav .dropdown-item:hover,
#topnav .dropdown-item:active {
color: #fff;
background-color: #1383af;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<nav id="navbar" class="navbar navbar-expand-md mr-auto">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#topnav" aria-controls="topnav" aria-expanded="false"
aria-label="Toggle menu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="topnav">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#pagelink">Home</a>
</li>
<li class="nav-item dropdown active">
<a class="nav-link dropdown-link" href="#pagelink">Magazine</a>
<a class="nav-link dropdown-toggle" href="#" id="navlink01" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></a>
<div class="dropdown-menu" aria-labelledby="navlink01">
<a class="dropdown-item" href="#pagelink">Sub item 1</a>
<a class="dropdown-item active" href="#pagelink">Sub item 2</a>
<a class="dropdown-item" href="#pagelink">Sub item 3</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="index.php">Portfolio</a>
</li>
</ul>
</div>
</div>
</nav>
Navbar with splitted dropdown buttons
.dropdown-toggle:hover + .dropdown-menu{
display:block;
}
With this css it will work
#media (min-width: 768px) {
#topnav .dropdown-toggle:hover + .dropdown-menu,
#topnav .dropdown-menu:hover {
display: block;
}
#topnav .dropdown-menu:not(:hover) {
display: none;
}
}
on this dropdown nav-item
<li class="nav-item dropdown active">
<a class="nav-link dropdown-link" href="#pagelink">Magazine</a>
<a class="nav-link dropdown-toggle" href="#" id="navlink01" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></a>
<div class="dropdown-menu" aria-labelledby="navlink01">
<a class="dropdown-item" href="#pagelink">Sub item 1</a>
<a class="dropdown-item active" href="#pagelink">Sub item 2</a>
<a class="dropdown-item" href="#pagelink">Sub item 3</a>
</div>
</li>

How to add dropdown below the navbar in bootstrap 3.3.7

So I am trying to make my dropdown actually appear below the navbar like in the shown picture
Here is my html:`
<div class="container">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed"
data-toggle="collapse" data-target="#myNavbar">
<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 logo" href="#"></a>
</div>
<div class="collapse navbar-collapse navbar-right" id="myNavbar">
<ul class="nav navbar-nav">
<li class="dropdown"><a href="#" class="dropdown-toggle"
data-toggle="dropdown" role="button" aria-expanded="false">blah
<!-- <span class="caret"></span> -->
</a>
<ul class="dropdown-menu" role="menu">
<li>blah1</li>
<li>blah 2</li>
<li>blah 3</li>
</ul></li>
<li>blah</li>
<li class="dropdown"><a href="#" class="dropdown-toggle"
data-toggle="dropdown" role="button" aria-expanded="false">blah
</a>
<ul class="dropdown-menu" role="menu">
<li>blah</li>
<li>blah & blah</li>
<li>blah</li>
</ul></li>
<li> blah</li>
<li>blah</li>
<li><img src="../images/search.png"/></li>
<li>Login</li>
</ul>
</div>
</div>
</nav>
</div>
Here is my css:
.icon--house, .modal button, article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block
}
.navbar-default {
background-color: #030303 !important;
border: #030303;
}
.nav > li > a {
padding: 25px 20px;
font-size: 16px;
}
/* bigger menu items in dropdown */
.dropdown-menu > li > a {
padding: 20px;
}
/* removes whitespace in dropdown from navbar */
.dropdown-menu {
padding: 0;
float: right;
left: 50% !important;
right: auto !important;
text-align: center !important;
transform: translate(-50%, 0) !important;
}
.dropdown:hover .dropdown-menu {
display: block;
}
.dropdown-menu>li>a:hover {
color: #FFF;
background-color: #da1a32;
text-decoration: none;
}
.navbar .navbar-nav > li > a {
color: #FFF !important;
border-bottom: transparent solid 3px;
padding-bottom: 5px;
}
.navbar .navbar-nav > li > a:hover {
border-bottom: #da1a32 solid 3px;
}
a:link {
text-decoration: none;
color: #FFF !important;
}
a:visited {
text-decoration: none;
color: #FFF;
}
a:hover {
text-decoration: none;
color: #FFF;
}
a:active {
text-decoration: none;
color: #FFF;
}
.align-center, .missing {
text-align: center
}
body {
font-family: Montserrat, sans-serif;
font-weight: 300;
line-height: 1.4;
color: #202020;
overflow-x: hidden
}
img {
max-width: 100%;
height: auto
}
a {
transition: .3s ease;
text-decoration: none
}
h1 {
font-size: 30px;
line-height: 1.1;
margin-bottom: .5em
}
this is what I want it to appear like:
And this is what It looks like overlapping the actual navbar:
I've tried some different things such as adding a margin to the bottom of my header but it did not help. If anyone could help it would be greatly appreciated, as I'm not sure where to go from here. If you could also tell me exactly what css it was that needed to be change that would be great. Thanks.
You just need to adjust the 'top' value on the .dropdown-menu class, which is absolute positioned. probably at 100% now
.dropdown-menu {
top: 100%;
}
this will make it line up with the bottom of the li.dropdown > a element,
so if you have 20 extra px of black background from navbar padding, try this:
.dropdown-menu {
top: calc(100% + 20px);
}

nav-bar link's color is not working in bootstrap

I am trying to change link color on nav-bar but after the changing it seems the same. What is wrong? Why its not working? Here is the code:
<nav class="navbar navbar-expand-lg navbar-dark bg-primary fixed-top" id="sideNav">
<a class="navbar-brand" href="#page-top">
<span class="d-block d-lg-none">Start Bootstrap</span>
<span class="d-none d-lg-block">
<img class="img-fluid img-profile rounded-circle mx-auto mb-2" src="img/profile.jpg" alt="">
</span>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#experience">Experience</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#education">Education</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#skills">Skills</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#interests">Interests</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#awards">Awards</a>
</li>
</ul>
</div>
</nav>
CSS
.bg-primary {
background-color: #BD5D38 !important;
}
,
.nav-link {
color: #222222 !important;
}
.nav-link:hover,
.nav-link:focus,
.nav-link:active {
color: #ffffff;
}
#sideNav .navbar-nav .nav-item .nav-link {
font-weight: 600;
text-transform: uppercase;
}
#media (min-width: 992px) {
#sideNav {
text-align: center;
position: fixed;
top: 0;
left: 0;
display: flex;
flex-direction: column;
width: 17rem;
height: 100vh;
}
#sideNav .navbar-brand {
display: flex;
margin: auto auto 0;
padding: 0.5rem;
}
#sideNav .navbar-brand .img-profile {
max-width: 10rem;
max-height: 10rem;
border: 0.5rem solid rgba(255, 255, 255, 0.2);
}
#sideNav .navbar-collapse {
display: flex;
align-items: flex-start;
flex-grow: 0;
width: 100%;
margin-bottom: auto;
}
#sideNav .navbar-collapse .navbar-nav {
flex-direction: column;
width: 100%;
}
#sideNav .navbar-collapse .navbar-nav .nav-item {
display: block;
}
#sideNav .navbar-collapse .navbar-nav .nav-item .nav-link {
display: block;
}
}
I changed it on the .nav-link class but it's not working. While nav-link lass is inside tag. I don't want to use tags for defining hover and link colors because on my site other links will have other colors while only nav-links must have this color. That is why I am trying to use nav-link class for it. How can I make it worked?
Thanks in advance!
I think you have an unneeded comma after closing .bg-primary in your css. Right now it looks like:
.bg-primary {
background-color: #BD5D38 !important; },
Remove the comma at the end so it should be:
.bg-primary {
background-color: #BD5D38 !important; }
I think the comma is messing with the following lines of code. And the important in your color css is preventing the hover, focus and active states to work.
Here is how the top part of your css should look:
.bg-primary {
background-color: #BD5D38 !important; }
.nav-link {
color: #222222;
}
.nav-link:hover, .nav-link:focus, .nav-link:active {color:#ffffff}
Also if you are linking to the new beta version of bootstrap 4 you need to be more specific and add the .navbar-dark .navbar-nav so it would look like:
.bg-primary {
background-color: #BD5D38 !important;
}
.navbar-dark .navbar-nav .nav-link {
color: #222222;
}
.navbar-dark .navbar-nav .nav-link:hover,
.navbar-dark .navbar-nav .nav-link:focus,
.navbar-dark .navbar-nav .nav-link:active {
color:#ffffff
}