Bootstrap header/jumbotron background image - html

I'm messing around with Bootstrap for the first time and was struggling to get an image as the background for a header that included the nav and jumbotron. Currently the image I've set isn't showing up and I'm not sure why. If you could point me in the right direction as to where or what needs to change it would be appreciated.
<div class="container header-bg">
<nav class="navbar" role="navigation">
<div class="container">
<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="#">Elliott Davidson</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav pull-right">
<li>About</li>
<li>Pictures</li>
<li>Videos</li>
<li>Sponsors</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="jumbotron">
<div class="container">
<h1>Elliott Davidson</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a></p>
</div>
</div>
</div>
.header-bg {
width:100%;
height:475px;
background: url("img/elliott-davidson-slider.jpg");
background-size:cover;
}
.jumbotron {
color: white;
text-shadow: black 0.3em 0.3em 0.3em;
background: transparent;
}

background: url("../img/elliott-davidson-slider.jpg");
By – Yerko Palma

Try adding "background-image" like so:
.header-bg {
width:100%;
height:475px;
background-image: url("img/elliott-davidson-slider.jpg");
background-size:cover;
}

Related

The height:100% just does not seem to work no matter what element I apply it to [duplicate]

This question already has answers here:
Percentage Height HTML 5/CSS
(7 answers)
Closed 2 years ago.
So I'm in the process of making a very simple landing page using just html and css with bootstrap, and I've been trying to have a background image that covers 100% of the available browser window, and I've tried wrapping it in a class="wrapper" tag and also applying "height:100%" to many different elements but the image just does not extend beyond the last html element in the body.
Edit: spelling
The main markup:
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
PURFFECT MATCH
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Signup</li>
<li>Login</li>
</ul>
</div>
</div>
</nav>
<div class="wrapper">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="centering">
<h1>Purrfect Match</h1>
<h3>Matching felines in need to human caretakers</h3>
<hr>
<button class="btn btn-default btn-lg">Get Started!</button>
</div>
</div>
</div>
</div>
</div>
<script src="https:code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
All the CSS I've applied:
.centering {
text-align: center;
padding-top: 25%;
height: 100%;
}
body {
padding-top: 140px;
height:100%;
}
.wrapper {
height: 100%;
width: 100%;
background: url(https://images.pexels.com/photos/416160/pexels-photo-416160.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940);
background-size: cover;
}
h1 {
height: 100%;
}
what the webpage looks like
In order for height:100% to work, it needs to be in a container with an explicitly defined height (eg: 100px). This can be a distant ancestor if the ancestors between also have percentage heights.
If you want it to be 100% of the viewport, try 100vh instead.
Why not just add it to the body? Like this:
body {
padding-top: 140px;
height:100%;
background: url(https://images.pexels.com/photos/416160/pexels-photo-416160.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940);
background-size: cover;
}
Here's an example:
.centering {
text-align: center;
padding-top: 25%;
height: 100%;
}
body {
padding-top: 140px;
height:100%;
background: url(https://images.pexels.com/photos/416160/pexels-photo-416160.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940);
background-size: cover;
}
.wrapper {
height: 100%;
width: 100%;
}
h1 {
height: 100%;
}
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
PURFFECT MATCH
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Signup</li>
<li>Login</li>
</ul>
</div>
</div>
</nav>
<div class="wrapper">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="centering">
<h1>Purrfect Match</h1>
<h3>Matching felines in need to human caretakers</h3>
<hr>
<button class="btn btn-default btn-lg">Get Started!</button>
</div>
</div>
</div>
</div>
</div>

How to set out the background image of a jumbotron at full size and make it responsive?

I want to make the background image of the jumbotron to have full size without needing to state the height in pixes. Reason for that is that I want it to be responsive. Also I want the image to be underneath the transparent navbar.
You can take a look here
The code for it is:
<nav class="navbar-inner navbar-inverse">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<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="#">Cosmos</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav pull-right">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
<div class="row">
<div class="col-md-12">
<div class="jumbotron" id="first">
<h1 class="text-center" id="h1first">
Welcome to Cosmos<br>
web design
</h1>
</div>
</div>
</div>
The css is:
.navbar-inner {
background:transparent;
}
#first {
background-image: url(http://netdna.webdesignerdepot.com/uploads/2014/07/featured36.jpg);
background-size: cover;
height: 900px;
}
You could use a min-height of 100vh for your hero. And you have to position your navbar absolutely, like this:
https://codepen.io/Sixl/pen/oBrxKr

Twitter Bootstrap Section Scrolling Issue

On my website in development, I have a link in my navbar that should bring me to the section with the id About, however It seems to ignore the positioning of my navbar, thus throwing off the position a tight bit. Any help in resolving this issue would be appreciated
Visualization of the Problem
Before clicking: http://imgur.com/akrheOX
After clicking: http://imgur.com/zlmL6GQ
Navbar Code
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<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 page-scroll" rel="home" href="#" title="Virtual Currency Converter"><img style="max-width:350px; margin-top: -20px;"
src="./assets/img/vicuco_brand.png">
</a>
</div>
<div id="navbar" class="navbar-collapse collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a class="page-scroll" href="#About">About</a>
</li>
<li><span class="glyphicon glyphicon-cog gi-2x"></span></li>
</ul>
</div><!-- nav-collapse -->
</div>
</nav>
About Section Code
<section class="bg-primary" id="About">
<div class="row">
<div class="container">
<div class="row">
<div class=" text-center">
<h2 class="section-heading" id="AboutHeader">About Us</h2>
<div id="AboutSubtitle">
<p>
Vicuco stands for <strong>Virtual Currency Converter</strong>. <br><br>
Indeed, it is our goal to allow for simple and easy conversion <br>
of the virtual currencies among themselves, as well as to foreign currencies. <br><br>
We are an aggregator. That means we aggregate virtual currency <br>
trading data from all major virtual currency exchanges, in order <br>
to show you a near real-time conversion rate. <br><br>
We will send you in the right direction, if you need to buy, sell, or <br>
exchange virtual currency.<br><br>
</p>
<p>
Follow us on <a class="btn btn-social-icon btn-twitter" href="https://twitter.com/vicucodotcom">
<span class="fa fa-twitter fa-2x"></span></a> and check out our
<strong>blog</strong>
for our latest developments!
</p>
</div>
</div>
</div>
</div>
<img src="assets/img/cloud.png" id="cloud" width="25%" height="100%">
</div>
</section>
You are using a fixed header, so it's location and size will be ignored by the other page contents. One method to fix this is to use a little script that does the following:
Detects the navbar height
On navabar item click - scroll the page but offset it from the top of the viewport
The offset is determined by the navbar height we just detected.
You can see it added below.
I say 'one method' because there is an alternate approach where the anchor points can be offset (see here)
$(document).ready(function() {
$(".navbar ul li a[href^='#']").on('click', function(e) {
e.preventDefault();
$('html, body').animate({
scrollTop: $(this.hash).offset().top - $('.navbar').height()
}, 600);
});
});
#one, #two, #three {
height: 1000px;
}
#one {
background: pink;
}
#two {
background: salmon;
}
#three {
background: lightsalmon;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http:////maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<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="#">Offset Scroll</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Section one</li>
<li>Section two</li>
<li>Section three</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<section id="one"></section>
<section id="two"></section>
<section id="three"></section>
</div>
</body>

What is the best way to add some space after Bootstrap navbar?

The following code displays a navbar always on the top of the page.
I need the second container (content) to be positioned at the end of the navbar and not under it.
At the moment second container is under the navbar.
I could add some empty space on the top of the content are, but I am not sure it is a good approach.
Any idea how to solve it?
<div class="container">
<div class="row">
<div class="container">
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
</ul>
<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>
</div>
</nav>
</div>
</div>
<div class="row">
<div ng-view></div>
</div>
</div>
Updated 2018
Bootstrap 3
According to the Bootstrap docs (http://getbootstrap.com/components/#navbar-fixed-top) you should use padding-top on the body..
"The fixed navbar will overlay your other content, unless you add
padding to the top of the . Try out your own values or use our
snippet below. Tip: By default, the navbar is 50px high."
body { padding-top: 70px; }
Demo: http://www.bootply.com/Ob3Bajkv1f
Bootstrap 4
Padding is also recommended for the fixed-top Navbar in Bootstrap 4 to prevent content hiding at the top of the body. You can add custom CSS for padding-top or use the pt-5 utility class on the body tag:
<body class="pt-5"></body>
You would need some CSS like this:
body {
padding-top: 20px;
padding-bottom: 20px;
}
Or like this:
.navbar {
margin-bottom: 20px;
}
Make sure you only use what you need,
Just add margin-top: 50px; to the underlaying container.
50px has to be the height of your navbar.
I was able to solve this issue using the following code.
<div class="container">
<!-- navbar -->
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<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="#">KanbanBoard</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Boards</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>User</li>
</ul>
</div>
</div>
</nav>
<!-- boards -->
<div ng-view></div>
</div>

Bootstrap navbar won't collapse + small buttons

I'm builing a website. This is the portfolio page: www.alweso.2ap.pl/portfolio.html
On all the other pages the navbar collapses on mobile phones, but not on this one. The code for the navbar is exactly the same as on the other pages:
<div class="container">
<div class="row">
<div class="col-md-12">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<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="images/logo-kolor.png" alt="cafeteria" class="logo-kolor"/></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Strona główna</li>
<li>O mnie</li>
<li class="active">Portfolio</li>
<li>Blog</li>
<li>Kontakt</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
</div>
</div>
Also, the buttons on the portfolio page used for filtering the portfolio appear super small on mobile devices. Here's the code:
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="btn-group">
<button type="button" class="btn btn-large filter" data-filter=".wszystko">Wszystko</button>
<button type="button" class="btn btn-large filter" data-filter=".niemowleta">Sesje niemowlęce</button>
<button type="button" class="btn btn-large filter" data-filter=".dzieci">Sesje dziecięce</button>
<button type="button" class="btn btn-large filter" data-filter=".sluby">Sesje ślubne</button>
</div>
</div>
</div>
</div>
CSS:
.btn, .btn-default, .btn:focus, .btn:hover, .btn:active {
margin-left: 0;
margin-right: 20px;
margin-bottom: 30px;
box-shadow: none;
-webkit-box-shadow: none;
border-radius: 0;
border: rgba(255,255,255,0) !important;
}
.btn, .btn-default {
background-color: rgba(0,0,0,0.1);
color: rgba(0,0,0,0.7);
}
If it comes to the navbar, I copy-pasted the code from other pages just to be sure it's exactly the same, but it doesn't help at all and I'm out of ideas. Help extremely appreciated.
On line 6 of html try and change
<meta name="viewport" content="width=device-width, initial-scale=1">
I validated the page in W3C click here to see