I am able to create a full-width image background in Bootstrap 3. An example can be shown here:
body,
html {
height: 100%;
}
body {
padding-top: 50px;
}
.full {
padding: 0 !important;
margin: 0 auto !important;
background-size: cover;
overflow: hidden;
}
.wide {
width: 100%;
height: auto;
}
.logo {
color: #fff;
font-weight: 800;
font-size: 14pt;
padding: 25px;
text-align: center;
}
.line {
padding-top: 20px;
white-space: no-wrap;
overflow: hidden;
text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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="#">Brand</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home
</li>
<li>About
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Username
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
<div class="full" style="background-image:url('https://c.stocksy.com/a/RcN300/z0/805779.jpg');">
<div class="container">
<div class="row clearfix">
<div style="padding: 0 0 200px 0;">
<div class="col-xs-5 line">
<hr>
</div>
<div class="col-xs-2 logo text-center">Logo</div>
<div class="col-xs-5 line">
<hr>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="text-center">
<h1>Content</h1>
</div>
</div>
<!-- /.container -->
When the page displays for Desktop, the image is shown wide covering entire area.
When the page displays for mobile, all the image now shows as if a zoom-out occurred.
What's this behavior? How can I make the image in mobile view look similar to the image displayed in desktop version?
Is this related to responsive imaging?
Thanks
/Bilal
This is caused by the standard behavior of cover. If you resize your desktop browser to a portrait like size, you'll see what I mean.
One option would be to use a media query, so when page is viewed in portrait mode, it will look somewhat better.
body,
html {
height: 100%;
}
body {
padding-top: 50px;
}
.full {
padding: 0 !important;
margin: 0 auto !important;
background-size: cover;
overflow: hidden;
}
.wide {
width: 100%;
height: auto;
}
.logo {
color: #fff;
font-weight: 800;
font-size: 14pt;
padding: 25px;
text-align: center;
}
.line {
padding-top: 20px;
white-space: no-wrap;
overflow: hidden;
text-align: center;
}
#media (orientation: portrait) {
.full {
background-size: 200% auto;
background-position: top right;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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="#">Brand</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home
</li>
<li>About
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Username
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
<div class="full" style="background-image:url('https://c.stocksy.com/a/RcN300/z0/805779.jpg');">
<div class="container">
<div class="row clearfix">
<div style="padding: 0 0 400px 0;">
<div class="col-xs-5 line">
<hr>
</div>
<div class="col-xs-2 logo text-center">Logo</div>
<div class="col-xs-5 line">
<hr>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="text-center">
<h1>Content</h1>
</div>
</div>
<!-- /.container -->
Related
I have a problem in my css. I want to make my navbar like this ( as you can see, it has no background on navbar and it joins with slider ). I have tried every advice in youtube tutorials but nothing worked.
Here's the link I want to show you:
http://theme.ridianur.com/alamak/
I was able to change the color background of my navbar by opening bootstrap.min.css in notepad, search for "navbar-default", and change the color code. But, I wasn't able to make it no background like I want to.
My html :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="boot/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>Image Slider</title>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<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>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>HOME</li>
<li>NEWS</li>
<li>ABOUT</li>
<li>CONTACT US</li>
</ul>
<div class="logo">
<img src="kets.png">
</div>
</div>
</nav>
<div class="container-fluid hero-slide">
<div class="row">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="img/1.jpg" alt="Cats1">
<div class="carousel-caption">
<div class="tekslide1">
<h1>Hewan yang mainstream</h1>
<p>Kita juga gatau kenapa milih topik kucing</p>
</div>
</div>
</div>
<div class="item">
<img src="img/2.jpg" alt="Cats2">
</div>
<div class="item">
<img src="img/3.jpg" alt="Cats3">
</div>
<div class="item">
<img src="img/4.jpg" alt="Cats4">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
</body>
</html>
and my css :
#charset "utf-8";
#font-face{
font-family: 'custom';
src: url('OpenSans-Regular.ttf') format('truetype'); //<-- semicolon
}
#font-face{
font-family: 'custom1';
src: url('Alternate.ttf') format('truetype'); //<-- semicolon
}
#media (min-width: 768px){
.navbar .navbar-nav{
display: inline-block;
float: none;
vertical-align: top;
font-family: 'custom';
letter-spacing: 5px;
padding-top: 12px;
margin-bottom: -20px;
}
.tekslide1{
font-size: 25px;
padding-left: 300px;
padding-bottom: 500px;
font-family: 'custom1';
}
.navbar .navbar-collapse{
text-align: right;
padding-right: 120px;
}
.navbar-default .navbar-collapse .nav >li >a {
color: #EEEEEE;
margin-left: 10px;
margin-right: 5px;
font-size: 13px;
}
.navbar-default .navbar-collapse .nav >li >a:hover, .navbar-default .navbar-collapse .nav >li >a:focus{
color: #BDBDBD;
background: none;
}
.logo{
float: left;
padding: 2px;
margin: 2px;
margin-bottom: -15px;
margin-left: 5%;
border: none;
border-radius: 100px;
}
.hero-slide{
margin-top: -20px;
}
.navbar li { color: #000 }
Any help would be appreciated. Thanks!
I'll explain this in pseudocode. If you want help you need include relevant bits of html and css in your post, not the archive of an entire site.
This effect you're looking for is nothing more than:
<div class="wrapper">
<div class="navigation">
</div>
<div class="banner">
</div>
</div>
and
.wrapper{background:url('your_image.jpg');}
.navigation, .banner{background:transparent;}
A graphic applied to a parent container and navigation / banner with transparent backgrounds.
Im in the process of learning bootstrap and developing my first website by im having a really annoying issue trying to get a background color or image display behind my transparent navigation.
This is my html code so far
<body>
<header>
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapse">
<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="#featured"><img id="main-logo" src="img/logo.svg"/></a>
</div><!-- end of navbar-header -->
<div class="collapse navbar-collapse" id="collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</div><!-- end of collapse navbar-collapse -->
</div><!-- end of container -->
</nav><!-- end of navigation -->
</header>
<div class="top-section">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="name">
<img id="name-text" src="img/text.svg"/>
</div>
</div>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
This is my current css stylesheet
body {
position: relative;
}
/*--Navigation--*/
.navbar-default {
background-color: transparent;
border: none;
}
.nav li a {
margin-top: 30px;
}
#main-logo {
float: left;
}
/*--Top Section--*/
.top-section {
background-color: #7ecaeb;
margin-top: 80px;
position: relative;
background-position: center;
background-size: cover;
}
.name {
text-align: center;
float: none;
}
#name-text {
width: 300px;
height: auto;
}
What i really want to try and do is just have the background on the class .top-section (either color or picture depending on what i go for) go behind the nav.
Im sure im just being a bit stupid here but i cant for the life of me see what im doing wrong, im still learning this so its quite new to me.
Thanks everyone
Problem: space between .nav and .jumbotron in bootstrap.
what did I do: override the bootstrap.css , override .jumbotron{margin-bottom:0px}, it's not working.
What I've found: it works well when I debug it in the original file.
couldn't work in override css file
work well in original file
HTML:
<body>
<div class="header">
<div class="top-header">
<div class="jumbotron">
<img src="image/name.png" alt="">
<h2>Curiosity Creative</h2>
</div><!--Jumbotron-->
</div><!--top-header-->
<nav class="navbar navbar-default">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#displayItem" 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>
</div><!--navbar-header-->
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="displayItem">
<ul class="nav nav-tabs">
<li class="home active">
<i></i> Home</li>
<li class="me">
<i></i>AboutMe</li>
<li class="blog">
<i></i>Blog</li>
<li class="contact">
<i></i>Contact</li>
</ul>
</div> <!-- collapse navbar-collapse-->
</div><!--container -->
</nav><!--nav-->
</div>
CSS:
*{
margin: 0;
padding: 0;
}
body{
background: url("../image/body_bg.jpg");
overflow: scroll;
}
div{
position:relative;
}
.top-header{
background-color: white;
}
.jumbotron {
background-color:transparent !important;
text-align: center;
margin-bottom:0px;
}
.jumbotron img{
width: 400px;
}
.jumbotron h2{
color: #aaa;
font-size: 13px;
font-family: verdana;
}
It looks to me like maybe you've included your "index.css" before the "bootstrap.css". If that is correct, swap them around so that your "index.css" is loaded last, not first.
eg;
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/index.css" rel="stylesheet">
I'm trying to figure out how to make the above code behave well on displays > 768px and < 768px. Right now is working fine for resolutions below 768px, but I can't make it work for resolutions above that.
That's the what I'm trying to do:
Resolution above 768px - Full page (search box with 100% remaining width):
Resolution below 768px (only search box visible):
Code:
.navbar .navbar-form {
padding: 0;
margin-right: 0;
margin-left: 0;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.clear {
width: 1%;
display: table-column;
}
#media(max-width:767px) {
.navbar .navbar-form {
padding-left: 15px;
padding-right: 0;
}
.navbar .navbar-form .input-group {
padding-right: 15px;
}
.navbar .navbar-form .form-control {
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#navbar-collapse">
<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 hidden-xs" href="/">Title</a>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for..."/>
<span class="clear hidden-sm hidden-md hidden-lg"></span>
<span class="input-group-btn hidden-xs">
<button class="btn btn-default" type="button">Go!</button>
</span>
</div>
</div>
</form>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li>Webpage 1</li>
<li>Webpage 2</li>
</ul>
</div>
</div>
</nav>
Whew, you have yourself a nasty little problem here. It took me a while, but I think I've gotten you a solution together.
First, you need to do the following:
Add display: inline to your form-group
Add display: table to your input-group
Add width: 1% to your input-group-btn
These changes are from this issue here (what you want, but keeps the search bar inside the collapse menu) - Bootstrap 3 - How to maximize input width inside navbar
The next changes you need to make are for when you are above the 768px breakpoint, otherwise it will mess up your collapse menu.
#media(min-width:768px) {
.container-fluid {
display: flex;
}
.navbar-header {
flex: 1;
}
}
Lastly, you need to remove navbar-right from your navbar-form.
Here is a JSFiddle - An embedded snippet is also included.
.navbar .navbar-form {
padding: 0;
margin-right: 0;
margin-left: 0;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.clear {
width: 1%;
display: table-column;
}
#media(max-width:767px) {
.navbar .navbar-form {
padding-left: 15px;
padding-right: 0;
}
.navbar .navbar-form .input-group {
padding-right: 15px;
}
.navbar .navbar-form .form-control {
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
}
#media(min-width:768px) {
.container-fluid {
display: flex;
}
.navbar-header {
flex: 1;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#navbar-collapse">
<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 hidden-xs" href="/">Title</a>
<form class="navbar-form" role="search">
<div class="form-group" style="display: inline">
<div class="input-group" style="display: table">
<input type="text" class="form-control" placeholder="Search for..."/>
<span class="clear hidden-sm hidden-md hidden-lg"></span>
<span class="input-group-btn hidden-xs" style="width: 1%">
<button class="btn btn-default" type="button">Go!</button>
</span>
</div>
</div>
</form>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li>Webpage 1</li>
<li>Webpage 2</li>
</ul>
</div>
</div>
</nav>
I have the following CSS code, and my problem is that my
nav bar comes on top of my header block. How can I move
the nav bar straight down from the header?
header {
background: black;
height: 60px;
left: 0;
margin: 0;
padding: 0;
position: absolute;
width: 100%;
}
header img {
float: left;
margin-right: 10px;
position: relative;
}
header h1 {
color: white;
font: 26px Helvetica, Arial, sans-serif;
line-height: 60px;
margin: 0;
vertical-align: middle;
}
nav {
background: black;
margin: 0;
padding: 0;
position: absolute;
width: 100%;
}
give the nav a margin-top that is the same height of your navbar.
nav {
background: black;
margin: 0;
margin-top:60px;
padding: 0;
position: absolute;
width: 100%;
}
#H.A; you give position absolute to your header block & nav block . So, when you give position absolute to an element then the element remove for the normal flow
CSS:
nav {
top:60px;
padding: 0;
position: absolute;
width: 100%;
}
Read this article for more http://css-tricks.com/791-absolute-positioning-inside-relative-positioning/
<!DOCTYPE html>
<html >
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<style>
.navbar-fixed-top{
position:static;
}
</style>
</head>
<body>
<div class="row">
<div class="col-lg-12">
<div class="intro-message">
<h1>HOST</h1>
<h3>two is better than one</h3>
<hr class="intro-divider">
<ul class="list-inline intro-social-buttons">
<li>
<i class="fa fa-twitter fa-fw"></i> <span class="network-name">Twitter</span>
</li>
<li>
<i class="fa fa-github fa-fw"></i> <span class="network-name">Github</span>
</li>
<li>
<i class="fa fa-linkedin fa-fw"></i> <span class="network-name">Linkedin</span>
</li>
</ul>
</div>
</div>
</div>
</div>
<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
<div class="container topnav">
<!-- 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 topnav" href="/">Host</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
Login
</li>
<li>
Sign up
</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
</body>
</html>