I have 2 menus on the web page one needs to show at the center bottom and another one on the top right. This following code shows all of them in the same line.
Here is the layout I am trying to achieve.
**********************************************************************************
Home About User Login
Logo Heading
Link1 Link2 Link3 Link4 Link5
**********************************************************************************
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"/>
<style>
.navbar-nav {
flex-direction: row;
}
.nav-link {
padding-right: .5rem !important;
padding-left: .5rem !important;
}
/* Fixes dropdown menus placed on the right side */
.ml-auto .dropdown-menu {
left: auto !important;
right: 0px;
}
.navbar-nav > li > a
{
padding: 0;
margin: 0;
vertical-align: bottom;
}
</style>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary rounded">
<a class="navbar-brand" href="">
<img style="width: 64px;height: 64px;" src="../../Images/new.png" >Heading
</a>
<ul class="navbar-nav mr-auto">
<li class="nav-item active" ID="link1" runat="server" >
<a class="nav-link">Link1</a>
</li>
<li class="nav-item active" ID="link2" runat="server" >
<a class="nav-link">Link2</a>
</li>
<li class="nav-item active" ID="link3" runat="server" >
<a class="nav-link">Link3</a>
</li>
<li class="nav-item active" ID="link4" runat="server" >
<a class="nav-link">Link4</a>
</li>
<li class="nav-item active" ID="link5" runat="server" >
<a class="nav-link">Link5</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="../../page.aspx">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../About.aspx" >About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../User.aspx">User</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"><asp:Label ID="LogOnUser" runat="server"></asp:Label></a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Log Out</a>
</div>
</li>
</ul>
</nav>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
You're super close! An mx-auto and mt-auto on the bottom-center menu and an mb-auto on the top-right menu are all you need to get it working.
NOTE: This does break on smaller screens as we're still treating everything as columns and columns do wrap. But, you could absolutely position the top-right menu if you need to on smaller screens.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
<style>
.navbar-nav {
flex-direction: row;
}
.nav-link {
padding-right: .5rem !important;
padding-left: .5rem !important;
}
/* Fixes dropdown menus placed on the right side */
.ml-auto .dropdown-menu {
left: auto !important;
right: 0px;
}
.navbar-nav>li>a {
padding: 0;
margin: 0;
vertical-align: bottom;
}
</style>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary rounded">
<a class="navbar-brand" href="">
<img style="width: 64px;height: 64px;" src="../../Images/new.png">Heading
</a>
<ul class="navbar-nav mx-auto mt-auto">
<li class="nav-item active" ID="link1" runat="server">
<a class="nav-link">Link1</a>
</li>
<li class="nav-item active" ID="link2" runat="server">
<a class="nav-link">Link2</a>
</li>
<li class="nav-item active" ID="link3" runat="server">
<a class="nav-link">Link3</a>
</li>
<li class="nav-item active" ID="link4" runat="server">
<a class="nav-link">Link4</a>
</li>
<li class="nav-item active" ID="link5" runat="server">
<a class="nav-link">Link5</a>
</li>
</ul>
<ul class="navbar-nav ml-auto mb-auto">
<li class="nav-item">
<a class="nav-link" href="../../page.aspx">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../About.aspx">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../User.aspx">User</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">
<asp:Label ID="LogOnUser" runat="server"></asp:Label>
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Log Out</a>
</div>
</li>
</ul>
</nav>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
Try this code. hope will help you.
.navbar-nav {
flex-direction: row;
}
.nav-link {
padding-right: .5rem !important;
padding-left: .5rem !important;
}
/* Fixes dropdown menus placed on the right side */
.ml-auto .dropdown-menu {
left: auto !important;
right: 0px;
}
.navbar-nav > li > a
{
padding: 0;
margin: 0;
vertical-align: bottom;
}
.bottom_menu{
margin-top: 30px;
}
.top_menu{
margin-bottom: 30px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
<nav class="navbar navbar-expand-lg navbar-dark bg-primary rounded justify-content-md-center">
<a class="navbar-brand" href="">
<img style="width: 64px;height: 64px;" src="../../Images/new.png" >Heading
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-between align-items-center w-100" id="navbarNavDropdown">
<ul class="bottom_menu navbar-nav ml-auto text-md-center">
<li class="nav-item active" ID="link1" runat="server" >
<a class="nav-link">Link1</a>
</li>
<li class="nav-item active" ID="link2" runat="server" >
<a class="nav-link">Link2</a>
</li>
<li class="nav-item active" ID="link3" runat="server" >
<a class="nav-link">Link3</a>
</li>
<li class="nav-item active" ID="link4" runat="server" >
<a class="nav-link">Link4</a>
</li>
<li class="nav-item active" ID="link5" runat="server" >
<a class="nav-link">Link5</a>
</li>
</ul>
<ul class="top_menu navbar-nav ml-auto justify-content-md-center justify-content-start flex-nowrap">
<li class="nav-item">
<a class="nav-link" href="../../page.aspx">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../About.aspx" >About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../User.aspx">User</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"><asp:Label ID="LogOnUser" runat="server"></asp:Label></a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Log Out</a>
</div>
</li>
</ul>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
You mean Like This?
<style>
#header{
position: relative;
width: 100%;
height: 100px;
background-color: orange;
}
a{
display: inline-block;
width: 50px;
}
#logo, #navigation, #url{
position: absolute;
}
#logo{
top: calc(50%);
}
#navigation{
top: 0;
right: 0;
}
#url{
left: calc(50% - 125px);
bottom: 0;
}
</style>
<div id = "header">
<div id = "logo">
LOGO
</div>
<div id = "navigation">
<a>Home</a>
<a>About</a>
<a>User</a>
</div>
<div id = "url">
<a>Link1</a>
<a>Link2</a>
<a>Link3</a>
<a>Link4</a>
<a>Link5</a>
</div>
</div>
Related
This is my html
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<img class="logo" src="/images/logo.png" alt="">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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">
<ul class="navbar-nav">
<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="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button"
data-bs-toggle="dropdown" aria-expanded="false">
Dropdown link
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
This is my css
/* Navbar */
.navbar {
width: 100%;
/* height: 45px; */
background-color: red;
position: absolute;
top: 0;
left: 0;
}
.logo {
height: 30px;
}
I want the logo to be on the far left and the nav-items together on the far right , I was adding a justify content to the container but did not work , any idea on how to do this ?
You can assign class justify-content-end to the #navbarNavDropdown div.
I also added px-lg-5 after container-fluid as to show all text in dropdown menu.
/* Navbar */
.navbar {
width: 100%;
/* height: 45px; */
background-color: red;
position: absolute;
top: 0;
left: 0;
}
.logo {
height: 30px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" />
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid px-lg-5">
<img class="logo" src="/images/logo.png" alt="">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNavDropdown">
<ul class="navbar-nav">
<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="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown link
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<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>
On the other hand, you are using Bootstrap-5 instead of Bootstrap-4.
I haven't been working on code for ages and I'm facing an issue that is getting me crazy cause I can't even start doing anything. I'm working on the very base of my website and when I try my page the navbar automatically goes on Mobile mode while I'm on desktop.
I tried on Chrome and Firefox with the same results : a shrinked navbar on full-size page (it's not even working correctly as it's not the good size). Reducing the window's size will make the mobile navbar work correctly but impossible to get a normal one.
I've tried different styles of navbar from Codepen to see if my code was wrong but same problem. I even tried using Bootstrap 3 instead of 4 and the code gets even worst.
This one for example is wrong : https://codepen.io/mmgolden/pen/JNewdL
HTML Head :
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css">
<script src="assets/js/jquery-3.4.1.min.js"></script>
<script src="assets/js/bootstrap.js"></script>
<link href="assets/css/style.css" rel="stylesheet" type="text/css">
HTML Body :
<body>
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarMobile" aria-controls="navbarMobile" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="nav-left">
<ul class="nav navbar-nav">
<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>
<a class="navbar-brand mx-auto" href="#"><div id="logo"></div></a>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav ml-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>
</ul>
</div>
<!-- Mobile -->
<div class="collapse" id="navbarMobile">
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Mobile Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Mobile Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Mobile Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Mobile Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Mobile Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Mobile Link</a>
</li>
</ul>
</div>
</nav>
<div class="slider">
</div>
</body>
CSS :
.slider {
background: #333;
height: 400px;
width: 100%;
}
#logo {
background: #ccc;
width: 150px;
height: 70px;
}
.navbar-toggler {
margin-top: 15px;
}
#media screen and (min-width: 992px) {
.navbar {
height: 130px;
}
#logo {
width: 260px;
height: 120px;
position: relative;
bottom: -20px;
}
.navbar-light .navbar-nav .nav-link {
padding-right: 75px;
}
#nav-left {
padding-left: 30px;
}
}
Screenshot : https://ibb.co/KDFqfTH
I need it it show up normally on desktop and shrink on mobile/tablet.
Thanks for your time.
I have a doubt relating to the dropdown in a navbar. For the normal nav-link (no dropdown) I put the menu text inside an H3, but when I tried to do the same for the dropdown-link, the arrow is not next to the title but under it. I decided to replace the h3 with a span and give the same CSS as an h3, this time the arrow was on the right place, but all the other styles were not taken into account.
The third example is the one more close to what I want, but the font-size is not quite the same.
Original code without dropdown
html {
font-size: 16px;
}
body {
font-family: Arial;
font-size: 1rem;
}
#logo {
max-height: 2.5rem;
}
.nav_container {
margin-bottom: 10%;
}
h1,h2,h3,h4,h5,h6 {
margin-bottom: .25rem;
margin-top: .25rem;
}
h3 {
font-size: 1.25rem;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Original</title>
<!-- Bootstrap 3.0-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Bootstrap 4.0-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<!-- FontAwesome5 Icons -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="css/main.css">
<!-- Fin liens CSS et Script -->
</head>
<body>
<div class="nav_container">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
<div class="d-flex align-items-center">
<a class="navbar-brand" href="#"><img id="logo" src="https://i.stack.imgur.com/440u9.png"></a>
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-uppercase" href="index.php">
<h3 class="font-weight-bold">Home</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link1</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link2</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link3</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link4</h3>
</a>
</li>
</ul>
</nav>
</div>
</body>
</html>
My tries
html {
font-size: 16px;
}
body {
font-family: Arial;
font-size: 1rem;
}
#logo {
max-height: 2.5rem;
}
.nav_container {
margin-bottom: 10%;
}
#navbardrop {
font-size: 1.25rem;
}
#navbardrop2 {
font-size: 1.25rem;
}
#navbardrop3 {
font-size: 1.25rem;
margin-bottom: .25rem;
margin-top: .25rem;
}
#admin_menu {
font-weight: 700!important;
margin-bottom: .25rem;
margin-top: .25rem;
}
h1, h2, h3, h4, h5, h6 {
margin-bottom: .25rem;
margin-top: .25rem;
}
h3 {
font-size: 1.25rem;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Example</title>
<!-- Bootstrap 3.0-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Bootstrap 4.0-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<!-- FontAwesome5 Icons -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<!-- CSS-->
<link rel="stylesheet" type="text/css" href="css/main.css">
<!-- Fin liens CSS et Script -->
</head>
<body>
<h2>Try 1</h2>
<div class="nav_container">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="d-flex align-items-center">
<a class="navbar-brand" href="#"><img id="logo" src="https://i.stack.imgur.com/440u9.png"></a>
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-uppercase" href="index.php">
<h3 class="font-weight-bold">Home</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link 1</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link2</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link3</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link4</h3>
</a>
</li>
<!-- Admin -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
<h3 id="admin_menu">Admin</h3>
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">
<h4>Admin1</h4>
</a>
<a class="dropdown-item" href="#">
<h4>Admin2</h4>
</a>
</div>
</li>
</ul>
</nav>
</div>
<h2>Try 2</h2>
<div class="nav_container">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="d-flex align-items-center">
<a class="navbar-brand" href="#"><img id="logo" src="https://i.stack.imgur.com/440u9.png"></a>
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-uppercase" href="index.php">
<h3 class="font-weight-bold">Home</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link 1</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link2</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link3</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link4</h3>
</a>
</li>
<!-- Admin -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop2" data-toggle="dropdown"><span id="admin_menu">Admin</span></a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">
<h4>Admin1</h4>
</a>
<a class="dropdown-item" href="#">
<h4>Admin2</h4>
</a>
</div>
</li>
</ul>
</nav>
</div>
<h2>Try 3</h2>
<div class="nav_container">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="d-flex align-items-center">
<a class="navbar-brand" href="#"><img id="logo" src="https://i.stack.imgur.com/440u9.png"></a>
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-uppercase" href="index.php">
<h3 class="font-weight-bold">Home</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link 1</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link2</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link3</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link4</h3>
</a>
</li>
<!-- Admin -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle font-weight-bold" href="#" id="navbardrop3" data-toggle="dropdown">Admin</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">
<h4>Admin1</h4>
</a>
<a class="dropdown-item" href="#">
<h4>Admin2</h4>
</a>
</div>
</li>
</ul>
</nav>
</div>
</body>
</html>
give position:relative to h3 and position:absolute to :after and adjust it accordingly. thanks
Workaround
CSS
#navbardrop{
font-size: 1.25rem;
}
#admin_menu {
font-weight: 700!important;
margin-bottom: .25rem;
margin-top: .25rem;
}
h3{
font-size: 1.25rem;
}
.dropdown-toggle::after{
display: none;
}
h4{
font-size: 1rem;
}
HTML
<div class="nav_container">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
<div class="d-flex align-items-center">
<a class="navbar-brand" href="homepage"><img id="logo" src="images/logo.jpg"></a>
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-uppercase" href="index.php"><h3 class="font-weight-bold">Accueil</h3></a>
</li>
<li class="nav-item">
<a class="nav-link" href="add_mat.php"><h3 class="font-weight-bold">Ajout Matériel</h3></a>
</li>
<li class="nav-item">
<a class="nav-link" href="add_cat.php"><h3 class="font-weight-bold">Ajout Catégorie</h3></a>
</li>
<li class="nav-item">
<a class="nav-link" href="add_type.php"><h3 class="font-weight-bold">Ajout Type</h3></a>
</li>
<li class="nav-item">
<a class="nav-link" href="add_model.php"><h3 class="font-weight-bold">Ajout Modèle</h3></a>
</li>
<!-- Admin -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
<h3 id="admin_menu">Admin <span class="fas fa-angle-down"></span></h3>
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="../update_data.php"><h4>Update Data</h4></a>
<a class="dropdown-item" href="../bd_tables.php"><h4>Tableaux BD</h4></a>
</div>
</li>
</ul>
</nav>
</div>
Result
How do I center my navigation links with bootstrap and CSS with 2 links on the far right. I will replace these 2 links with buttons and graphics later.
Here is a link to how it currently looks. The main navigation needs to be centered and the 2 links far right. http://www.woodenpalette.com/index2.html
This is what I have so far:
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<!-- Links -->
<ul class="navbar-nav justify-content-center">
<li class="nav-item">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="drawings.html">Drawings</a>
</li>
<li class="nav-item">
<a class="nav-link" href="eBook.html">Book</a>
</li>
<li class="nav-item">
<a class="nav-link" href="learn_how_to_draw.html">Learn</a>
</li>
<li class="nav-item">
<a class="nav-link" href="drawing_workshops.html">Workshops</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact.php">Contact</a>
</li>
</ul>
<ul class="nav justify-content-end">
<a class="nav-link" href="contact.php">Login</a> |
<a class="nav-link" href="contact.php">Register</a>
</ul>
</nav>
.navbar {
clear: both;
width: 100%;
margin-left: auto;
margin-right: auto;
}
.navbar ul{
text-align: center;
float: right;
margin: auto;
overflow: hidden;
}
Here is the correction:
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse">
<ul class="nav fix-center">
<li class="active">Home</li>
<li>Drawings</li>
<li>Book</li>
<li>Learn</li>
<li>Workshop</li>
</ul>
<ul class="nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign
Up</a>
</li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span>
Login</a>
</li>
</ul>
</div>
</div>
.fix-center{
display:block;
margin:0 auto;
text-align:center;
}
.nav li{
display:inline-block;
}
.navbar-right{
position:absolute;
right:0;
top:0;
}
I am creating an app in Bootstrap 3 with a tab bar. I am dynamically adding and removing tabs. This all works great, what I would like to do though is to have the tab bar be horizontally scrollable through the tabs if there are too many tabs to fit in the width of the app instead of creating multiple rows or tabs.
Has anyone done this or have an idea how to implement this?
Here is an example:
(Not working in snippet for some reason, so here is a link to Bootply : http://www.bootply.com/oROUAMwsG1)
.nav-tabs {
overflow-x: auto;
overflow-y: hidden;
display: -webkit-box;
display: -moz-box;
}
.nav-tabs>li {
float: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="col-md-4">
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active">Section 1
</li>
<li>Section 2
</li>
<li>Section 3
</li>
<li>Section 4
</li>
<li>Section 5
</li>
<li>Section 6
</li>
<li>Section 7
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<p>I'm in Section 1.</p>
</div>
<div class="tab-pane" id="tab2">
<p>I'm in Section 2.</p>
</div>
</div>
</div>
</div>
</div>
i solved this using:
.nav.nav-tabs {
overflow-x: auto;
overflow-y: hidden;
flex-wrap: nowrap;
}
example: https://codepen.io/r3l4x/pen/mdpdMLQ
note sure about cross browser stuff, so may not be a good answer.
Bootstrap 5 tab horizontal scroll for many items with pure javascript
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Bootstrap 5 tab horizontal scroll for many item</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<style>
.tab-scroller{
position: relative;
max-width: 100%;
overflow: hidden;
}
.tab-scroller-arrow{
position: absolute;
top: 0;
bottom: 0;
width: 25px;
cursor: pointer;
z-index: 1;
display: flex;
justify-content: center;
align-items: center;
background-color: #ffffff;
border: 1px solid #222222;
}
.tab-scroller .right-arrow{
right: 0;
}
.tab-scroller .left-arrow{
left: 0;
}
.tab-scroller .left-arrow.d-none~.nav{
padding-left: 0;
}
.tab-scroller .nav{
position: relative;
padding-left: 35px;
flex-wrap: nowrap;
}
</style>
</head>
<div class="tab-scroller" >
<i class="tab-scroller-arrow left-arrow d-none">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-left" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"/>
</svg>
</i>
<i class="tab-scroller-arrow right-arrow d-none">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-right" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"/>
</svg>
</i>
<ul class="nav nav-pills" id="pills-tab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="pills-home-tab" data-bs-toggle="pill" data-bs-target="#pills-home" type="button" role="tab" aria-controls="pills-home" aria-selected="true">Home</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-profile-tab" data-bs-toggle="pill" data-bs-target="#pills-profile" type="button" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-disabled-tab" data-bs-toggle="pill" data-bs-target="#pills-disabled" type="button" role="tab" aria-controls="pills-disabled" aria-selected="false" disabled>Disabled</button>
</li>
</ul>
</div>
<div class="tab-content" id="pills-tabContent">
<div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab" tabindex="0">Tab 1</div>
<div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab" tabindex="0">Tab 2</div>
<div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab" tabindex="0">Tab 3</div>
<div class="tab-pane fade" id="pills-disabled" role="tabpanel" aria-labelledby="pills-disabled-tab" tabindex="0">Tab 4</div>
</div>
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
<!-- Custom js -->
<script>
document.addEventListener("DOMContentLoaded", function(){
// selector
document.querySelectorAll(".tab-scroller").forEach((el) => {
let scrollTabInner = el.querySelector(".nav")
let scrollTabItem = el.querySelectorAll(".nav-item")
let leftArrow = el.querySelector(".left-arrow")
let rightArrow = el.querySelector(".right-arrow")
//scrollable tab width
let scrollTabWidth = el.offsetWidth
//all tab items width
let scrollTabItemsWidth = () => {
let itemsWidth = 0;
scrollTabItem.forEach(el => {
let itemWidth = el.offsetWidth;
itemsWidth += itemWidth;
});
return itemsWidth
}
//hidden tab item width
let widthOfHiddenItems = scrollTabItemsWidth() - scrollTabWidth;
let rightValue = 0;
if (scrollTabItemsWidth() > scrollTabWidth) {
rightArrow.classList.remove("d-none")
}
//right arrow click functionality
rightArrow.addEventListener("click", () => {
if (rightValue > widthOfHiddenItems) {
rightArrow.classList.add("d-none")
leftArrow.classList.remove("d-none")
scrollTabInner.style.cssText = `right: ${widthOfHiddenItems + 35}px;`
} else {
rightArrow.classList.remove("d-none")
leftArrow.classList.remove("d-none")
rightValue += 200;
scrollTabInner.style.cssText = `right: ${rightValue}px;`
}
})
//left arrow click functionality
leftArrow.addEventListener("click", () => {
rightValue -= 200;
scrollTabInner.style.cssText = `right: ${rightValue}px;`
rightArrow.classList.remove("d-none")
if (rightValue <= 0) {
leftArrow.classList.add("d-none")
rightArrow.classList.remove("d-none")
scrollTabInner.style.cssText = `right: 0px;`
}
})
})
})
</script>
</body>
</html>
I created a horizontal scroll-able tab bar using Navs.
You can check the working demo of the below code here.
CSS
.nav {
overflow-x: auto;
overflow-y: hidden;
height: 115px;
}
.nav-item {
cursor: pointer;
margin: 15px 10px;
width: 200px;
height: 70px;
box-shadow: 0 4px 6px -6px #222;
}
.nav-link {
font-size: 14px;
text-align: center;
}
.nav-item.selected {
color: #fff;
background-color: #007bff;
}
HTML
<div class="card">
<div class="card-body">
<ul class="nav flex-column nav-pills">
<li class="nav-item selected">
<span class="nav-link">HTML </span>
</li>
<li class="nav-item">
<span class="nav-link">CSS</span>
</li>
<li class="nav-item">
<span class="nav-link">JS</span>
</li>
<li class="nav-item">
<span class="nav-link">React</span>
</li>
<li class="nav-item">
<span class="nav-link">Angular</span>
</li>
<li class="nav-item">
<span class="nav-link">Vue</span>
</li>
<li class="nav-item">
<span class="nav-link">Bootstrap</span>
</li>
<li class="nav-item">
<span class="nav-link">Tailwind</span>
</li>
<li class="nav-item">
<span class="nav-link">Codepen</span>
</li>
</ul>
</div>
</div>
.nav-tabs {
overflow-x: auto;
overflow-y: hidden;
display: -webkit-box;
display: -moz-box;
}
.nav-tabs>li {
float: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="teste.css">
<title>Document</title>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="col-md-4">
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active">Section 1</li>
<li>Section 2</li>
<li>Section 3</li>
<li>Section 4</li>
<li>Section 5</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<p>I'm in Section 1.</p>
</div>
<div class="tab-pane" id="tab2">
<p>I'm in Section 2.</p>
</div>
<div class="tab-pane" id="tab3">
<p>I'm in Section 3.</p>
</div>
<div class="tab-pane" id="tab4">
<p>I'm in Section 4.</p>
</div>
<div class="tab-pane" id="tab5">
<p>I'm in Section 5.</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>