responsive menu with height 60px and full height borders - css

I wan to have a menu with a 1px gray border-bottom below the navbar and also gray borders around nav items and at right of the logo. The orange area is the content area, like:
Im using bootstrap 4 responsive menu. But I would like that the menu occupies a height of 60px and that has borders with full height. A full height border at right of the "Logo", and then full height borders around the nav items. But its not working properly, Im getting this: https://jsfiddle.net/xxub3zvp/1/.
The borders of the menu items and the border at right of the logo are not occupying the full height. Also the gray border bottom of the menu is not occupying the full width.
Html:
<div class="container-fluid px-0 py-0">
<nav class="navbar navbar-expand-md navbar-light">
<a class="logo font-weight-bold text-primary" href="#">Logo</a>
<button class="navbar-toggler mr-3" type="button" data-toggle="collapse" data-target="#main_nav" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="menu_container">
<div class="collapse navbar-collapse" id="main_nav">
<ul class="navbar-nav ml-auto d-flex align-items-lg-center">
<li class="nav-item">
<a class="nav-link" href="#">Item 0</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Item 1</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="userDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="
false">
<i class="fa fa-user" aria-hidden="true"></i> Jan
</a>
<div class="dropdown-menu" aria-labelledby="userDropdown">
<a class="dropdown-item text-gray" href="#">i1</a>
<a class="dropdown-item text-gray" href="#">i2</a>
</div>
</li>
</ul>
</div>
</div>
</nav>
</div>
<section style="background-color:orange;">
content
</section>
css:
.menu_container {
position: relative;
width: 100%;
border-bottom:1px solid gray;
height:60px;
}
div.dropdown-menu {
left: auto;
right: 0;
}
.nav-item {
border-left: 1px solid gray;
padding: 0.3rem 0.75rem;
}
.navbar{
border-right: 1px solid gray;
}
.logo{
border-right:1px solid gray;
padding: 0 1rem;
height: 45px;
line-height: 45px;
}
.dropdown-menu {
border-radius: 0;
border-top: 0;
border-left: 1px solid gray;
border-right: 1px solid gray;
border-bottom: 1px solid gray;
}
.navbar {
padding:0;
}

Update/Add your css with following css
.nav-item {
border-left: 1px solid gray;
padding: 0 0.75rem;
line-height: 60px;
}
.logo {
border-right:1px solid gray;
padding: 0 1rem;
line-height: 60px;
}
.nav-link {
padding: 0 1rem;
}
https://jsfiddle.net/xxub3zvp/4/

Related

How to automatically display the navbar vertically (boostrap-React.js )?

I am trying to automatically display the navbar vertically instead of horizontally , but I do not understand why its not working whene I use
# media ?
/*
I am trying to automatically display the navbar vertically instead of horizontally , but I do not understand why its not working ?
I am trying to automatically display the navbar vertically instead of horizontally , but I do not understand why its not working ?
function App() {
return (
<div className="App"> n
<nav class="navbar navbar-expand-md navbar-dark bg-dark mb-4" >
<div class="container-fluid">
<a class="navbar-brand" href="#">Top navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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 me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"/>
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
<header className="App-header"></header>
</div>
);
}
export default App;
//App.css
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
#media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
.b-example-divider {
height: 3rem;
background-color: rgba(0, 0, 0, .1);
border: solid rgba(0, 0, 0, .15);
border-width: 1px 0;
box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15);
}
.b-example-vr {
flex-shrink: 0;
width: 1.5rem;
height: 100vh;
}
.bi {
vertical-align: -.125em;
fill: currentColor;
}
.nav-scroller {
position: relative;
z-index: 2;
height: 2.75rem;
overflow-y: hidden;
}
.nav-scroller .nav {
display: flex;
flex-wrap: nowrap;
padding-bottom: 1rem;
margin-top: -1px;
overflow-x: auto;
text-align: center;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}

gap borders' right and left

When I applied padding to 'a' elements, there will be gaps top-borders' left and right.I want the top border covers entire line until navbar's right border. How can I solve this problem.
* {
margin: 0;
padding: 0;
font-family: 'Lato', sans-serif;
}
.wrapper {
display: grid;
grid-template-columns: 1fr 6fr;
}
.navbar {
border-right: gray 3px solid;
padding: 5%;
position: sticky;
top: 0;
height: 100vh;
box-sizing: border-box;
min-width: 300px;
}
#navbar-header {
text-align: center;
margin-bottom: 20px;
}
#navbar-content a {
text-decoration: none;
color: black;
}
#navbar-content a li {
list-style: none;
padding: 5%;
padding-left: 10%;
border-top: gray 1px solid;
}
<div class="wrapper">
<div class="navbar">
<h2 id="navbar-header">JS Documentation</h2>
<ul id="navbar-content">
<a href="#intro">
<li>Introduction</li>
</a>
<a href="#know">
<li>What you should already know</li>
</a>
<a href="#js-java">
<li>JavaScript and Java</li>
</a>
<a href="#hello">
<li>Hello World</li>
</a>
<a href="#var">
<li>Variables</li>
</a>
<a href="#dec-var">
<li>Declaring Variables</li>
</a>
<a href="#var-sco">
<li>Variable Scope</li>
</a>
<a href="#glo-var">
<li>Global Variables</li>
</a>
<a href="#cons">
<li>Constants</li>
</a>
<a href="#data">
<li>Data Types</li>
</a>
<a href="#if-else">
<li>if...else statement</li>
</a>
<a href="#while">
<li>while statement</li>
</a>
<a href="#func">
<li>Function declarations</li>
</a>
<a href="#ref">
<li>Reference</li>
</a>
</ul>
</div>
<div class="contents">
</div>
</div>
When I applied padding to 'a' elements, there will be gaps top-borders' left and right.I want the top border covers entire line until navbar's right border. How can I solve this problem.
Remove the padding-left/right from the navbar and increase the one of the li:
* {
margin: 0;
padding: 0;
font-family: 'Lato', sans-serif;
}
.wrapper {
display: grid;
grid-template-columns: 1fr 6fr;
}
.navbar {
border-right: gray 3px solid;
padding: 5% 0; /*updated*/
position: sticky;
top: 0;
height: 100vh;
box-sizing: border-box;
min-width: 300px;
}
#navbar-header {
text-align: center;
margin-bottom: 20px;
}
#navbar-content a {
text-decoration: none;
color: black;
}
#navbar-content a li {
list-style: none;
padding: 5% 10%; /*updated*/
border-top: gray 1px solid;
}
<div class="wrapper">
<div class="navbar">
<h2 id="navbar-header">JS Documentation</h2>
<ul id="navbar-content">
<a href="#intro">
<li>Introduction</li>
</a>
<a href="#know">
<li>What you should already know</li>
</a>
<a href="#js-java">
<li>JavaScript and Java</li>
</a>
<a href="#hello">
<li>Hello World</li>
</a>
<a href="#var">
<li>Variables</li>
</a>
<a href="#dec-var">
<li>Declaring Variables</li>
</a>
<a href="#var-sco">
<li>Variable Scope</li>
</a>
<a href="#glo-var">
<li>Global Variables</li>
</a>
<a href="#cons">
<li>Constants</li>
</a>
<a href="#data">
<li>Data Types</li>
</a>
<a href="#if-else">
<li>if...else statement</li>
</a>
<a href="#while">
<li>while statement</li>
</a>
<a href="#func">
<li>Function declarations</li>
</a>
<a href="#ref">
<li>Reference</li>
</a>
</ul>
</div>
<div class="contents">
</div>
</div>

Bootstrap 4 hover on navbar links causes flickering

I want to make my navbar links have a darker background color whenever I hover my mouse over them. It is working OK, but when I change padding (to 0px in this case) it starts to flicker: (View on full screen for better effect)
Also, the image link is not the same height as the other links(And when collapsed, it has this right blank space), and I can't get it in same line using the current styling rules.
**Edit: It's caused by the padding:0px!important, but that's because I do not want the hovering background to take the entire height. How to make the hovering background with less height?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<style>
.navbar {
min-height: 80px;
font-size: 0.8rem;
font-weight:500;
}
.navbar-brand {
padding: 0 15px;
height: 80px;
line-height: 80px;
}
.navbar-toggle {
/* (80px - button height 34px) / 2 = 23px */
margin-top: 23px;
padding: 9px 10px !important;
}
#media (min-width: 768px) {
.navbar-nav > li > a {
/* (80px - line-height of 27px) / 2 = 26.5px */
padding-top: 26.5px;
padding-bottom: 26.5px;
line-height: 27px;
}
}
.bottom-space {
margin-bottom: 20px;
}
#navbar_logged_in > a:link {
color: white ;
}
#navbar_logged_in > a:hover {
opacity:0.7 ;
}
#navbar_logged_in > a:visited {
color: white ;
}
#navbar_logged_in > li.nav-link{
color:white;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link{
background-color: #17A2B8;
}
body {
padding-top: 110px;
}
.main-nav a:hover {
background-color: #0D47A1!important;
padding: 0px!important;
}
</style>
<nav id="navbar_logged_in" class="navbar navbar-expand-lg navbar-light bottom-space fixed-top" style="background: linear-gradient(to right, #3399ff , #1a8cff, #0080ff, #0073e6);">
<div class="container">
<a class="navbar-brand mx-auto" href="#">
Logo
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-right" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white;margin-right:25px;">
<img class="img-circle" src="Image" alt="Image" width="35" height="35" style="border-radius: 50%!important;">
</a>
</li>
<li class="nav-item main-nav">
<a id="homepage_link" class="nav-link" href="#" style="color:white">Homepage</a>
</li>
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white">About</a>
</li>
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white">Log Out</a>
</li>
</ul>
</div>
</div>
</nav>
What's causing that? How can I fix it?
Thanks
The flickering is caused because when you hover, you are removing the padding, which pulls the element out from under the cursor. This then stops the hover and reapplies the padding which puts it back under the cursor, triggering the hover state. Rinse and repeat.
To stop the flicker, you need these two styles to work together:
#media (min-width: 768px) {
.navbar-nav > li > a {
padding-top: 26.5px;
padding-bottom: 26.5px;
line-height: 27px;
}
}
.main-nav a:hover {
background-color: #0D47A1!important;
padding: 0px!important;
}
If you want the hovering background to take less height, replace the part that you don't want the background on with margin. This might look like:
#media (min-width: 768px) {
.navbar-nav > li > a {
padding: 6.5px 8px; /* top/bottom, sides */
margin: 20px 0px;
line-height: 27px;
}
}
.main-nav a:hover {
background-color: #0D47A1!important;
}
In short, don't make your box size change on hover, and if you don't want background, use margin instead of padding
The padding in the hover is causing the problem: padding: 10px!important;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<style>
.navbar {
min-height: 80px;
font-size: 0.8rem;
font-weight:500;
}
.navbar-brand {
padding: 0 15px;
height: 80px;
line-height: 80px;
}
.navbar-toggle {
/* (80px - button height 34px) / 2 = 23px */
margin-top: 23px;
padding: 9px 10px !important;
}
#media (min-width: 768px) {
.navbar-nav > li > a {
/* (80px - line-height of 27px) / 2 = 26.5px */
padding-top: 26.5px;
padding-bottom: 26.5px;
line-height: 27px;
}
}
.bottom-space {
margin-bottom: 20px;
}
#navbar_logged_in > a:link {
color: white ;
}
#navbar_logged_in > a:hover {
opacity:0.7 ;
}
#navbar_logged_in > a:visited {
color: white ;
}
#navbar_logged_in > li.nav-link{
color:white;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link{
background-color: #17A2B8;
}
body {
padding-top: 110px;
}
.main-nav a:hover {
background-color: #0D47A1!important;
}
</style>
<nav id="navbar_logged_in" class="navbar navbar-expand-lg navbar-light bottom-space fixed-top" style="background: linear-gradient(to right, #3399ff , #1a8cff, #0080ff, #0073e6);">
<div class="container">
<a class="navbar-brand mx-auto" href="#">
Logo
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-right" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white;margin-right:25px;">
<img class="img-circle" src="Image" alt="Image" width="35" height="35" style="border-radius: 50%!important;">
</a>
</li>
<li class="nav-item main-nav">
<a id="homepage_link" class="nav-link" href="#" style="color:white">Homepage</a>
</li>
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white">About</a>
</li>
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white">Log Out</a>
</li>
</ul>
</div>
</div>
</nav>

How to make all navbar <li>s the same width

I am using Angular 4, Bootstrap 4 alpha 6 (css). I am trying to make each <li> the equal width (not 100% of the navbar). I was trying to use flex box but I cant get it to make them all equal.
I've tried several ways but each time the items will all be a fixed width but not the same width.
Heres an example of what I'm trying to do
[ ---item 1--- | ---item 2--- | ---item 3--- ]
HTML
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ng-container *ngIf="isLoggedIn">
<span class="navbar-text"> </span>
<ul class="nav navbar-nav ">
<li class="nav-item active">
<a class="nav-link" href="#">Dashboard <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="profileDropdownMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
My Account
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item">My Account</a>
<a class="dropdown-item">My Account</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="accountDropdownMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Profile
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" [routerLink]="['/profile', 'view']">My Account</a>
<a class="dropdown-item" [routerLink]="['/profile']">Edit my Profile</a>
</div>
</li>
</ul>
</ul>
</div>
</nav>
CSS
nav ul{
list-style: none;
margin: 0 2px;
padding: 0;
display: flex;
justify-content: space-around;
}
nav li{
width: 100%
}
.nav.navbar-nav > li{
border-right: 2px solid white;
}
EDIT: This works but I would prefer to use flex so that its done automatically
.nav.navbar-nav > li{
border-right: 2px solid white;
width: 200px;
max-width: 200px;
text-align: center;
}
Other ways I've tried
1)
.navbar ul.nav {
!*margin: 0;*!
display: table;
width: 100%;
!*direction: rtl;*!
table-layout: fixed;
margin:0;
padding:0;
}
.navbar ul.nav li {
!*float: right;*!
display: table-cell;
width: 20%;
!*float: none;*!
text-align: center;
!*direction: rtl;*!
}
.navbar .nav > li:hover {
background-color: #808080
}
.navbar .nav li:first-child a {
!*border-left: 0;*!
!*border-radius: 3px 0 0 3px;*!
}
.nav.navbar-nav > li{
!*width: 10%;*!
border-right: 2px solid white;
}
2)
nav {
text-align: center;
margin: 20px 0 0 ;
padding: 10px 0;
}
nav ul{
list-style: none;
margin: 0 2px;
padding: 0;
}
nav li {
display: inline-block;
padding: 5px 5px;
}
nav a {
font-weight: normal;
padding: 10px 5px;
}
Use calc() Basically by dividing 100% width by 3 each li will be 1/3 in width. Next you can set each "a" to 100% (width will be 100% of parent) and display:inline-block (so that width takes effect.
nav li{
width: calc(100% / 3);
}
I really don't see how you can get them to be the same size without giving your <nav> some kind of width. However, if you do give it a width, you can get all your child elements to be the same width using a combination of display: table; and display: table-cell. It's all the niceties of <table> without the syntactic commitment.
nav {
width: 50%;
position: relative;
}
nav ul {
display: table;
padding: 0;
margin: 0;
width: 100%;
}
nav ul li {
text-align: center;
display: table-cell;
border: 1px solid black;
}
<nav>
<ul>
<li>Fizz</li>
<li>Buzz</li>
<li>Foo</li>
</ul>
</nav>

How to achieve this menu layout? With full-height borders and the dropdown-menu properly aligned with the menu border bottom?

I want to have a menu like below, where:
the border-bottom of the menu is next to the orange background without any white space, and this border-bottom occupy the full-width, without any white space at left or right
the logo have a full height border right and and each menu item also have
full-height borders
Also the "Item" that has a dropdown menu i want that when is open it is aligned with the gray border-bottom of the navbar.
For that im using the code below, but Im not achieving this layout, I have a working example with the layout Im getting "http://jsfiddle.net/4606qqux/". Do you know how to fix the code to achieve the above layout?
HTML:
<div class="container-fluid px-0">
<nav class="navbar navbar-expand-md navbar-light">
Logo
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#main_nav" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="menu_container">
<div class="collapse navbar-collapse" id="main_nav">
<ul class="navbar-nav ml-auto d-flex align-items-lg-center">
<li class="nav-item">
<a class="nav-link" href="#">Item 0</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Item 1</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="userDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-user" aria-hidden="true"></i> Jan
</a>
<div class="dropdown-menu" aria-labelledby="userDropdown">
<a class="dropdown-item" href="#">Edit Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">logout</a>
</div>
</li>
</ul>
</div>
</div>
</nav>
</div>
CSS
.menu_container {
position: relative;
width: 100%;
border-bottom:1px solid gray;
}
div.dropdown-menu {
left: auto;
right: 0;
}
section {
background-color: orange;
height: 300px;
width: 100%;
}
.nav-item {
border-left: 1px solid gray;
}
.navbar{
border-right: 1px solid gray;
}
.logo{
border-right:1px solid gray;
}
From what I understood this is what you are after:
.logo {
border-right:1px solid gray;
height: 40px;
border-bottom: 1px solid gray;
padding-left: 20px;
padding-right: 20px;
line-height: 40px;
}
.dropdown-menu {
border-radius: 0;
border: 1px solid gray;
margin-top: 0;
}
Here is the updated fiddle:
http://jsfiddle.net/4606qqux/1/
Here is an even-more-updated-fiddle without padding around the top navigation element:
http://jsfiddle.net/4606qqux/2/

Resources