Sticky top navbar without having the logo resize - html

I have the following code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="row">
<nav class="col-sm-6">
<span class="pull-left">
<a href="#" class="navbar-left">
<img src="img/gyn.png" alt="" class="logo">
</a>
</span>
</nav>
<nav class="col-sm-6">
<span class="pull-right">
<ul class="nav navbar-nav thmbl">
<li><a class="tupac" href="#team"><strong>TEAM</strong></a></li>
<li><a class="tupac" href="#services"><strong>SERVICES</strong></a></li>
<li><a class="tupac" href="#gal"><strong>GALLERY</strong></a></li>
<li><a class="tupac" href="#location"><strong>LOCATION</strong></a></li>
</ul>
</span>
</nav>
</div>
</div>
</nav>
For the life of me I can't understand why the logo is displaying at full size and not being contained in the Navbar. I basically want the logo on the left and my menu items on the right. Moreover, I want them to always be on the samle line, i.e. when I resize the windows (or on a smaller screen like an iPhone for example), it scales down. Maybe I have tunnel vision but can anyone perhaps point out the problem?

Can't say for sure without looking at your css, but images will only be resized if the logo class is configured correctly. You may want to look at this example https://codepen.io/bootstrapped/pen/KwYGwq on how to configure css properly.
For what concerns wrapping, the default behaviour is to wrap especially as you are dividing the screen in 2 columns when small. An option is to play around with CSS (see How to make bootstrap 3 navbar not wrap). Alternatively, play with column sizing so that a small logo doesn't take half screen real estate and the menu items are scaled correctly. For very small screen, the best option is to collapse and show a vertical menu.
This code from bootply should do what you need:
<div class="container example2">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar2">
<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="http://disputebills.com"><img src="https://res.cloudinary.com/candidbusiness/image/upload/v1455406304/dispute-bills-chicago.png" alt="Dispute Bills">
</a>
</div>
<div id="navbar2" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<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>
<!--/.container-fluid -->
</nav>
</div>
and this is the CSS
.navbar-brand {
padding: 0px;
}
.navbar-brand>img {
height: 100%;
padding: 15px;
width: auto;
}
/* EXAMPLE 2 (larger logo) - simply adjust top bottom padding to make logo larger */
.example2 .navbar-brand>img {
padding: 7px 15px;
}
/* CSS Transform Align Navbar Brand Text ... This could also be achieved with table / table-cells */
.navbar-alignit .navbar-header {
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;
height: 50px;
}
.navbar-alignit .navbar-brand {
top: 50%;
display: block;
position: relative;
height: auto;
transform: translate(0,-50%);
margin-right: 15px;
margin-left: 15px;
}
.navbar-nav>li>.dropdown-menu {
z-index: 9999;
}
body {
font-family: "Lato";
}

Related

Centering banner image on screen resize

I'm having an issue where a banner image (the "Review Us" text and lines) is not centering correctly when trying to adjust the screen size. Here is a before and after of what my issue is. The after image is also showing the same results on mobile screens
before
after
The HTML for that image goes as followed:
<div class="rowBanner">
<img src="images/reviewus.png" alth="review">
</div>
The only CSS in effect is on
div.rowBanner{
padding-top: 40px;
text-align:center;
}
I would like the "Review Us" text part of the image to be centered (left-to-right) regardless of screen width
The problem you have might be from desktop to mobile the hambuger menu shift your logo. using position absolute with transform: translate(-50%, 0%); will center your img by its own width.
.rowBanner {
position: absolute;
left: 50%;
display: block;
transform: translate(-50%, 0%);
}
Centering Percentage Width/Height Elements
REF: https://css-tricks.com/centering-percentage-widthheight-elements/
.navbar {
position: relative;
}
.rowBanner {
position: absolute;
left: 50%;
display: block;
transform: translate(-50%, 0%);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="rowBanner">
<img src="http://via.placeholder.com/100x50" alth="review">
</div>
<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>
</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 class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
Just add this css to the image:
div.rowBanner > img {
display: block;
margin: 0 auto;
max-width: 100vw;
}
Edited: Added a maximum with to the img, 100vw means 100 viewport width units, See: http://caniuse.com/#feat=viewport-units
You may try following CSS:
div.rowBanner {
margin-left:auto;
margin-right:auto;
width:80%;
}
What about using CCS background-image to set your image. You can then control where the center point is on different resolutions via background-position
function resize(isDesktop) {
if (isDesktop) {
$('.banner').css('width', '100%');
} else {
$('.banner').css('width', '200px');
}
}
.banner {
background-image: url('https://i.ytimg.com/vi/qh7LLydY8eo/maxresdefault.jpg');
background-size: cover;
background-position: center;
height: 175px;
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="resize(true)">Desktop</button>
<button onclick="resize()">Mobile</button>
<div class="page">
<div class="banner">
</div>
</div>

Having bootstrap navbar have elements on top and bottom of header

Can't quite seem to wrap my head around a bootstrap nav having elements on bottom and top of navbar, while still utilizing the collapsable navbar.
Here is what I've tried: Fiddle
As you can see, I was able to achieve the text on top and bottom of navbar (while still using the collapsable navbar feature), but when you look at it in mobile (as in, when the menu is collapsed and you click on the hamburger logo), it's completely messed up.
So this has me wondering if perhaps I'm not approaching this the right way?
Here is the CSS:
#mainNavBarTop {
position: absolute;
margin-top: -10px;
top: 0;
left: 0;
}
#mainNavBarBottom {
position: absolute;
margin-bottom: -10px;
bottom: 0;
left: 0;
}
and HTML
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header"><button class="navbar-toggle collapsed" type="button" 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><img src="" /></div>
<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav" id="mainNavBarBottom">
<li class="bottom">About</li>
<li class="bottom">Contact</li>
</ul>
<ul class="nav navbar-nav" id="mainNavBarTop">
<li class="bottom">About</li>
<li class="bottom">Contact</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group"><input class="form-control" type="text" placeholder="Search"/></div>
<button class="btn btn-default" type="submit">Submit</button>
</form>
</div>
</div>
</nav>
If you want the navigation links to display over multiple lines on a desktop view, all you have to do is specify a width for the navbar that accommodates for the image, and also add enough items to the dropdown so that they overflow.
Optionally, you can have the links pressed up against the right rather than the left by adding float: right to the li elements of the navbar. Note that this will reverse the order of the items in the list, so you may wish to list the links in reverse order in the HTML itself if you opt for this.
You can see this by expanding the snippet below, or by viewing the JSFiddle here. The links all stay directly below one another in the collapsed menu, though occupy two lines in the desktop view. Expanding the JSFiddle to the maximum width shows that the links will revert back to a single line when there is enough space to contain them.
#media (min-width: 768px) {
.navbar-nav.pull-right {
width: calc(100% - 120px); /* 100% - image width */
}
.navbar-nav>li {
float: right; /* Optionally align items to the right */
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default">
<div class="container">
<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>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img class="img-responsive" src="http://placehold.it/120x30" width="120px;" /></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav pull-right">
<li>Saved searches</li>
<li>Settings</li>
<li>About</li>
<li>Sign In</li>
<li>Another Link</li>
<li>Another Link</li>
<li>Another Link</li>
<li>Another Link</li>
</ul>
</div>
</div>
</nav>
Hope this helps! :)

The logo not taking full height of the header

I need to set the height of the logo same as the header. Though I set the height of the logo as 100% it doesn't take the height of the header. I am not sure how to set the height of the logo as the header height. Here is my code
app.css
body {
font-family: 'Open Sans', sans-serif;
border-top:none;
}
.navbar {
margin-bottom: 0px;
padding: 10px 15px;
}
.navbar img {
width : 100%;
height : 100%;
}
Master page
You can see the reference of the logo in the header element
<header>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- 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>
<img src="~/Images/NGSR-logo.jpg" />
</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>Requests</li>
<li>Activities</li>
<li>Reports</li>
<li>Admin</li>
<li class="dropdown">
Country <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</li>
<li>Save View</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</header>
Header view
Try to set a max-width for the logo image:
.navbar-header img{
max-width:280px;
}
and then set padding to zero for the navbar:
.navbar{
padding:0;
}
For my example I picked a random logo from google, however that should give you the general idea!
Fiddle here: https://jsfiddle.net/captain_theo/f1a5bda1/

Restrict Bootstrap navar to fixed height while allowing for custom icons in navbar menu

I'm trying to place custom icons in a Bootstrap navbar while keeping the navbar at exactly 50px height. Even if I declare .navbar { height: 50px; }, after placing the icon, the navbar height increases a couple of pixels in height. Click on the link in the navbar and note the approx 2px space between the navbar and the dropdown menu (the navbar is 52px in this example due to the height of the icon).
See: http://jsfiddle.net/hj3h58gm/4/
I understand the current behavior, I just don't know a way around it without decreasing the height of the icon, which I don't want to do.
Any suggestions?
The icon is denoted with .el-ico.
HTML
<body>
<nav class="el-nav navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
click this
<span class="el-ico"></span>
</a>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
</body>
CSS
.el-nav {
height: 50px;
max-height: 50px;
}
.el-ico {
display: inline-block;
width: 30px;
height: 18px;
background-image: url(icon.png);
}
You only need to use the right selector with your CSS and use a media query with your navbar when adjusting for height because at under 768px you'll have adverse effects (your mobile dropdowns background will seem invisible when really the navbar is set at 50px, default is min-height: 50px).
#media (min-width: 768px) {
.navbar.el-nav {
height: 50px;
}
}
.navbar .el-ico {
display: inline-block;
width: 30px;
height: 18px;
background-image: url(http://placehold.it/350x150/ff0);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default el-nav navbar-fixed-top">
<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="#">Brand</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="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> <span class="el-ico"></span>
</a>
<ul class="dropdown-menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li role="separator" class="divider"></li>
<li>Separated link
</li>
<li role="separator" class="divider"></li>
<li>One more separated link
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>

How to create a Bootstrap sticky nav that is below a marquee but then pinned to top after scrolling

Using the bootstrap v3 framework How do I create a Navigation header that is below or part of a jumbotron or large container (like a marquee image) but sticks to the top when user scrolls down?
I started with the bootrap example and placed it below a marquee image. However, how do you change to navbar-fixed-top and detect when user has scrolled to an appropriate position?
Example:
poolhousedigital.com
HTML:
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<div id="intro" class="container">
<h1>Navbar example</h1>
<p>This example is a quick exercise to illustrate how the default, static and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p>To see the difference between static and fixed top navbars, just scroll.</p>
<p>
<a class="btn btn-lg btn-primary" href="../../components/#navbar" role="button">View navbar docs ยป</a>
</p>
</div> <!-- /container -->
</div> <!-- /jumbotron -->
<!-- Fixed navbar -->
<div class="navbar navbar-inverse navbar-fixed" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" 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" href="#">Project name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-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>
</div>
CSS:
body {
min-height: 2000px;
padding-top: 0px;
}
.jumbotron {
position: relative;
background: none;
padding: 0px;
margin-bottom: 0px;
min-height: 500px;
}
.jumbotron:after {
content:"";
background: url("img/2gratermay20121.jpg");
background-repeat:no-repeat;
background-position: 0% 0%;
background-size: 100% 100%;
opacity: 1;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
See this example on Bootply: http://bootply.com/95797
The example uses a masthead, but you can replace this with your jumbotron.
Here is another example.. http://bootply.com/96188#
Both use the Affix plugin to attach the nav after scroll.