issue with CSS minus margin - html

i have use minus margin to place the navbar inside a div which has a class main..in small screen when i click on the navbar toggler icon it does not look good..because i need to change the margin again...how can i solve this problem without using minus margin?
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.min.css">
<div class="top"></div>
<div class="wrapper">
<nav class="navbar navbar-expand-md navbar-dark bg-dark sticky-top">
<button class="navbar-toggler ml-auto" data-toggle="collapse" data-target="#navDrop">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navDrop">
<ul class="navbar-nav">
<li class="nav-item">
HOME
</li>
<li class="nav-item">
ABOUT
</li>
<li class="nav-item">
SKILL
</li>
<li class="nav-item">
PORTFOLIO
</li>
<li class="nav-item">
TEAM
</li>
<li class="nav-item">
BLOG
</li>
<li class="nav-item">
CONTACT
</li>
</ul>
</div>
</nav>
<div class="main"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter- bootstrap/4.1.1/js/bootstrap.min.js"></script>
here is output of my code:
https://codepen.io/Sakhawat5/pen/NzwQJz

--Update--
As I think your question is how to append the navbar class to the main div if the user has scrolled more then 50px. This is what could help you out.
$(document).scroll(function() {
if ($(document).scrollTop() >= 50) {
// user scrolled 50 pixels or more;
// do stuff for example:
$('.navbar').appendTo('.main');
// this will append the navbar to the main div, if you want other styling on the navbar aswell we can do the following:
$('.navbar').addClass('.UserHasScrolled')
// now in you CSS set styling to .UserHasScrolled
} else {
// do things when user has NOT scrolled more then 50px
}
});
Also make sure to include jQuery, this is possible, paste this beneath all other scripts:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
To your .UserHasScrolled class you can set something like this:
.UserHasScrolled {
position: absolute;
width: 100%;
top: 0;
}
--First answer--
What you ask for is: #media screen and (max-width 767px) while the screen width has a lower size than 767px you can define an overwriting css style like this:
#media screen and (min-width 767px) {
.navbar {
margin-bottom: -336px;
}
}
But this causes another problem, while the navbar is closed the main class will still have a margin of -336px and that's not what you want I guess.
To keep your navbar on top just set position to fixed:
.navbar {
position: fixed;
width: 90%;
margin-left: 5%;
margin-right: 5%;
}

This is your solution:
.top{
height:50px;
background:red;
}
.navbar{
margin-left:20px;
margin-right:20px;
}
.main{
height:1500px;
background:orange;
}
<div class="top"></div>
<div class="wrapper">
<div class="main">
<nav class="navbar navbar-expand-md navbar-dark bg-dark sticky-top">
<button class="navbar-toggler ml-auto" data-toggle="collapse" data-target="#navDrop">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navDrop">
<ul class="navbar-nav">
<li class="nav-item">
HOME
</li>
<li class="nav-item">
ABOUT
</li>
<li class="nav-item">
SKILL
</li>
<li class="nav-item">
PORTFOLIO
</li>
<li class="nav-item">
TEAM
</li>
<li class="nav-item">
BLOG
</li>
<li class="nav-item">
CONTACT
</li>
</ul>
</div>
</nav>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter- bootstrap/4.1.1/js/bootstrap.min.js"></script>

The changes to your CSS as follows should fix the issue:
.navbar{
margin-left: 5%;
margin-right: 5%;
width: 90%;
position: fixed;
}
and if you don't want a fixed nav:
.navbar{
margin-left: 5%;
margin-right: 5%;
width: 90%;
position: absolute;
}
Let me know if you have any questions.

Related

Bootstrap 4 sticky footer issue

I'm kinda new to web-development using bootstrap and I'm trying to achieve something with my footer...
Actually my footer is looking like this for the desktop version of my website:
the footer elements are displayed in line without any issue...
But if I change the page's resolution until I reach the mobile design of it my footer elements are stacked on top of each others instead of still being inline:
I tried to fix that to use media queries and css, to add a display : inline-block to the html list but it didn't worked, and I don't really know what I should use to keept it displayed correctly.
Here is the code pen of the footer :
https://codepen.io/rgmislife/pen/poJJeyV
.footer-page {
background-color: #d2d7e8;
right: 0;
bottom: 0;
left: 0;
/**position:absolute;**/
position: relative;
width: 100%;
height: auto;
}
#media screen and (min-width: 320px) and (max-width: 1024px) {
.footer-page {
position: relative;
}
}
#media screen and (min-width: 768px) and (max-width: 1024px) {
.footer-page {
position: absolute;
}
}
.navbar-brand {
font-family: 'Raleway', regular;
color: white;
font-size: 15px;
letter-spacing: 1px;
}
.icon {
font-size: 0.4rem;
}
.nav-link {
font-family: 'Raleway', Semi-Bold;
letter-spacing: 1px;
color: #3a5199;
font-size: 15px;
letter-spacing: 1px;
no
}
<link href="//use.fontawesome.com/releases/v5.0.7/css/all.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<footer>
<div class="footer-page">
<nav class="navbar navbar-fixed-bottom navbar-expand-md bg-faded justify-content-center">
Brand
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100" id="collapsingNavbar3">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#"><i class="fab fa-linkedin fa-2x"></i></a>
</li>
<li class="nav-item d-inline-block">
<a class="nav-link" href="nous-contacter.php"><i class="fas fa-envelope fa-2x"></i></a>
</li>
</ul>
<ul class="nav navbar-nav ml-auto w-100 justify-content-end">
<li class="nav-item">
<a class="nav-link" href="nous-contacter.php">Nous contacter</a>
</li>
<li class="nav-item">
<a class="nav-link" href="mentions.html">Mentions Légales</a>
</li>
<li class="nav-item">
<a class="nav-link" href="CGV.html">CGV</a>
</li>
<li class="nav-item">
<a class="nav-link" href="presse.html">Presse</a>
</li>
<li class="nav-item">
<a class="nav-link" href="evenements.html">Evénements</a>
</li>
</ul>
</div>
</nav>
</div>
</footer>
and thats is the css code I tried :
.nav li {display: inline-block;}
If anyone has an idea feel free to let me know.
Thanks.
Is this what you're looking for?
#media screen and (max-width:768px){
.navbar-nav{
flex-direction: row;
}
.navbar-nav .nav-item{
margin: 0 10px;
}
}
Your elements are going to stack on mobile regardless based off text length and screen sizes
Your links are stacked, because they don't fit into container. You nothing can do without changing your html structure. And I suggest you to organize the layout ones more. Now it looks quite messy.
Quick fix, just to see what can be done (I see that you use bootstrap, so I base on that):
remove w-50 from navbar-brand link. It is the main reason of links stacking.
Now you want your icons are in the center, and as I understand you want keep them inside navbar-collapse together with links. So remove ml-auto w-100 from ul navbar-nav where are the links. Add mx-autoto ul where icons are, it makes them be in the center between brand and links.
Look into the snippet in full page mode.
.footer-page {
background-color: #d2d7e8;
right: 0;
bottom: 0;
left: 0;
/**position:absolute;*/
position: relative;
width: 100%;
height: auto;
}
#media screen and (min-width: 320px) and (max-width: 1024px) {
.footer-page {
position: relative;
}
}
#media screen and (min-width: 768px) and (max-width: 1024px) {
.footer-page {
position: absolute;
}
}
.navbar-brand {
font-family: 'Raleway', regular;
color: white;
font-size: 15px;
letter-spacing: 1px;
}
.icon {
font-size: 0.4rem;
}
.nav-link {
font-family: 'Raleway', Semi-Bold;
letter-spacing: 1px;
color: #3a5199;
font-size: 15px;
letter-spacing: 1px;
}
<link href="//use.fontawesome.com/releases/v5.0.7/css/all.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<footer>
<div class="footer-page">
<nav class="navbar navbar-fixed-bottom navbar-expand-md bg-faded justify-content-center">
Brand
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100" id="collapsingNavbar3">
<ul class="navbar-nav mx-auto">
<li class="nav-item active">
<a class="nav-link" href="#"><i class="fab fa-linkedin fa-2x"></i></a>
</li>
<li class="nav-item d-inline-block">
<a class="nav-link" href="nous-contacter.php"><i class="fas fa-envelope fa-2x"></i></a>
</li>
</ul>
<ul class="nav navbar-nav justify-content-end">
<li class="nav-item">
<a class="nav-link" href="nous-contacter.php">Nous contacter</a>
</li>
<li class="nav-item">
<a class="nav-link" href="mentions.html">Mentions Légales</a>
</li>
<li class="nav-item">
<a class="nav-link" href="CGV.html">CGV</a>
</li>
<li class="nav-item">
<a class="nav-link" href="presse.html">Presse</a>
</li>
<li class="nav-item">
<a class="nav-link" href="evenements.html">Evénements</a>
</li>
</ul>
</div>
</nav>
</div>
</footer>

How do I stack one navigation menu on top other the other using z-index?

I am a bit stuck trying to place or stack two navigation menus on top of each other, I am using Bootstrap, HTML and CSS.
I think I might need to use the z-index, but not sure exactly how.
I have added the code below and included picture of what I would like to achieve.
Code:
<!<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/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.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<nav class="navbar navbar-expand-md bg-white navbar-white">
<a class="navbar-brand" href="#">
<img src="assets/logo2.png"height="84px">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="accessability">
<li class="nav-item">
<a class="contrast">Contrast</a>
</li>
<li class="Font-size">Font size</a>
</li>
<li class="download">Download a brochure</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">New Vehicles</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Nearly New/ Used Vehicles</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Motability</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Aftercare</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Us</a>
</li>
</ul>
</div>
</nav>
<br>
<nav class="navbar navbar-inverse bg-primary">
<ul>
<li class="sec-menu">Versa Connect</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="sec-menu">Overview</li>
<li class="sec-menu">Offers</li>
<li class="sec-menu">Models</li>
<li class="sec-menu">Optional Extras</li>
</ul>
</nav>
<section id="cover_image">
<div class="container">
<img src="assets/cover_image.jpg" >
<div class="text-block">
<h1>Versa Connect</h1>
<p>The Ford Torneo Connect is a relaxing and comfortable place to be.
Great to drive, great to sit in, it boasts premium finish, high quality materials
and fuel efficiency without compromising everyday practicality. </p>
<button type="button" class="btn btn-lg btn-primary">Make an enquiry</button>
</div>
</div>
</body>
</html>
CSS
h1{
font-family: roboto;
}
p{
font-family: roboto;
font-size: 18px;
}
li{
font-family: roboto;
font-size: 18px;
display:inline;
padding: 30px;
}
li a{
color: #000;
}
.navbar-right{
float: right !important;
margin-right: -15px;
display: inline;
}
ul.nav navbar-nav navbar-right li a{
display: flex;
}
li.sec-menu a{
color: #fff;
font-family: roboto;
}
.container{
margin: 0;
padding: 0;
}
.text-block {
text-align: center;
position: absolute;
bottom: 10px;
left: 100px;
background-color:rgba(255,255,255,0.66);
color:#000;
width: 380px;
padding:50px;
}
.btn btn-lg btn-primary{
padding-left: 10px;
width: 360px;
}
I would appreciate it if somebody could help me with my coding and show me how or where I should code the z-index in my code.
The z-index property is used for stacking items on top of each other via the z plane (think of a 3-dimensional plane), so that property would not help you here. All you need to do is create each navbar using a separate "nav" or "div" tag, which will put them on separate lines.
You are on the right track, but you have multiple errors in your code that are causing this issue. Your navbar consisting of "Contrast, Font Size, Download a Brochure" have closing anchor tags but not beginning anchor tags. This navbar is also using a class "accessability" that is not defined in your CSS, which is why it's appearing as an unstyled unordered list.
Here is a simple version of what you are looking for:
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
<nav>
<ul>
<li>Contrast</li>
<li>Font Size</li>
<li>Download a Brochure</li>
</ul>
</nav>
<nav>
<ul>
<li>New Vehicles</li>
<li>Nearly New/Used Vehicles</li>
<li>Motability</li>
<li>Aftercare</li>
<li>Contact Us</li>
</ul>
</nav>
</body>
</html>
This works, you do not need the z-index. You can view it here on codepen https://codepen.io/anon/pen/Rvdgaq
<nav class="navbar navbar-expand-md bg-white navbar-white">
<a class="navbar-brand" href="#">
<img src="assets/logo2.png"height="84px">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="accessability">
<li class="nav-item">
<a class="contrast">Contrast</a>
</li>
<li class="Font-size">Font size</a>
</li>
<li class="download">Download a brochure</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">New Vehicles</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Nearly New/ Used Vehicles</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Motability</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Aftercare</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Us</a>
</li>
</ul>
</div>
</nav>
<nav class="navbar navbar-inverse bg-primary">
<ul>
<li class="nav-item sec-menu">Versa Connect</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item sec-menu">Overview</li>
<li class="nav-item sec-menu">Offers</li>
<li class="nav-item sec-menu">Models</li>
<li class="nav-item sec-menu">Optional Extras</li>
</ul>
</nav>
</div>
</div>
<section id="cover_image">
<div class="container">
<div class="row">
<img src="assets/cover_image.jpg" >
<div class="text-block">
<h1>Versa Connect</h1>
<p>The Ford Torneo Connect is a relaxing and comfortable place to be.
Great to drive, great to sit in, it boasts premium finish, high quality materials
and fuel efficiency without compromising everyday practicality. </p>
<button type="button" class="btn btn-lg btn-primary">Make an enquiry</button>
</div>
</div>
</div>
</section>
A Few things I noticed, 1. You did not close off your section tag so that could be causing issues. And you do not need postion: absolute; on .text-block, take off bottom: 10px;
Make it position relative

Anchor tag in navbar takes whole row - angular

I am trying to make a topbar and a sidebar.
This is the code for my top navbar:
<header>
<nav class="navbar navbar-expand-md fixed-top">
<img src="logo.svg" />
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-right ">
<img src="avatar.png">
<li class="nav-item dropdown ">
<a class="nav-link ">Hello</a>
</li>
</ul>
</div>
</nav>
</header>
And then my sidebar :
<div class="container-fluid">
<nav class="col-sm-3 col-md-2 d-none d-sm-block sidebar">
<ul class="nav nav-pills flex-column">
<li class="nav-item collapsed active" data-toggle="collapse" data-target="#home" >
<a class="nav-link active" href="#"> <img src="homeIcon.png" /> Home <span class="sr-only">(current)</span></a>
</li>
<ul class="sub-menu collapse " id="home">
<li class="nav-item "><a class="nav-link" href="#" > FirstMember</a></li>
<li class="nav-item "><a class="nav-link" href="#"> Second</a></li>
<li class="nav-item "><a class="nav-link" href="#"> Third</a></li>
<li class="nav-item "><a class="nav-link" href="#"> Fourth</a></li>
</ul>
<li class="nav-item">
<a class="nav-link" href="#"><img src="secondElement.png" /> Second Element</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><img src="" /> History</a>
</li>
</ul>
</nav>
<app-home></app-home>
So in app.component.html I am writing my sidebar and navbar, and then is the content.
The issue is that in the topbar.. the where the logo stands, takes the whole row, which then pushes the button and the Hello on the next row.
Only the image inserted is smaller, but when I hover in the a href, it's in the whole row.
How do I fix this ?
And also, every element on the sidebar has an image as an icon, is it better that when the screen gets smaller, the text gets removed and only icons show, or do I make the sidebar appear as a dropdown on the top in smaller screens?
I am using angular5 and bootstrap4.
This is the css :
/* Move down content */
body {
padding-top: 5.5rem;
background-color: #F4F4F4;
}
.navbar {
background-color: #fff;
}
.nav.nav-link a {
color: #;
}
.sidebar {
position: fixed;
top: 69px;
bottom: 0;
left: 0;
z-index: 1000;
padding: 0;
overflow-x: hidden;
overflow-y: auto;
/* Scrollable contents if viewport is shorter than content. */
border-right: 1px solid #eee;
background-color: #
}
.sidebar li{
padding-left: 5px;
}
.sidebar .nav {
margin-bottom: 20px;
}
.sidebar .nav-item {
width: 100%;
}
.sidebar .nav-item+.nav-item {
margin-left: 0;
}
.sidebar .nav-link {
border-radius: 0;
}
.flex-column a {
color: #fff;
}
.dropdown{
font-weight: bold;
color:#;
}
.nav-pills .active{
background-color: ;
font-weight:bold;
}
.nav-pills .nav-link.active {
background-color: ;
color: #1C2058;
}
I am using:
angular/cli: 1.5.0
Angular: 5.0.1
Node:8.9.1
bootstrap: ^4.0.0-alpha.6,
jquery: ^3.2.1,
From your example your anchor isn't using .navbar-brand and instead uses .navbar-left, which if I remember is Bootstrap v3. I can't find navbar-left as a class in v4 documentation:
<a class="navbar-brand" href="#">
<img src="logo.svg" />
</a>
You're also using nav-item for the dropdown, which is also incorrect it should be nav-link dropdown. I would get a new copy of your navbar from the v4 documentation and see if it works when you paste it in.
If it does, but just doesn't work in your application it might be due to ViewEncapsulation so you need to make sure your styles are either globally available (styles.scss) or they are in your navbar components SCSS file (navbar.component.scss or example.component.scss)
All you have left now is to comment out your custom CSS, and paste a fresh copy of the v4 navbar directly from the docs with no changes. That should work immediately. Then slowly start applying the custom changes until it breaks starting with just your branding.

Why is my bootstrap navbar not displaying inline?

Here is my html using bootstrap (I'm sure bootstrap is installed correctly)
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand">Rebar</a>
</div>
<div>
<ul class="nav navbar-nav">
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
</nav>
When it displays the three links are being displayed as block elements.
This is because in Bootstrap the css for li is this:
.nav>li {
position: relative;
display: block;
}
But for me the menu seems to appear correctly. See snippet, but only on a full page. On mobile devices it will behave like a block element since the screen doesn't have room to show them inline.
EDIT: Updated the snippit to work as requested (see comments below this answer)
.navbar .container-fluid>.navbar-header {
float: left;
margin-right: 10px;
}
.navbar .navbar-nav {
float: left;
margin: 5px;
}
.nav>li {
float: left;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand">Rebar</a>
</div>
<div style="display: inline-block;">
<ul class="nav navbar-nav">
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
</div>
</div>
</nav>
Currently on Bootstrap 4. The flex layout seems to be columnar by default in my ecosystem as well.
The most direct override for this use case:
.navbar-nav {
flex-direction: row;
}
Just ran into this issue with BS4. Learned I needed to add navbar-expand-lg class to my nav.
<nav class="navbar navbar-expand-lg">
I'm not saying the other answers are incorrect in any way, but all that is really needed to accomplish the original question is this entry in the subtheme's CSS file:
.nav.navbar-nav li {
float: left;
}
It should be noted that the class(s) before the li will vary depending on selections in the Appearance section of the theme and other factors. For example, right out of the box the class would have been .menu.nav li
I was facing the same problem.
Try this:
.navbar-nav {
display: inline-block;
}
.navbar-nav>li {
display: inline-block;
}
It worked for me
If you want like this way check this DEMO
<nav class="navbar navbar-default navbar-static-top" id="topnavbar">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#top_navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div id="top_navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
Link 1
</li>
<li>
Link 2
</li>
<li>
Link 3
</li>
</ul>
</div>
</div>
</nav>
Currently on Bootstrap 4, the inline navbar can be achieved by adding class "nav-item" on list elements and class "nav-link" on a tags like this:
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand">Rebar</a>
</div>
<div>
<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>
</div>
</nav>
Navbars require a wrapping .navbar with .navbar-expand{-sm|-md|-lg|-xl} for responsive collapsing and color scheme classes.
So if your nav class is like that
change lg to sm or if -sm then change into -lg
You can make an inline navbar easily with this custom CSS class:
Css:
.nav.inline-navbar>li{
display: inline-block;
}
Now use it in your Html:
.....
<ul class="nav navbar-nav inline-navbar">
......
</ul>
.....
For a quuick modify, I add style="display: inline" in the below position:
<div class="collapse navbar-collapse" id="navbarSupportContent" style="display: inline">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#" onclick="toggleContent('single')">One Line Param</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#" onclick="toggleContent('multi')">Multi Line Param</a>
</li>
</ul>
</div>
just simply add this into your CSS and get the elements in one line
.navbar-nav {
display: inline-block;
}
.navbar-nav li {
display: inline-block;
}
In the snippet below, the highlighted line used to be <div class="nav navbar-nav">. In this case, just removing 'navbar-nav' solved the problem to me.
<nav class="navbar fixed-top" id="homehead">
<img class="navbar-brand" src="" height=50 width=50 alt="">
THIS LINE-> <div class="nav">
<a class="nav-item nav-link" href="">Link1<span
class="sr-only"></span></a>
<a class="nav-item nav-link" href="">Link2</a>
<a class="nav-item nav-link" href="">Link3</a>
<a class="nav-item nav-link" href="">Link4</a>
</div>

How to display logo in center at boostrap for mobile device?

I am trying to develop a website using twitter bootstrap. I use a image as logo in navbar using this code
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#"><img class="img-responsive" src="images/bradley.png" alt="" /></a>
</div>
<div>
<ul class="nav navbar-nav">
<li class="home current-page">Swap</li>
<li class="episodes">Tales</li>
<li class="about">About</li>
<li class="contact">Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
It is ok for laptop. But for mobile device and tab i want that logo will be center. Please tell me How can i do that? This is my site https://dl.dropboxusercontent.com/u/168659703/project/index.html
.navbar-header {
margin: 0 auto;
display: table;
/* margin-right: 50px; */ remove this or add margin-right: auto !important;
}
http://jsfiddle.net/L64Pa/
Here's an update for Bootstrap 4 since the original accepted answer is now a broken fiddle.
The flexbox utils that are now included in Bootstrap 4 can be used to responsively change the alignment of content. For example, here the brand is centered on mobile:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="d-flex flex-grow-1">
<span class="w-100 d-lg-none d-block"><!-- hidden spacer to center brand on mobile --></span>
<a class="navbar-brand mx-0" href="#">
Brand
</a>
<div class="w-100 text-right">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#myNavbar">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>
<div class="collapse navbar-collapse flex-grow-1 text-right" id="myNavbar">
<ul class="navbar-nav ml-auto flex-nowrap">
<li class="nav-item">
Link
</li>
<li class="nav-item">
Link
</li>
<li class="nav-item">
Link
</li>
<li class="nav-item">
Link
</li>
</ul>
</div>
</nav>
Demo: https://codeply.com/go/DPyf5WFg99
.navbar-header
{
display:block;
text-align:center;
}
You could do a semi "hack" style CSS in your main.css file with:
#media only screen and (max-device-width: 480px) {
.navbar-brand {
float:none !important;
}
.img-responsive {
margin:0 auto !important;
display:block !important;
}
}