Vertical center items in Bootstrap 4 - html

How can I align text to the middle in a dropdown menu navbar?
I have this:
I already try to follow snippets but I don't have success.
<ul class="navbar-nav ml-auto">
<li ngbDropdown class="nav-item dropdown">
<a ngbDropdownToggle class="nav-link dropdown-toggle" [routerLink]="" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span>menu</span>
<div ngbDropdownMenu class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item">OPTION 1</a>
<hr class="menu-item--division">
<a class="dropdown-item">OPTON 2</a>
<hr class="menu-item--division">
<a class="dropdown-item">OPTION 3</a>
<hr class="menu-item--division">
<a class="dropdown-item">OPTION 4</a>
<hr class="menu-item--division">
<a class="dropdown-item">OPTON 5</a>
</div>
</li>
</ul>
This is my actual code
https://codeply.com/p/zNU5s3kyQl

Use below CSS in your dropdown-item or add d-flex justify-content-center align-items-center classes in each dropdown-item.
.dropdown-item {
display: flex;
justify-content: center;
align-items: center;
}
.dropdown-menu hr {
margin-top: 0;
margin-bottom: 0;
border: 0;
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
.dropdown-menu a {
height: 53px;
}
.dropdown-item {
text-align: center;
}
.dropdown-item:hover,
.dropdown-item:focus {
color: #16181b;
text-decoration: none;
background-color: #F3F3F3;
text-align: center;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<ul class="navbar-nav ml-auto">
<li ngbDropdown class="nav-item dropdown">
<a ngbDropdownToggle class="nav-link dropdown-toggle" [routerLink]="" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span>menu</span>
<div ngbDropdownMenu class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item d-flex justify-content-center align-items-center">OPTION 1</a>
<hr class="menu-item--division">
<a class="dropdown-item d-flex justify-content-center align-items-center">OPTON 2</a>
<hr class="menu-item--division">
<a class="dropdown-item d-flex justify-content-center align-items-center">OPTION 3</a>
<hr class="menu-item--division">
<a class="dropdown-item d-flex justify-content-center align-items-center">OPTION 4</a>
<hr class="menu-item--division">
<a class="dropdown-item d-flex justify-content-center align-items-center">OPTON 5</a>
</div>
</a>
</li>
</ul>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

Related

Bootstrap - Image not covering inteire width of container

im starting a project using bootstrap and i've been having a little bit of trouble trying to figure out a way to make this image cover the inteire width of my container
any ideias??
appreciate the help!!!
here's my code
hey guys,
im starting a project using bootstrap and i've been having a little bit of trouble trying to figure out a way to make this image cover the inteire width of my container
any ideias??
appreciate the help!!!
here's my code
:root {
--DarkerGray: #1b1d1d;
--Gray: #3F4545;
--MediumGray: #464a4a;
--DarkBlue: #123B79;
--LightBlue: #18A5A7;
--LightGray: #D9D9D9;
--LighterGray: #eceaea;
--White: white;
--OrangeSelect: rgb(255, 166, 0);
}
html, body {
user-select: none;
}
.navbar {
background-color: var(--DarkBlue);
}
.nav-item {
cursor: pointer;
font-weight: 550;
}
.dropdown-item {
cursor: pointer;
font-weight: 550;
}
.dropdown-item:hover {
background-color: var(--OrangeSelect);
}
#containerIMG {
width: 100%;
height: 500px;
object-fit: cover;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<body>
<nav class="navbar navbar-expand-lg navbar-dark ">
<a class="navbar-brand" href="#">
<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 mr-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle text-white" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
CARDÁPIO
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#"> PRATOS </a>
<a class="dropdown-item" href="#"> LANCHES </a>
<a class="dropdown-item" href="#"> SOPAS </a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle text-white" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
BEBIDAS
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#"> ÁGUAS </a>
<a class="dropdown-item" href="#"> SUCOS </a>
<a class="dropdown-item" href="#"> REFRIGERANTES </a>
<a class="dropdown-item" href="#"> CERVEJAS </a>
<a class="dropdown-item" href="#"> VINHOS </a>
<a class="dropdown-item" href="#"> APERITIVOS </a>
<a class="dropdown-item" href="#"> DRINKS </a>
</li>
<li class="nav-item">
<a class="nav-link text-white">RESERVAR MESA <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link text-white"> PESQUISAR </a>
</li>
<li class="nav-item">
<a class="nav-link text-white"> MINHA CONTA </a>
</li>
<li class="nav-item">
<a class="nav-link text-white"> MEUS PEDIDOS</a>
</li>
</ul>
</div>
</nav>
<div class="container-fluid bg-dark">
<img src="https://t.ctcdn.com.br/essK16aBUDd_65hp5umT3aMn_i8=/400x400/smart/filters:format(webp)/i606944.png" id="containerIMG">
</div>
</body>
You have to delete the padding of the .container-fluid class, you can add p-0 to the class in your HTML
:root {
--DarkerGray: #1b1d1d;
--Gray: #3F4545;
--MediumGray: #464a4a;
--DarkBlue: #123B79;
--LightBlue: #18A5A7;
--LightGray: #D9D9D9;
--LighterGray: #eceaea;
--White: white;
--OrangeSelect: rgb(255, 166, 0);
}
html, body {
user-select: none;
}
.navbar {
background-color: var(--DarkBlue);
}
.nav-item {
cursor: pointer;
font-weight: 550;
}
.dropdown-item {
cursor: pointer;
font-weight: 550;
}
.dropdown-item:hover {
background-color: var(--OrangeSelect);
}
#containerIMG {
width: 100%;
height: 500px;
object-fit: cover;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<body>
<nav class="navbar navbar-expand-lg navbar-dark ">
<a class="navbar-brand" href="#">
<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 mr-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle text-white" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
CARDÁPIO
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#"> PRATOS </a>
<a class="dropdown-item" href="#"> LANCHES </a>
<a class="dropdown-item" href="#"> SOPAS </a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle text-white" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
BEBIDAS
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#"> ÁGUAS </a>
<a class="dropdown-item" href="#"> SUCOS </a>
<a class="dropdown-item" href="#"> REFRIGERANTES </a>
<a class="dropdown-item" href="#"> CERVEJAS </a>
<a class="dropdown-item" href="#"> VINHOS </a>
<a class="dropdown-item" href="#"> APERITIVOS </a>
<a class="dropdown-item" href="#"> DRINKS </a>
</li>
<li class="nav-item">
<a class="nav-link text-white">RESERVAR MESA <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link text-white"> PESQUISAR </a>
</li>
<li class="nav-item">
<a class="nav-link text-white"> MINHA CONTA </a>
</li>
<li class="nav-item">
<a class="nav-link text-white"> MEUS PEDIDOS</a>
</li>
</ul>
</div>
</nav>
<div class="container-fluid p-0 bg-dark">
<img src="https://t.ctcdn.com.br/essK16aBUDd_65hp5umT3aMn_i8=/400x400/smart/filters:format(webp)/i606944.png" id="containerIMG">
</div
</body>

How to make whole <li> clickable as a link

I have navigation menu that contains links,
what I want to achieve is to make the whole li element clickable as a link.
so how to achieve that please?
I'm using bootstrap 3.2 library.
below is the HTML and CSS code.
User wants to able to click on the Link from anywhere inside the li html element
.navbar {
position: relative;
min-height: 40px !important;
margin-bottom: 20px;
border: none !important;
}
#navbarSupportedContent .nav-item {
text-transform: uppercase;
text-align: center;
font-weight: 800;
border-right: 1px solid #01154D;
padding: 10px 24px;
}
#navbarSupportedContent .nav-item:hover {
background-color: #DBDDFD;
color: #000 !important;
}
<div role="navigation">
<div class="container">
<div id="undefined-sticky-wrapper" class="sticky-wrapper" style="height: 42px;"><nav class="navbar navbar-expand-lg navbar-dark bg-primary sticky-top">
<div class="collapse navbar-collapse justify-content-center" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto" style="float:inherit;">
<li class="nav-item active">
<a class="nav-link" href="/webcenter/portal/dummy/pages_en">
<span id="submenu1">Home</span>
</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="/webcenter/portal/dummy/pages_employeetools">
<span id="submenu1">Employee Tools</span>
</a>
</li>
<li class="nav-item ">
<div class="dropdown show">
<a style="color:#e6ecf2;" aria-expanded="false" aria-haspopup="true" class="dropdown-toggle" data-toggle="dropdown" href="#" id="dropdownMenuLink" role="button">MEDIA CENTER</a>
<div aria-labelledby="dropdownMenuLink" class="dropdown-menu">
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/photogallery">PHOTO GALLERY</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/news1">NEWS</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/newpage">dummy MAGAZINE</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/ashurtiassagheer">dummy</a>
</div>
</div>
</li>
<li class="nav-item ">
<a class="nav-link" href="/webcenter/portal/dummy/pages_documents">
<span id="submenu1">Documents</span>
</a>
</li>
<li class="nav-item"><a data-afr-tlen="7" id="T:arabic2" class="nav-link xej" style="font-size: initial;" onclick="this.focus();return false;" data-afr-fcs="true" href="#"><span style="">العربية</span>
<i aria-hidden="true" class="fa fa-language"></i></a>
</li>
<li class="nav-item" style="margin-left: auto;"><span id="T:wcLogoutLink:spacesActionPGL" class="x1a"><a data-afr-tlen="0" id="T:wcLogoutLink:logoutLink" title="Log out of WebCenter Portal" class="nav-link glyphicon glyphicon-log-out xf0 p_AFTextOnly" style="" onclick="this.focus();return false;" data-afr-fcs="true" href="#"></a></span>
</li>
</ul><span id="T:search2" class="x1a">
<div class="navbar-form navbar-left visible-xs" id="searchxs"><div id="T:searchbox2" class="x131" aria-live="polite"><div style="display:none"><a id="T:searchbox2:_afrCommandDelegate" class="xej" onclick="this.focus();return false;" data-afr-fcs="true" href="#"></a></div></div>
</div></span>
</div>
</nav></div>
</div>
</div>
Remove li padding and add width 100% and padding to a tag
li.nav-item > a, li.nav-item > .dropdown show a{
display: block;
width: 100%;
}
.navbar {
position: relative;
min-height: 40px !important;
margin-bottom: 20px;
border: none !important;
}
li.nav-item a{ padding: 10px 0px;}
#navbarSupportedContent .nav-item {
text-transform: uppercase;
text-align: center;
font-weight: 800;
border-right: 1px solid #01154D;
padding: 0px 24px;
}
#navbarSupportedContent .nav-item:hover {
background-color: #DBDDFD;
color: #000 !important;
}
<div role="navigation">
<div class="container">
<div id="undefined-sticky-wrapper" class="sticky-wrapper" style="height: 42px;"><nav class="navbar navbar-expand-lg navbar-dark bg-primary sticky-top">
<div class="collapse navbar-collapse justify-content-center" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto" style="float:inherit;">
<li class="nav-item active">
<a class="nav-link" href="/webcenter/portal/dummy/pages_en">
<span id="submenu1">Home</span>
</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="/webcenter/portal/dummy/pages_employeetools">
<span id="submenu1">Employee Tools</span>
</a>
</li>
<li class="nav-item ">
<div class="dropdown show">
<a style="color:#e6ecf2;" aria-expanded="false" aria-haspopup="true" class="dropdown-toggle" data-toggle="dropdown" href="#" id="dropdownMenuLink" role="button">MEDIA CENTER</a>
<div aria-labelledby="dropdownMenuLink" class="dropdown-menu">
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/photogallery">PHOTO GALLERY</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/news1">NEWS</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/newpage">dummy MAGAZINE</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/ashurtiassagheer">dummy</a>
</div>
</div>
</li>
<li class="nav-item ">
<a class="nav-link" href="/webcenter/portal/dummy/pages_documents">
<span id="submenu1">Documents</span>
</a>
</li>
<li class="nav-item"><a data-afr-tlen="7" id="T:arabic2" class="nav-link xej" style="font-size: initial;" onclick="this.focus();return false;" data-afr-fcs="true" href="#"><span style="">العربية</span>
<i aria-hidden="true" class="fa fa-language"></i></a>
</li>
<li class="nav-item" style="margin-left: auto;"><span id="T:wcLogoutLink:spacesActionPGL" class="x1a"><a data-afr-tlen="0" id="T:wcLogoutLink:logoutLink" title="Log out of WebCenter Portal" class="nav-link glyphicon glyphicon-log-out xf0 p_AFTextOnly" style="" onclick="this.focus();return false;" data-afr-fcs="true" href="#"></a></span>
</li>
</ul><span id="T:search2" class="x1a">
<div class="navbar-form navbar-left visible-xs" id="searchxs"><div id="T:searchbox2" class="x131" aria-live="polite"><div style="display:none"><a id="T:searchbox2:_afrCommandDelegate" class="xej" onclick="this.focus();return false;" data-afr-fcs="true" href="#"></a></div></div>
</div></span>
</div>
</nav></div>
</div>
</div>
Do not render the <li> big, but the <a>. The anchor element already has all the bindings necessary to provide an accessible and very usable link. Rendering it bigger improves usability.
.navbar {
position: relative;
min-height: 40px !important;
margin-bottom: 20px;
border: none !important;
}
#navbarSupportedContent .nav-item {
text-transform: uppercase;
text-align: center;
font-weight: 800;
}
#navbarSupportedContent .nav-link {
display: block;
border-right: 1px solid #01154D;
padding: 10px 24px;
}
#navbarSupportedContent .nav-link:hover {
background-color: #DBDDFD;
color: #000 !important;
}
<div role="navigation">
<div class="container">
<div id="undefined-sticky-wrapper" class="sticky-wrapper" style="height: 42px;">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary sticky-top">
<div class="collapse navbar-collapse justify-content-center" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto" style="float:inherit;">
<li class="nav-item active">
<a class="nav-link" href="/webcenter/portal/dummy/pages_en">
<span id="submenu1">Home</span>
</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="/webcenter/portal/dummy/pages_employeetools">
<span id="submenu1">Employee Tools</span>
</a>
</li>
<li class="nav-item ">
<div class="dropdown show">
<a style="color:#e6ecf2;" aria-expanded="false" aria-haspopup="true" class="dropdown-toggle" data-toggle="dropdown" href="#" id="dropdownMenuLink" role="button">MEDIA CENTER</a>
<div aria-labelledby="dropdownMenuLink" class="dropdown-menu">
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/photogallery">PHOTO GALLERY</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/news1">NEWS</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/newpage">dummy MAGAZINE</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/ashurtiassagheer">dummy</a>
</div>
</div>
</li>
<li class="nav-item ">
<a class="nav-link" href="/webcenter/portal/dummy/pages_documents">
<span id="submenu1">Documents</span>
</a>
</li>
<li class="nav-item"><a data-afr-tlen="7" id="T:arabic2" class="nav-link xej" style="font-size: initial;" onclick="this.focus();return false;" data-afr-fcs="true" href="#"><span style="">العربية</span>
<i aria-hidden="true" class="fa fa-language"></i></a>
</li>
<li class="nav-item" style="margin-left: auto;"><span id="T:wcLogoutLink:spacesActionPGL" class="x1a"><a data-afr-tlen="0" id="T:wcLogoutLink:logoutLink" title="Log out of WebCenter Portal" class="nav-link glyphicon glyphicon-log-out xf0 p_AFTextOnly" style="" onclick="this.focus();return false;" data-afr-fcs="true" href="#"></a></span>
</li>
</ul><span id="T:search2" class="x1a">
<div class="navbar-form navbar-left visible-xs" id="searchxs"><div id="T:searchbox2" class="x131" aria-live="polite"><div style="display:none"><a id="T:searchbox2:_afrCommandDelegate" class="xej" onclick="this.focus();return false;" data-afr-fcs="true" href="#"></a></div></div>
</div></span>
</div>
</nav>
</div>
</div>
</div>
So a simple CSS only solution would be;
Remove the padding from li element.
Make the a tag a block and give it 100% width
.navbar {
position: relative;
min-height: 40px !important;
margin-bottom: 20px;
border: none !important;
}
#navbarSupportedContent .nav-item {
text-transform: uppercase;
text-align: center;
font-weight: 800;
border-right: 1px solid #01154D;
padding: 0;
}
#navbarSupportedContent .nav-item:hover {
background-color: #DBDDFD;
color: #000 !important;
}
#navbarSupportedContent .nav-item a {
display: block;
width: 100%;
padding: 10px 24px; // removed from list and added here for same visual effect
}
<div role="navigation">
<div class="container">
<div id="undefined-sticky-wrapper" class="sticky-wrapper" style="height: 42px;"><nav class="navbar navbar-expand-lg navbar-dark bg-primary sticky-top">
<div class="collapse navbar-collapse justify-content-center" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto" style="float:inherit;">
<li class="nav-item active">
<a class="nav-link" href="/webcenter/portal/dummy/pages_en">
<span id="submenu1">Home</span>
</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="/webcenter/portal/dummy/pages_employeetools">
<span id="submenu1">Employee Tools</span>
</a>
</li>
<li class="nav-item ">
<div class="dropdown show">
<a style="color:#e6ecf2;" aria-expanded="false" aria-haspopup="true" class="dropdown-toggle" data-toggle="dropdown" href="#" id="dropdownMenuLink" role="button">MEDIA CENTER</a>
<div aria-labelledby="dropdownMenuLink" class="dropdown-menu">
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/photogallery">PHOTO GALLERY</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/news1">NEWS</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/newpage">dummy MAGAZINE</a>
<a class="dropdown-item" href="/webcenter/portal/dummy/pages_mediacenter/ashurtiassagheer">dummy</a>
</div>
</div>
</li>
<li class="nav-item ">
<a class="nav-link" href="/webcenter/portal/dummy/pages_documents">
<span id="submenu1">Documents</span>
</a>
</li>
<li class="nav-item"><a data-afr-tlen="7" id="T:arabic2" class="nav-link xej" style="font-size: initial;" onclick="this.focus();return false;" data-afr-fcs="true" href="#"><span style="">العربية</span>
<i aria-hidden="true" class="fa fa-language"></i></a>
</li>
<li class="nav-item" style="margin-left: auto;"><span id="T:wcLogoutLink:spacesActionPGL" class="x1a"><a data-afr-tlen="0" id="T:wcLogoutLink:logoutLink" title="Log out of WebCenter Portal" class="nav-link glyphicon glyphicon-log-out xf0 p_AFTextOnly" style="" onclick="this.focus();return false;" data-afr-fcs="true" href="#"></a></span>
</li>
</ul><span id="T:search2" class="x1a">
<div class="navbar-form navbar-left visible-xs" id="searchxs"><div id="T:searchbox2" class="x131" aria-live="polite"><div style="display:none"><a id="T:searchbox2:_afrCommandDelegate" class="xej" onclick="this.focus();return false;" data-afr-fcs="true" href="#"></a></div></div>
</div></span>
</div>
</nav></div>
</div>
</div>
Simple Solution, Just throw list (li) between the anchor tags (a)
<ul class="navbar-nav mr-auto" style="float:inherit;">
<a class="nav-link" href="/webcenter/portal/dummy/pages_en">
<li class="nav-item active">
<span id="submenu1">Home</span>
</li>
</a>
<a class="nav-link" href="/webcenter/portal/dummy/pages_employeetools">
<li class="nav-item ">
<span id="submenu1">Employee Tools</span>
</li>
</a>
</ul>

How to move dropdown item to the right end of the page

I'm trying to move the language switcher and it's items to the right end of the page. I tried ml-auto but it didn't work.
When I try to move the language picker using padding-left all of its items appear in the center of the page. Any solutions or advices?Here is how my web-page looks like.
.navbar-nav {
margin: 0 auto;
}
.nav-link {
font-weight: 900;
font-size: 1rem;
float: right;
}
#top-nav {
position: absolute;
z-index: 3;
width: 100%;
background-color: transparent !important;
}
#logo {
width: 100px;
height: 50px;
margin-left: 0;
padding-left: 0;
}
.flag-icon {
border-radius: 50%;
}
.navbar-light .navbar-toggler {
color: #FFFFFF;
border-color: #FFFFFF;
}
<nav class="navbar navbar-expand-lg navbar-light bg-light" id="top-nav">
<a class="navbar-brand" id="logo" href="index.html">
<img src="media/logo_light.svg" />
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse " id="navbarNav">
<ul class="navbar-nav">
<li id="main" class="nav-item active ">
<a class="nav-link text-light" href="#">მთავარი<span class="sr-only">(current)</span></a>
</li>
<li id="about-us" class="nav-item">
<a class="nav-link text-light" href="#">ჩვენ შესახებ</a>
</li>
<li id="services" class="nav-item">
<a class="nav-link text-light" href="#">სერვისები</a>
</li>
<li id="contact" class="nav-item">
<a class="nav-link text-light " href="#">კონტაქტი</a>
</li>
<li class="nav navbar-nav nav-item dropdown justify-content-end">
<a class="nav-link dropdown-toggle" href="#" id="dropdown09" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="flag-icon flag-icon-ge"></span></a>
<div class="dropdown-menu" aria-labelledby="dropdown09">
<a class="dropdown-item nav-link" href="#gb"><span class="flag-icon flag-icon-gb"></span></a>
<a class="dropdown-item nav-link" href="#ru"><span class="flag-icon flag-icon-ru"> </span></a>
</div>
</li>
</ul>
</div>
</nav>
Do you want something like this?
.navbar-nav {
margin: 0 auto;
}
.nav-link {
font-weight: 900;
font-size: 1rem;
}
#top-nav {
position: absolute;
z-index: 3;
width: 100%;
background-color: transparent !important;
}
#logo {
width: 100px;
height: 50px;
margin-left: 0;
padding-left: 0;
}
.flag-icon {
border-radius: 50%;
}
.navbar-light .navbar-toggler {
color: #FFFFFF;
border-color: #FFFFFF;
}
.navbar-nav {
float: right;
}
<nav class="navbar navbar-expand-lg navbar-light bg-light" id="top-nav">
<a class="navbar-brand" id="logo" href="index.html">
<img src="media/logo_light.svg" />
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse " id="navbarNav">
<ul class="navbar-nav">
<li id="main" class="nav-item active ">
<a class="nav-link text-light" href="#">მთავარი<span class="sr-only">(current)</span></a>
</li>
<li id="about-us" class="nav-item">
<a class="nav-link text-light" href="#">ჩვენ შესახებ</a>
</li>
<li id="services" class="nav-item">
<a class="nav-link text-light" href="#">სერვისები</a>
</li>
<li id="contact" class="nav-item">
<a class="nav-link text-light " href="#">კონტაქტი</a>
</li>
<li class="nav navbar-nav nav-item dropdown justify-content-end">
<a class="nav-link dropdown-toggle" href="#" id="dropdown09" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="flag-icon flag-icon-ge"></span></a>
<div class="dropdown-menu" aria-labelledby="dropdown09">
<a class="dropdown-item nav-link" href="#gb"><span class="flag-icon flag-icon-gb"></span></a>
<a class="dropdown-item nav-link" href="#ru"><span class="flag-icon flag-icon-ru"> </span></a>
</div>
</li>
</ul>
</div>
</nav>
Try adding a class to your language switcher, navbar-right, that used to work on Bootstrap 3, not 100% sure on Bootstrap 4

How to maintain focus state on parent item in dropdown menu?

I have a menu with a dropdown in it. When I click the dropdown, the child menu is a color. I'm trying to maintain that same color (which is in the hover state) in the parent item, after the menu is clicked. Currently, when I click the dropdown and then mouse away from the parent, it changes back to the original menu color (pink).
Best to open the snippet in full page to see what I'm referring to.
.dropdown-menu {
border: none;
border-radius: 0;
margin: 0;
}
.dropdown-item:hover {
background-color: #0091c7;
}
.nav-link.dropdown-toggle:hover {
background-color: #00aeef;
}
.nav-link > li.dropdown-toggle.active > a,
.nav-link > li.dropdown-toggle.active > a:focus,
.nav-link > li.dropdown-toggle.active > a:hover {
background-color: #00aeef;
color: #ffffff;
}
.bg-pink {
background-color: #d60c8c;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container p-5">
<div class="row">
<div class="col-sm-12">
<!-- HTML here -->
<div class="container-fluid bg-pink">
<div class="container">
<div class="row">
<div class="col-lg-12">
<nav class="navbar navbar-expand-lg navbar-light bg-pink">
<a class="navbar-brand" href="#">
<i class="fa fa-home fa-2x"></i>
</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 mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</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">
Dropdown Parent
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #00aeef;">
<a class="dropdown-item" href="#">Action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Action Action</a>
<a class="dropdown-item" href="#">Action Action</a>
<a class="dropdown-item" href="#">Action Action</a>
<a class="dropdown-item" href="#">Action Action Action</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
When the dropdown is clicked, the show class is added to its parent li.
I added
li.show > #navbarDropdown,
to your css here:
li.show > #navbarDropdown,
.nav-link > li.dropdown-toggle.active > a,
.nav-link > li.dropdown-toggle.active > a:focus,
.nav-link > li.dropdown-toggle.active > a:hover {
background-color: #00aeef;
color: #ffffff;
}

Vertical-Alignment of Image in Navbar

I have a website that I am developing utilizing the Bootstrap 4 framework. I am trying to create a navbar with the navbar-brand in the center. I was able to place the navbar-brand in the center with a navbar-nav on each side of the navbar-brand. Please find below the code that I utilized. My issue is that the navbar-brand is vertically aligned in the center of the navbar.
How can I align the navbar-brand to the bottom of the navbar and have the excess stick out at the top of the navbar without adjusting the margins?
#hdrContainer {
background-color: #0a3782;
}
.container {
background-color: inherit;
}
#tblHeader {
width: 100%;
/*font-size: .8125rem;*/
font-size: 1rem;
text-align: right;
color: #ffffff;
font-weight: bold;
}
#tblHeader tr {
height: 50px;
}
.breadcrumb {
background-color: inherit;
margin-bottom: initial;
font-weight: bold;
}
.breadcrumb .active {
color: inherit;
}
#socialbrand {
text-align: right;
}
#mainNavbar {
background-color: gray;
}
#mainNavbar .container .navbar {
position: relative;
z-index: 0;
max-height: 40px;
}
.navbar-brand {
position: relative;
z-index: 1;
margin-right: initial;
}
.form-control {
width: 200px;
}
.btn-outline-navy {
color: #f6b40e;
background-color: transparent;
background-image: none;
border-color: #f6b40e;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
<div id="hdrContainer" class="container-fluid">
<div class="container">
<table id="tblHeader">
<tbody>
<tr>
<td>
<nav aria-label="breadcrumb" role="navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item active" aria-current="page">Commander, Naval Surface Force, US Pacific</li>
</ol>
</nav>
</td>
<td id="socialbrand" style="display: block; padding: .75rem 1rem;">Follow Us |
<i class="fa fa-facebook-square" aria-hidden="true"></i>
<i class="fa fa-twitter-square" aria-hidden="true"></i>
<i class="fa fa-flickr" aria-hidden="true"></i>
<i class="fa fa-wordpress" aria-hidden="true"></i>
<i class="fa fa-youtube-square" aria-hidden="true"></i>
</td>
</tr>
<tr>
<td colspan="2">
<nav class="navbar navbar-light">
<form class="form-inline">
<input class="form-control form-control-sm ml-auto mr-sm-2 float-right" placeholder="Search" aria-label="Search" type="search">
<button class="btn btn-sm btn-outline-navy my-2 my-sm-0" type="submit">Search</button>
</form>
</nav>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="mainNavbar" class="container-fluid">
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light">
<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 ml-auto 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 dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<!-- Just an image -->
<a class="navbar-brand mr-auto ml-auto" href="#">
<img src="https://getbootstrap.com/assets/brand/bootstrap-solid.svg" alt="" width="75" height="75">
</a>
<ul class="navbar-nav ml-auto 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 dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown1" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown1">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
The solution below makes use of the various flexbox utility classes available in Bootstrap, described in detail in the docs.
The .navbar-brand got wrapped into <div id="logo"> in order to set it's positioning to absolute, and it's bottom position to 0. That pushes down the logo container to the bottom of the navbar.
Additionally, I've added the .d-none .d-lg-block classes in order to hide the logo when the menu is collapsed.
Available as a CodePen as well.
/* Pushing logo to bottom */
#logo {
position: absolute;
bottom: 0;
}
/* Basic styling to resemble to source */
.navbar {
background-color: gray;
}
#header {
height: 100px;
color: white;
background-color: #0a3782;
display: flex;
justify-content: center;
align-items: center;
}
<div id="header">[header placeholder]</div>
<nav class="navbar navbar-expand-lg navbar-light">
<div class="container">
<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 justify-content-around" id="navbarSupportedContent">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">Features</a>
<a class="nav-item nav-link" href="#">Pricing</a>
<a class="nav-item nav-link disabled" href="#">Disabled</a>
</div>
<div id="logo" class="d-none d-lg-block">
<a class="navbar-brand m-0" href="#">
<img src="http://getbootstrap.com/assets/brand/bootstrap-solid.svg" width="75" height="75" alt="">
</a>
</div>
<div class="navbar-nav">
<a class="nav-item nav-link" href="#">Item 1</a>
<a class="nav-item nav-link" href="#">Item 2</a>
<a class="nav-item nav-link" href="#">Item 3</a>
<a class="nav-item nav-link" href="#">Item 4</a>
</div>
</div>
</div>
</nav>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>