This looks great:
http://imageshack.us/a/img96/5789/n4u7.png
But when you shrink another 5 pixels, the columns appear to break and the image goes to a new line.
http://imageshack.us/a/img59/2195/uk4v.png
Instead, I would like the image to shrink, so it can stay on the same line as the collapsible button.
The HTML:
<!-- navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<!-- container -->
<div class="container">
<!-- navbar header -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-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="#">
<img class="img-responsive" src="assets/img/logo.png" >
</a>
</div>
<!-- /navbar header -->
<!-- collapse -->
<div class="collapse navbar-collapse navbar-ex1-collapse navbar-right">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Services</li>
<li>About</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</div>
<!-- /collapse -->
</div>
<!-- container -->
</nav>
<!-- /navbar -->
The CSS:
nav.navbar {
padding-top: 0;
padding-bottom: 0;
background: rgba(179, 153, 255, .5)
}
nav.navbar div.container {
background: rgba(179, 153, 255, 1.0);
border: 1px solid black;
}
a.navbar-brand {
padding: 0 0 20px 15px;
}
img.img-responsive {
width: 100%;
}
#media (min-width: 992px) {
ul.navbar-nav li a {
padding-top: 12px;
padding-bottom: 12px;
border-top: 2px solid white;
border-bottom: 2px solid white;
margin-top: 36px;
}
}
If you want the image to shrink when you make the viewport smaller, the width of the image's containing element needs to be set as a percentage. In this case the image's immediate containing element is the anchor, so if you set that anchor width of 60% or whatever works, then when the viewport shrinks, the anchor width will shrink to maintain its 60% of its container, and the image with its width of 100% of the anchor will also shrink. Anchor will need to have block level display too.
Related
I need to do a responsive navbar with:
LOGO1(left side) text(centered) LOGO2(right side)
I am trying the next but It doesnt work when when resized to small screens.
Here is my problem: when in "lg" size the screen is correct. But when in "md" size or smaller the LOGO2 goes to left side.
And, in 'xs' size the 'text' continues showing with the LOGO2 below it.
In my markup code I have some angular staff, but it is not important to answer the question.
What am I doing wrong?
//markup
div class="container-fluid example2">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" ng-click="isMyNavCollapsed = !isMyNavCollapsed" ng-init="isMyNavCollapsed=false">
<span class="sr-only">Navegação</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand"><img src="img/SoundCloud64.png" alt="Cloud Clínica">
</a>
</div>
<p class='navbar-text navbar-center font35'><strong>Retire seu ticket aqui</strong></p>
<div class="collapse navbar-collapse" id="navbar_right" uib-collapse="isMyNavCollapsed">
<ul class="nav navbar-nav navbar-right">
<li><img class="img-responsive" height="150" width="200" src="img/red-ticket-md.png" /></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
</div>
//css
<style type="text/css">
.example2 .navbar-brand>img {
padding: 7px 15px;
}
.navbar-right img{
padding: 7px 15px;
}
.navbar-center
{
display:inline-block;
position: absolute;
width: 100%;
left: 0;
top: 0;
text-align: center;
overflow: visible;
height: 0;
padding:15px 10px 10px 10px;
z-index: 10099;
}
.navbar-nav,
.navbar-right {
display:inline-block;
position: relative;
z-index: 100100;
}
</style>
This question already has answers here:
Mysterious whitespace in between Bootstrap2 Navbar and row underneath
(2 answers)
Closed 5 years ago.
I am creating a website with bootstrap, and I encountered a problem when I created a featured image with a parallax effect. It seems that something is creating a space between the navigation bar (Bootstrap) and the featured image.
.parallax {
background-image: url("../images/aboutHeader.jpg");
height: 100%;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.parallax h2 {
color: white;
font-size: 4em;
text-align: center;
padding-top: 100px;
}
<!-- NAVBAR
================================================== -->
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img src="images/headerWhite.png" alt="Bird's Aerial Imaging LC" style="height:100%">
</a>
</div>
<div class="collapse navbar-collapse navbar-right" id="myNavbar">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="active">About</li>
<li>Gallery</li>
<li>Services</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
<!-- FEATURED IMAGE =============================================================== -->
<section style="height:250px;">
<div class="parallax">
<h2>About Us</h2>
</div>
</section>
What I understood from you that you mean the white vertical space between the parallax div and the navbar and my answer will depend on that, if your problem is different please let me know.
Your solution is all about removing:
1) The margin property from the "h2":
.parallax h2 {
margin-top: 0;
}
2) The padding property from the "navbar":
.navbar {
padding-bottom: 0;
}
Hope it works with you!
You can add position:absolute; top:0; to your section tag. That will definitely remove the space...
It could also be because of default margin or padding around the section. Try to add margin:0; padding:0; to that
Basically I am trying fix a header area to the top of all pages that require a header. The idea is to use a div with a class that can be applied when needed.
I have attempted a basic fixed div, however I always end up with it overlapping the content. Can anyone explain/show some css to float a div at the top of the body pushing all content down.
It should also be fixed, so scrolling would only affect content below.
My attempts have left me with the following:
As you can see the Applications title overlaps the table, when all other content should be floated down.
You would apply fixed positioning to the div in question, then add padding-top to the body to push it down from the top. Bootstrap achieves this affect by adding padding-top to the body element for the navbar component in combination with the .navbar-fixed-top CSS class. Otherwise you can apply padding-top or relative positioning position: relative; to the content element.
.topbar-fixed {
position: fixed;
top: 0;
left: 0;
width: 100%
}
.body {
padding-top: 50px; /* height of fixed bar */
}
/* OR */
.content-element {
position: relative;
top: 50px;
}
With the below code you can fix navbar to top.
HTML
<nav id="header" class="navbar navbar-fixed-top">
<div id="header-container" class="container navbar-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 id="brand" class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" 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><!-- /.container -->
</nav><!-- /.navbar -->
CSS
html,
body {
overflow-x: hidden; /* Prevent scroll on narrow devices */
}
body {
padding-top: 100px;
}
footer {
padding: 30px 0;
}
In a Bootstrap nav-bar, I'm trying to create two items whose drop-shadows intersect each other.
http://codepen.io/anon/pen/gaEJWY
It currently looks like this:
But I want it to look like this:
Anyone have an idea how to make this happen(using CSS preferably)?
.navbar-inner {
box-shadow: 0px 4px 8px #888888;
}
.navbar-brand {
background: #F8F8F8;
width: 160px;
height: 160px;
border-radius: 50%;
position: absolute;
box-shadow: 0px 10px 8px #888888;
margin-top: -25px;
padding-top: 29px;
padding-left: 29px;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- Always force latest IE rendering engine or request Chrome Frame -->
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<!-- Use title if it's in the page YAML frontmatter -->
<title>My Product</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700' rel='stylesheet' type='text/css'>
<link href="/stylesheets/all.css" rel="stylesheet" />
<script src="/javascripts/all.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top">
<div class="navbar-inner">
<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="#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="//placehold.it/100x100">
</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 navbar-right">
<li class="active">Store Locator</li>
<li>Share</li>
<li>Cocktails</li>
<li>Shop</li>
<li>Blog</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</div>
</nav>
<!--<div class="container">-->
<!--<img src="images/header-video.jpg">-->
<!--</div>-->
</body>
</html>
Many thanks!
You can create a pseudo element that will be behind your circle with the same color and height as the navbar.
You have to do the maths on the positioning, but it works.
.navbar-brand:before{
/* bigger than the circle to mask the shadow 1*/
width:200px;
/* same height as navbar */
height:50px;
content:".";
overflow:hidden;
text-indent:99999px;
display:block;
background: #F8F8F8;
position: absolute;
/* cause your div has margin -25px */
top:25px;
/* so it will mask everything on the sides */
left:-15px;
}
.navbar-brand > * {
/* everything inside the navbar brand need to have its positioning set */
position: relative;
}
Pen
Following this example from the official documentation, i noticed that on pages who are going to be < 2000px in height, i will have a lot of white space below the footer.
I can't specify the height of the footer as per this example (it might increase dynamically) so i guess i can't stick it to the footer?
How to work around this?
Use the Boostrap's sticky footer, and for the height of Footer, use this jquery, it checks height of footer and adds it to the html tag.
It runs on page load as well as on Window.resize event, so it works great for Responsive projects.
$(document).ready(function(){
$(window).resize(function(){
$("html").css("padding-bottom",$(".footer").outerHeight())
}),
$("html").css("padding-bottom",$(".footer").outerHeight()
);
});
What actually makes the footer stick to the bottom of the page in the example you are linking to in your comment is not the footer height, but the following CSS rules:
.footer {
position: absolute;
bottom: 0;
}
You can see this for yourself if you view the footer through your browser's developer tools and disable the height CSS rule, the footer will continue to be at the bottom of the page.
As far as the body margin is concerned, since your footer does not have a fixed height the only way you can set this is use Javascript to measure the footer and set the body margin on document.ready. See the attached example:
$(document).ready(function(){
var footerHeight = $('.footer').height();
$('body').css('margin-bottom', footerHeight);
});
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
/* Custom page CSS
-------------------------------------------------- */
/* Not required for template or sticky footer method. */
body > .container {
padding: 60px 15px 0;
}
.container .text-muted {
margin: 20px 0;
}
.footer > .container {
padding-right: 15px;
padding-left: 15px;
}
code {
font-size: 80%;
}
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
<!-- 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="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<!-- Begin page content -->
<div class="container">
<div class="page-header">
<h1>Sticky footer with fixed navbar</h1>
</div>
<p class="lead">Pin a fixed-height footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS. A fixed navbar has been added with <code>padding-top: 60px;</code> on the <code>body > .container</code>.</p>
<p>Back to the default sticky footer minus the navbar.</p>
</div>
<footer class="footer">
<div class="container">
<p class="text-muted">Place sticky footer content here.</p>
</div>
</footer>