I'm fairly new to bootstrap and having a hard time trying to get my jumbotron background image to scale properly without showing the white background. I'm using Bootstrap Fixed Nav at the top of the page, Jumbotron (bg image) in the middle, and Sticky Footer. When I test in google chrome to see if the layout is correct, it seems that the image doesn't stretch down to the top of the footer, which shows the white background. How can I get the background image to scale properly for all devices?
HTML:
<!-- Fixed navbar -->
<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="index.html">Jason<span>Murray</span></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="jumbotron">
<div class="container">
<h1 class="text-center">Front-End Web Developer</h1>
<p class="text-center">I'm Jason Murray, Front-End Web Developer who loves to write clean codes and build simplistic web designs.</p>
<p class="text-center"><a class="btn btn-primary btn-lg" href="#" role="button">Recent Work</a></p>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="text-center">Copyright © 2016 Jason Murray Web Design. All Rights Reserved</p>
</div>
</footer>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
CSS:
.jumbotron {
background: url("../img/lucho-49.jpg") no-repeat center center;
-webkit-background-size: 100% 100%;
-moz-background-size: 100% 100%;
-o-background-size: 100% 100%;
background-size: 100% 100%;
}
There is a margin bottom to this jumbotron class, so remove margin:
.jumbotron {
margin-bottom: 0;
}
Here is the fiddle: fiddle link
The image is not stretched down to the top of the footer is because of jumbotron's predefined property margin-bottom: 30px;.
In your CSS code do the following changes:
nav + .jumbotron {
margin-bottom: 0;
background: url("../img/lucho-49.jpg") no-repeat center center;
-webkit-background-size: 100% 100%;
-moz-background-size: 100% 100%;
-o-background-size: 100% 100%;
background-size: 100% 100%;
}
If you add margin-bottom: 0; in your .jumbotron selector it won't work due to specificity. Hence I've increased the specificity by adding Adjacent Sibling Selector, nav + .jumbotron to override your CSS properties with the predefined bootstrap's .jumbroton CSS properties.
Related
HTML:
<!-- Static navbar -->
<nav class="navbar navbar-default navbar-static-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="#">Project</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="jumbotron jumbotron-fluid vertical-center">
<div class="container">
<h1 class="display-3">TITLE</h1>
<p class="lead">This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
<hr class="my-4">
<p>Description text</p>
<p class="lead">
<a class="btn btn-primary btn-lg btn-jumbotron" href="#" role="button">Learn more</a>
</p>
</div>
</div>
<div class="container">
</div> <!-- /container -->
CSS:
.navbar{
padding: 7px 0;
margin-bottom: 0;
}
.jumbotron {
background-image: url(http://cdn.wallpapersafari.com/97/93/UE7u4i.jpg);
background-size: cover;
color: white;
margin: 0;
}
.vertical-center {
min-height: 100%; /* Fallback for browsers do NOT support vh unit */
min-height: 100vh; /* These two lines are counted as one :-) */
display: flex;
align-items: center;
}
.btn-jumbotron{
background-color: black;
border-color: white;
}
I'm trying to have a jumbotron have full height of the browser's window, but without the height of the static navbar. I did get it to size of full viewport by using height: min-height:100vh amnd center it, but as you can see from the jsfiddle example I have a scrollbar present because of the navbar's height - 64px.
How can I remove that?
https://jsfiddle.net/iDaniel19/12qxmkjt/
Use calc
.vertical-center {
min-height: 100%; /* Fallback for browsers do NOT support vh unit */
min-height: 100vh; /* These two lines are counted as one :-) */
min-height: calc(100% - 64px); /* */
min-height: calc(100vh - 64px); /* */
display: flex;
align-items: center;
}
Add to .navbar position: absolute; top: 0; width: 100%; and padding-top:64px; to .jumbotron
I would like to make one page scroll. Nav bar. Then a full width picture. than about me page, porfolio / projects and contact me. But it seems like am doing something wrong with the layout. Please help.
.navbar {
min-height: 80px;
margin-bottom: 0;
}
#btnnavbar {
margin-top: 20px;
}
#btnhome {
margin-top: 16px;
}
#imgbrand {
margin-top: -70px;
margin-left: px;
height: 220px;
width: 280px;
}
#firstpage {
margin-top: 90px;
}
.fixed-bg {
/* The background image */
background-image: url("http://res.cloudinary.com/ekilja01/image/upload/v1478095932/DeathtoStock_Lonely_Commute-05_ricqva.jpg");
/* Scale the background image to be as large as possible */
background-size: cover;
min-height: 100%;
min-width: 1024px;
/* Set up proportionate scaling */
width: 100%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0;
left: 0;
}
<html>
<head>
</head>
<body>
<!-- Navbar style available in Bootstrap framework-->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- /end-->
<!-- Anything that has to be responsive we are going to keep inside the Bootstrap grid -->
<div class="container-fluid">
<!-- /end -->
<div class="navbar-header">
<button type="button" class="navbar-toggle btn-lg" data-toggle="collapse" data-target=".navbar-collapse" id="btnnavbar">
<!-- For screen readers only -->
<span class="sr-only">Toggle navigation</span>
<!-- /end -->
<!-- Hamburger menu button appears when browser window has been shrinked -->
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- /end -->
<!-- Brand and toggle get grouped for better mobile display -->
<a class="navbar-brand " href="http://codepen.io/ekilja01">
<img class="img-responsive" id="imgbrand" src="http://www.kiljakandweb.com/favicon.png" alt="brand logo">
</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li id="btnhome">About
</li>
<li id="btnhome">Portfolio
</li>
<li id="btnhome">Contact
</li>
</ul>
</div>
</div>
</div>
</nav>
<div class="fixed-bg">
<div class="row">
<div class="col-lg-10 col-lg-offset-1 text-center">
<h1 class="text-center">1.4.1.3</h1>
<p>fafafa</p>
<div>
</div>
</div>
<div class="row">
<div class="col-lg-10 col-lg-offset-1 text-center">
<h1>Code</h1>
</div>
</div>
</body>
</html>
No matter how many times I've changed my folder and file names, made sure they are relative paths, etc., I can't seem to have my background image appear in my Jumbotron.
I just want it to show up behind in my Jumbotron DIV, but it's not.
Here's my HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Mock Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style1.css">
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- LOGO -->
<div class="navbar-header">
<!-- BUTTON FOR MENU ITEMS AS IT SHRINKS -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mainNavBar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
Mock Website
</div>
<!-- COLLAPSE MENU ITEMS -->
<div class="collapse navbar-collapse" id="mainNavBar">
<!-- MENU ITEMS -->
<ul class="nav navbar-nav navbar-right">
<li class="active">HOME</li>
<li>ABOUT</li>
<!-- DROP DOWN MENU -->
<li class="dropdown">
PORTFOLIO <span class="caret"></span
<ul class="dropdown-menu">
<li>PHOTOS</li>
<li>VIDEOS</li>
<li>MUSIC</li>
</ul>
</li>
<li>CONTACT</li>
</ul>
</div>
</div> <!-- Container Fluid -->
</nav> <!-- Nav -->
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container">
<h1>Navbar example</h1>
<p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p><a class="btn btn-lg btn-primary" href="#" role="button">View navbar docs »</a>
</p>
</div> <!-- CONTAINER -->
</div> <!-- JUMBOTRON -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Here's my CSS:
/* NAVBAR */
.navbar {
margin-bottom: 0px;
border-radius: 0px;
}
/* JUMBOTRON */
.jumbotron {
background-color: ;
background-image: url("/images/blue.jpg");
background-repeat: no-repeat;
background-size: cover;
color: #FFF;
}
.dropdown li {
text-align: right;
}
Change and condense your CSS from background-image to just background to keep things nice and clean.
e.g. background: url(/images/blue.jpg) cover no-repeat;
The code itself looks functional though. Is image in the same directory? Perhaps reviewing this post will help: Links not going back a directory?
Check the permissions on the folder where the images are being stored. Your code is correct, check this working fiddle with an external image url working perfectly:
/* NAVBAR */
.navbar {
margin-bottom: 0px;
border-radius: 0px;
}
/* JUMBOTRON */
.jumbotron {
background-color: ;
background-image: url("http://vignette2.wikia.nocookie.net/p__/images/0/0c/Superman%27s_classic_pose.png/revision/latest?cb=20131218234907&path-prefix=protagonist");
background-repeat: no-repeat;
background-size: cover;
color: #FFF;
}
.dropdown li {
text-align: right;
}
<!-- LOGO -->
<div class="navbar-header">
<!-- BUTTON FOR MENU ITEMS AS IT SHRINKS -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mainNavBar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
Mock Website
</div>
<!-- COLLAPSE MENU ITEMS -->
<div class="collapse navbar-collapse" id="mainNavBar">
<!-- MENU ITEMS -->
<ul class="nav navbar-nav navbar-right">
<li class="active">HOME</li>
<li>ABOUT</li>
<!-- DROP DOWN MENU -->
<li class="dropdown">
PORTFOLIO <span class="caret"></span
<ul class="dropdown-menu">
<li>PHOTOS</li>
<li>VIDEOS</li>
<li>MUSIC</li>
</ul>
</li>
<li>CONTACT</li>
</ul>
</div>
</div> <!-- Container Fluid -->
</nav> <!-- Nav -->
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container">
<h1>Navbar example</h1>
<p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p><a class="btn btn-lg btn-primary" href="#" role="button">View navbar docs »</a>
</p>
</div> <!-- CONTAINER -->
</div> <!-- JUMBOTRON -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
I am having an issue with my CSS at the moment and I can't seem to figure out how to fix the issue, I tried researching this problem but I couldn't really put into words how I would describe my situation.
Basically I have set the body to 100% height so that it acts as the parent for any child attribute that may set. the main goal that I am trying to achieve is to have the background image of my div to fill the rest of the page without extending it and creating an scroll overflow. However instead its overflowing and extending the body height and creating an overflow, which you can see in my screenshot below:
my html code is as follows
<body>
<nav class="navbar navbar-default">
<div class="container center-nav">
<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="#">MC</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>About Me</li>
<li>Gallery</li>
<li>Videos</li>
</ul>
</div>
</div>
</nav>
<div class="main-body">
<div class="main-wrapper">
</div>
</div>
My CSS
html{
height: 100%;
min-height: 100% !important;
}
body{
height: 100%;
min-height: 100% !important;
margin: 0;
}
.navbar.navbar-default{
margin-bottom: 0px;
border-radius: 0px;
}
.main-body{
height: 100%;
}
.main-wrapper{
height: 100%;
background: url("../images/test.jpg");
background-size:cover;
}
You've made .main-wrapper 100% the height of its parent. If body is 1000px, .main-wrapper will be as well. Since you also have another item in the body, it's pushing your main wrapper down.
Use height: calc(100% - [the height of the nav])
Ok, So I am creating a website with Bootstrap and I have run into an issue. I have placed an image in the nav bar in the logo and then I go to resize the browser to force mobile layout. When I get to where the image should start re-sizing, it drops below (or above) the menu toggle before re-sizing.
I have even tried adding .img-responsive to it but that is no help.
Here is an image of what I am talking about:
And here is my code:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img src="http://lorempixel.com/300/40/" class="img-responsive" alt="LOGO"></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container">
<div class="text-center">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
</div>
</div><!-- /.container -->
Any help would be appreciated
Thanks.
There are several ways to solve this. You can use media queries to set max-width or percentage width to .navbar-brand.
The clearest solution might be to use CSS3 calc to make it take 100% width minus the space that the menu button is taking (22px width + 20px of padding + 2px of border + 15px of margin = 59px total space). And because your image is pushed down at 390px screen width, your media query should be:
#media (max-width: 390px) {
.navbar-brand {
width: calc(100% - 59px);
}
}
Check the JSFiddle with the result.
My other answer might help you as well.