My portfolio page has a sticky navbar, but when I click on the navbar links it overlaps the text in each section. In about, it overlaps the text. In "portfolio" and "about" it overlaps both tiles. I tried to compensate with some padding-top in each section to no avail.
Here is the complete navbar:
<nav class="navbar navbar-toggleable-md navbar-light bg-faded fixed-top" style="background-color: #fc7a57;">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand mr-auto navfont" href="#">portfolio.</a>
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#about"><i class="fa fa-user-circle-o" aria-hidden="true"></i> about</a>
</li>
<li class="nav-item">
<a class="nav-link text" href="#portfolio"><i class="fa fa-picture-o" aria-hidden="true"></i> portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link text" href="#contact"><i class="fa fa-envelope-o" aria-hidden="true"></i> contact</a>
</li>
</ul>
</nav>
And here's the CSS code for one of the sections
#contact {
background-color: #466365;
width: 100%;
height: 100%;
padding-top:50px;
color: white;
}
https://codepen.io/pablovester/pen/ZKJxLL
Thank you guys
First thing wrong I see is you are using ID's to style elements, NO, use class.
You are using ID "portfolio" in more than 1 element while Id should be unique in document.
Anyway to fix your problem just add margin-top: 100px; will be enough
.portfolio {
background-color: #bcd39c;
width: 100%;
height: 100%;
padding-top:50px;
margin-top:100px;
}
and add a class in html
<div id="portfolio" class="portfolio">
and also in other needed IDS.
Hope it helps!
I'm working on this site and did exactly what you are trying to achieve, check it out
Take a look at this HTML source and check if help you. Don't forget to copy all links at CSS and Javascript Settings section.
https://codepen.io/danogliari/pen/gWQWqo
<nav id="myNavbar" class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbarCollapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Daniel Ogliari</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-right" id="navbarCollapse">
<ul class="nav navbar-nav">
<li class="active">About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
My solution to this same problem in Bootstrap 4 is...
.navbar-nav > .nav-item > a {
position: relative;
}
Related
Team,
I am working on responsive where I am getting menu in small size in the mobile mode but not as full width with close button.
Here is my image for the reference.
Here is the jsfiddle
Here is my code
<nav class="navbar navbar-expand-lg navbar-light">
<div class="container">
<a class="navbar-brand" href="#"><img src="images/GEPL-Capital-Logo.webp"></a>
<button class="navbar-toggler" style="margin-right:5px !important;" 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 top_nav" id="navbarSupportedContent">
<ul class="navbar-nav mx-auto ">
<li class="nav-item">
Home
<hr class="hr_nav">
</li>
<li class="nav-item ">About Us
</li>
<li class="nav-item ">Support
</li>
<li class="nav-item ">Contact Us
</li>
</ul>
<ul class="navbar navbar-nav navbar-right" style="display:flex;">
<li>
<button class="btn top_login">
Login
</button>
</li>
<li>
<button class="btn sign_btn">
SignUp
</button>
</li>
</ul>
</div>
</div>
</nav>
Please let me know what I am doing wrong. I am using bootstrap 5.0.2
I removed
.top_nav {margin-left: 204px!important;}
and added
.top_nav {
position: fixed;
top: 0;
width: 100%;
background: #fff;
left: 0;
padding-top: 70px;
z-index: -1;
}
Here is the updated link jsfiddle
UPDATE jsfiddle
link
How to display content above the bootstrap navigation bar. I tried the below code but I got the display content below the navigation bar.
index.html
<body>
<div class="container" id="topContent">Desktop only content above nav..</div>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="#">Start Bootstrap</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-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="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
style.css
#media (max-width: 767px) {
.navbar{
margin-top:0;
top:-65px;
position:relative;
}
#topContent{
margin-top:45px;
}
Assuming you want a fixed Navbar, you would use min-width instead of max-width in the media query...
#media (min-width: 992px) {
.navbar{
margin-top:0;
top:45px;
}
}
Demo 1: https://www.codeply.com/go/l0MAcYsfO2
If you want to avoid the extra CSS, use one of the responsive utility classes. For example, use mt-lg-5 for a top margin that is only applied on desktop (lg and up).
<div class="container" id="topContent">Desktop only content above nav..</div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top mt-lg-5">
<div class="container">
</div>
</nav>
Demo 2: https://www.codeply.com/go/voowMd6pom
Also see: Bootstrap 4 page wide header bar above navbar
Try to remove the class fixed-top in nav class=
HTML
<body>
<div class="container" id="topContent">Desktop only content above nav..</div>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">Start Bootstrap</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-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="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
In CSS try to:
#media (max-width: 767px) {
.navbar{
margin-top: 20px // the size that you want to your div above the navbar
}
#topContent{
top: 0;
position: fixed;
}
Remember in this css you are setting the classes for max-width: 767px so test in this size of screen, let me know with that works :)
In this code,
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
fixed-top class is there. It will make the nav bar fixed at top only
I guess the best way to do this is not to tamper with the Actual bootstrap components as anyone would advise you who has been working with it in the last couple of years.
The easiest way to achieve what you want to do is creating two seperate content boxes inside the Navbar like this:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
HELLOO
</div>
<div class="container">
<a class="navbar-brand" href="#">Start Bootstrap</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
Using two containers inside the navbar will asure you that they will stay on top of each other. This might also tamper with the responsive design but you can single handedly erase the diffrent containers for defined resolutions where you don't want them to appear.
You should not try to use a lot of css here becuase it looks easy. Defining Stuff on the html part is way more efficient and can save you a lot of time later on :)
I am trying to make navbar elements appear on same line. I tried overriding .nav class display to inline:block. but it is not working at all. Please help me fix this problem. This is working on bootstrap 3
HTML
<head>
<title>Samrat Luitel website design </title>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top topnav">
<div class="container-fluid topnav">
<div class="navbar-header">
<a class="navbar-brand topnav" href="#" target="_blank">Samrat Luitel</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
</div>
</div>
</nav>
</body>
CSS
body{
font-family:"Lato";
font-weight:700;
}
.navbar-brand{
color:black;
}
.nav {
display: inline-block;
}
You can use this
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/paper/bootstrap.min.css" />
<head>
<title>Samrat Luitel website design </title>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-fixed-top">
<div class="container topnav">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#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>
<a class="navbar-brand" href="#">Samrat Luitel</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
</div>
</nav>
</body>
Pls add inline-block style to your li, so that you can manage your list items.
.nav li{
display:inline-block;
}
You need to put this css .nav > li {display: inline}
Update your css with below css. Remove display:inline-block; from .nav css rule.
.nav {
float: left;
width: 100%;
}
.nav li {
display: inline-block;
padding: 0 10px;
}
Its difficult to understand the exact problem but i guess if inline is not working try float
.nav > li {float:left:width:30%;}
/* New edit */
Try this one
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse " id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>
I had the same problem and the suggested solutions with adding something like "... display: inline ..." to my stlyes.css file also did not help me (I also use Bootstrap4).
This is what finally helped me
<nav class="navbar navbar-default navbar-expand-sm">
...
</nav>
The important point here is navbar-expand-sm. This says that the nav-bar-items are only stacked vertically when the screen size is smaller or equal to small.
See further explanation here https://www.w3schools.com/bootstrap4/bootstrap_navbar.asp
li {
float:left;
}
ul {
list-style-type:none;
}
How to set the bootstrap 4 navbar height in all viewport to 80px ?
I tried "min-height: 80px" in ".navbar" but the navbar is broken.
The sass code:
$navbar-bg: #26f3fd;
$navbar-height: 80px;
.navbar {
background-color: $navbar-bg;
min-height: $navbar-height;
}
The html code:
<nav class="navbar navbar-toggleable-md navbar-light bg-faded" id="main-navbar" data-toggle="sticky-onscroll">
<button class="navbar-toggler navbar-toggler-left" type="button" data-toggle="collapse" data-target="#navbar-content" aria-controls="navbar-content" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-md-center" id="navbar-content">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="<?= esc_url(home_url('/')); ?>">Accueil</a>
</li>
</ul>
</div>
http://codepen.io/juavenel/pen/xqMPrQ/
The issue is because your navbar doesn't contain a navbar-brand so it's height collapses when the navbar stacks vertically.
This is a known issue that will be fixed in the beta release: https://github.com/twbs/bootstrap/pull/22230
The workaround is to include an empty placehold navbar-text or navbar-brand..
<nav class="navbar navbar-toggleable-md navbar-light bg-faded py-3" id="main-navbar">
<button class="navbar-toggler navbar-toggler-left" type="button" data-toggle="collapse" data-target="#navbar-content" aria-controls="navbar-content" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<span class="navbar-text"> </span>
<div class="collapse navbar-collapse justify-content-md-center" id="navbar-content">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Accueil</a>
</li>
</ul>
</div>
</nav>
http://www.codeply.com/go/FIKesgfDhL
Also, you can use vertical padding (py-3) instead to increase the height of the navbar and keep items vertically centered.
I want a header with a height of 150px which contains a navbar. The navbar should be vertically centered in the header.
HTML:
<header>
<div class="navbar navbar-static-top">
<div class="navbar-inner">
<div class="container" style="background:yellow;">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-th-list"></span>
</a>
<img src="img/logo.png" class="logo" />
<nav class="nav-collapse collapse pull-right" style="line-height:150px; height:150px;">
<ul class="nav" style="display:inline-block;">
<li>Portfolio</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
</div>
</header>
CSS:
header {
width: 100%;
line-height: 150px;
color:red;
height: 150px;
.navbar-inner {
border:0;
border-radius: 0;
background: blue;
padding:0;
margin:0;
height: inherit;
}
}
The nav/menu/vertical list is now in the top right of the header. How do I get it to center vertically? bootstrap.css is uncustomized.
your markup was a bit messed up. Here's the styles you need and proper html
CSS:
.navbar-brand,
.navbar-nav li a {
line-height: 150px;
height: 150px;
padding-top: 0;
}
HTML:
<nav class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img src="img/logo.png" /></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Portfolio</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</nav>
Or check out the fiddle at: http://jsfiddle.net/TP5V8/1/
You need also to set .min-height: 0px; please see bellow:
.navbar-inner {
min-height: 0px;
}
.navbar-brand,
.navbar-nav li a {
line-height: 150px;
height: 150px;
padding-top: 0;
}
If you set .min-height: 0px; then you can choose any height you want!
Good Luck!
For Bootstrap 4, there are now spacing utilities so it's easier to change the height via padding on the nav links. This can be responsively applied only at specific breakpoints (ie: py-md-3). For example, on larger (md) screens, this nav is 120px high, then shrinks to normal height for the mobile menu. No extra CSS is needed..
<nav class="navbar navbar-fixed-top navbar-inverse bg-primary navbar-toggleable-md py-md-3">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
<div class="navbar-collapse collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item py-md-3">Home</li>
<li class="nav-item py-md-3">Link</li>
<li class="nav-item py-md-3">Link</li>
<li class="nav-item py-md-3">More</li>
<li class="nav-item py-md-3">Options</li>
</ul>
</div>
</nav>
Bootstrap 4 Navbar Height Demo
I believe you are using Bootstrap 3. If so, please try this code, here is the bootply
<header>
<div class="navbar navbar-static-top navbar-default">
<div class="navbar-header">
<a class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="glyphicon glyphicon-th-list"></span>
</a>
</div>
<div class="container" style="background:yellow;">
<a href="/">
<img src="img/logo.png" class="logo img-responsive">
</a>
<nav class="navbar-collapse collapse pull-right" style="line-height:150px; height:150px;">
<ul class="nav navbar-nav" style="display:inline-block;">
<li>Portfolio</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
</header>