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>
Related
I've been trying to figure this out for a while now but I can't seem to be able to locate the problem. Whenever I click on an option from the navbar, it collapses to mobile size (currently set to 992px in bootstrap so its available on tablets), and then return to original size, which turns out that it has a height of 80px after inspecting it. It used to be fine before, but it has suddenly changed after some code edits. I have included some pictures of the problem below.
HTML:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<!-- Navigation logo and dropdown icon -->
<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="#"><img src="css/logo-dream.png" id="logo"></img></a>
</div>
<!-- Navigation Options -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right" id="nav-appearance">
<li id="main-nav">Home <span class="sr-only">(current)</span></li>
<li id="main-nav">About Us</li>
<li id="main-nav">Services</li>
<li id="main-nav">Gallery</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
Below is the CSS code I have used:
/* Main navbar design */
.navbar {
border-radius: 0px;
opacity: 0.95;
background-color: #171717;
border-bottom: 1px solid #9494b8;
margin-bottom: 0 !important;
}
.navbar .navbar-nav {
margin: 15px 0;
}
/* Navbar company logo */
.navbar-brand {
padding: 0;
}
#logo {
margin-left: 40px;
width: 171px;
height: 66px;
margin-top: 8px;
}
/* Navbar options */
#nav-appearance {
font-size: 1.7rem;
margin-right: 40px;
font-family: 'Quicksand', sans-serif;
}
#nav-appearance li {
padding-left: 35px;
}
.collapse {
padding: 0;
}
.navbar-collapse {
padding: 0;
}
/* ======= MEDIA QUERIES FOR NAVIGATION AND HOME ======= */
/* Tablets */
#media (max-width: 991px) {
#nav-appearance {
font-size: 1.7rem;
margin-right: 10px;
}
#nav-appearance a {
padding: 0;
}
#nav-appearance li {
padding: 15px 0 15px 0;
width: 80%;
transform: translateX(-50%);
top: 0;
left: 52%;
}
#main-nav {
border-bottom: 1px solid rgba(55, 55, 55, .95);
}
#logo {
content:url("home-icon-tiny.png");
height: 34px;
width: 34px;
margin-left: 13px;
}
}
/* Mobile */
#media (max-width: 767px) {
#logo {
margin-left: 13px;
}
}
Can anyone see any issues? I hope it's an easy fix.
Update:
From the page its clear that one of the JS files is interfering with the navbar elements. By setting some CSS we can remove the height change, please find below the CSS.
Codepen: here
CSS:
.navbar-brand img{
margin-top:7px;
margin-bottom:7px;
}
/* Navbar company logo */
.navbar-brand {
padding: 0;
height:100%;
}
HTML:
<!-- Navigation logo and dropdown icon -->
<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="#"><img src="css/logo-dream.png" id="logo"></img></a>
</div>
<!-- Navigation Options -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right" id="nav-appearance">
<li id="main-nav">Home <span class="sr-only">(current)</span></li>
<li id="main-nav">About Us</li>
<li id="main-nav">Services</li>
<li id="main-nav">Gallery</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
From the images given I would say that this is a floating elements not having height issue, the solution for this is the clearfix class. so if you change the code as shown below it should not happen. also I removed the div with container-fluid class.
Code: (Do not use)
<!-- Navigation logo and dropdown icon -->
<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="#"><img src="css/logo-dream.png" id="logo"></img></a>
</div>
<!-- Navigation Options -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right" id="nav-appearance">
<li id="main-nav">Home <span class="sr-only">(current)</span></li>
<li id="main-nav">About Us</li>
<li id="main-nav">Services</li>
<li id="main-nav">Gallery</li>
<li>Contact</li>
</ul>
</div>
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 -->
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">
Basically I am trying to convert the bootstrap navbar into a tool bar. On that toolbar I added some btn-groups with dropdowns which work fine before the media query collapses it. Once it has been collapsed the dropdown-menus cannot be seen, although the element is there and it casts the shadow that it would if it were there. How do I get these drops downs to show up after the collapse?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> INDEX </title>
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="mycss/style.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="datepicker/js/bootstrap-datepicker.js"></script>
</head>
<body>
<nav class="navbar navbar-footer">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#footNav"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="#">Tool Bar</a>
</div>
<div class="collapse navbar-collapse" id="footNav">
<!-- 1st btn-group (No Dropdown) -->
<div class="btn-group" role="group" aria-label="..." style="margin-right: 7px">
<button type="button" class="btn btn-default">Yesterday</button>
<button type="button" class="btn btn-default">Today</button>
<button type="button" class="btn btn-default">Tomorrow</button>
</div>
<!-- 2st btn-group doesn't work after collapse -->
<div class="btn-group" role="group" aria-label="..." style="margin-right: 7px">
<div class="btn-group dropup" role="group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Past
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Past</li>
<li>This</li>
<li>Next</li>
</ul>
</div>
<button type="button" class="btn btn-default">W</button>
<button type="button" class="btn btn-default">M</button>
<button type="button" class="btn btn-default">3M</button>
<button type="button" class="btn btn-default">Y</button>
</div>
<!-- 3rd btn-group doesn't work after collapse -->
<div class="dropup">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Date Range
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
<div class="input-group" style="padding-bottom: 4px;">
<span class="input-group-addon" >From:</span>
<input class="datepicker" style="height: 30px; width:120px; font-size: 18px; padding:10px;" name="startDate">
</div>
<div class="input-group">
<span class="input-group-addon" >To:</span>
<input class="datepicker2" style="height: 30px; width:120px; font-size: 18px; padding:10px;" name="endDate">
</div>
</ul>
</div>
</div>
</nav>
</body>
</html>
I use the standard bootstrap stuff with the exception of the css changes
/*Calendar tool Bar*/
.navbar {
border-radius: 0px;
}
.dropup{
display: inline-block;
}
.dropdown-menu .input-group .input-group-addon:first-child {
width: 63px;
}
.dropdown-menu {
padding: 4px 4px 4px 4px;
min-width: 30px;
}
.navbar-footer {
background-color: #f8f8f8;
border-color: #e7e7e7;
position: fixed;
bottom: 0px;
width: 100%;
margin-bottom: 0px;
vertical-align: middle;
}
.navbar-footer .navbar-toggle:hover,
.navbar-footer .navbar-toggle:focus {
background-color: #ddd;
}
.navbar-footer .navbar-toggle {
border-color: #ddd;
}
.navbar-footer .navbar-toggle .icon-bar {
background-color: #888;
}
button {
margin-top: 8px;
}
You just need to override the bootstrap .navbar-collapse.in class to make it visible even if it overflows vertically.
.navbar-collapse.in {
overflow-y: visible;
}
Working example.
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>