Scrolling navbar (navbar-fixed) only on Desktop - css

I want to make a navbar that scrolls with the site.
Now, if I just wanted that, I'd just add .navbar-fixed and call it a day.
However, I want that only on desktop.
On mobile, I want it to stay at the top.
Is there a way I can do that?
I've looked into jQuery for this, but everybody says I should use media queries for this (to which I do agree).
The code for my navbar is very simple with no additional CSS.:
<div class="navbar">
<nav>
<div class="nav-wrapper container">
<a href="#" class="brand-img img-responsive" wp-home-url wp-home-url-set="href" wp-home-url-scheme="relative">
<img src="https://www.finlaydag33k.nl/wp-content/uploads/2016/08/logo-FDG-300-01-300x300.png">
</a>
<ul id="nav-mobile" class="right">
<li>
<i class="material-icons">menu</i>
</li>
</ul>
</div>
</nav>
</div>
so tl;dr:
On desktop: make it like it's having .navbar-fixed.
On phone: make like it doesn't have .navbar-fixed.

You have 2 solutions for this .
1. Using CSS media queries .
1.a. First make your navbar fixed using position:fixed , and then under
767px ( which is mobile ) change it to position:relative or
absolute depending on what you want.
See snippet below or > jsFiddle
.content {
height:200px;
width:100%;
background:red;
}
.navbar {
position:fixed;
width:100%;
top:0;
left:0;
}
#media only screen and (max-width: 767px) {
.navbar {
position:relative;
}
}
<div class="navbar">
<nav>
<div class="nav-wrapper container">
<a href="#" class="brand-img img-responsive" wp-home-url wp-home-url-set="href" wp-home-url-scheme="relative">
<img src="https://www.finlaydag33k.nl/wp-content/uploads/2016/08/logo-FDG-300-01-300x300.png">
</a>
<ul id="nav-mobile" class="right">
<li>
<i class="material-icons">menu</i>
</li>
</ul>
</div>
</nav>
</div>
<div class="content">
</div>
1.b. You can also make a media query for desktop only.
See snippet below or > jsFiddle
.content {
height: 200px;
width: 100%;
background: red;
}
#media only screen and (min-width: 767px) {
.navbar {
position: fixed;
width: 100%;
top: 0;
left: 0;
}
}
<div class="navbar">
<nav>
<div class="nav-wrapper container">
<a href="#" class="brand-img img-responsive" wp-home-url wp-home-url-set="href" wp-home-url-scheme="relative">
<img src="https://www.finlaydag33k.nl/wp-content/uploads/2016/08/logo-FDG-300-01-300x300.png">
</a>
<ul id="nav-mobile" class="right">
<li>
<i class="material-icons">menu</i>
</li>
</ul>
</div>
</nav>
</div>
<div class="content">
</div>
2. Use jQuery for this and add class navbar-fixed in html and remove it when on mobile. See below or > jsFiddle
var wWidth = $(window).width()
if ( wWidth < 767) {
$(".navbar").removeClass("navbar-fixed-top")
}
.content {
height: 200px;
width: 100%;
background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="navbar navbar-fixed-top">
<nav>
<div class="nav-wrapper container">
<a href="#" class="brand-img img-responsive" wp-home-url wp-home-url-set="href" wp-home-url-scheme="relative">
<img src="https://www.finlaydag33k.nl/wp-content/uploads/2016/08/logo-FDG-300-01-300x300.png">
</a>
<ul id="nav-mobile" class="right">
<li>
<i class="material-icons">menu</i>
</li>
</ul>
</div>
</nav>
</div>
<div class="content">
</div>

using #Mihai T's (I don't know how to tag people here on SO) post as inspiration and a bit of a guide, I managed to get a working solution:
#media only screen and (max-width: 767px)
{
.navbar-fixed nav
{
position: relative;
}
.navbar-fixed
{
position: relative;
height: 56px;
z-index: 998;
}
}
Thanks for the help :D

Related

How to move a div containing a image

I cant seem to move the image inside a div. It can only be moved with absolute positioning, which I am not okay with. Can someone point out why the below given code isnt working. I want all 3 divs to be in one line . Image seems to be stuck in the top left corner. Applying padding doesnt change anything either.Please help
<div class="container" style="display:table">
<div style="display:table-cell">
<div class="emblem" style="padding:0 0 0 20px ;display:table-cell"></div>
<div class="logo" style="display:table-cell" Software Solutions</div>
</div>
<div class="header" style="">
<nav>
<ul style="display:flex;justify-content">
<li> Home</li>
<li>
<a href="{% url 'aboutus' %}" target="ifr" onclick="setTitle2()">
<title>RCE-About</title>About Us</a>
</li>
<li>Products</li>
<li>Solutions</li>
<li>Support</li>
</ul>
</nav>
</div>
</div>
It's maybe something like this you need to do..
EDIT:edited snippet code, navbar is under logo but take 100% width
.container{
display:flex;
justify-content: flex-start;
flex-wrap:wrap;
background:gray;
padding:5px;
}
.navbar-container{
width:100%
}
.container > div{
display:block;
height: 50px;
background: red;
margin-right: 15px;
padding:15px;
text-align:center;
}
ul{
margin:0;
padding:0;
}
ul li{
display:inline-block;
}
<div class="container">
<div class="1">Some text</div>
<div class="logo">LOGO</div>
<div class="navbar-container">
<div class="navbar">
<ul>
<li>test1</li>
<li>test2</li>
<li>test3</li>
</ul>
</div>
</div>
</div>

How to position half of image out of the div responsive

I would like to position the icons where the red square is. But I have tried the position: relative and position absolute but I dont understand why its not working.
<div class="col-xs-12 col-sm-4">
<div class="wrap">
<img class="blockico" src="<?php bloginfo('template_url'); ?>/img/icons/catering150.png">
<h4>Catering</h4>
The Menu
<br>
Today's Menu
<br>
Gallery
<br>
Festivities
<br>
</div>
</div>
.wrap {
position:relative;
width: 100%;
height: 100%;
background-color: #e9e9e9;}
.blockico {
position:absolute;
top:-50%;}
Not sure why this isn't working for you; I plugged it into a Fiddle and (while it doesn't behave the way I think you'd want) it seems to move the image up just fine. Here's a fiddle of a slightly different approach (not using position attributes; just applying a negative top margin) that might get you closer.
https://jsfiddle.net/35aohm3y/
.wrap {
margin-top:50px; /* push the wrap down a bit. You might not need this */
width: 100%;
height: 100%;
background-color: #e9e9e9;}
.blockico {
background:#666; /* added just for demonstration purposes */
margin-top:-50px; /* and push the image up a bit */
}
You can use a negative margin to pull the image up and out.
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.options ul,
.options li {
margin: 0;
padding: 0;
list-style: none;
}
.options>div {
margin: 50px 0;
/* for demo */
}
.options .wrap {
padding: 1rem;
text-align: center;
background-color: #e9e9e9;
}
.blockico {
margin-top: -50px;
}
<div class="container-fluid">
<div class="row options">
<div class="col-xs-12 col-sm-4">
<div class="wrap">
<img class="blockico" src="http://placehold.it/100x100/fc0">
<h4>Restaurant</h4>
<ul>
<li>The Menu</li>
<li>Today's Menu</li>
<li>Gallery</li>
<li>Festivities</li>
</ul>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="wrap">
<img class="blockico" src="http://placehold.it/100x100/fc0">
<h4>City Club & Garden</h4>
<ul>
<li>The Menu</li>
<li>Today's Menu</li>
<li>Gallery</li>
<li>Festivities</li>
</ul>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="wrap">
<img class="blockico" src="http://placehold.it/100x100/fc0">
<h4>Catering</h4>
<ul>
<li>The Menu</li>
<li>Today's Menu</li>
<li>Gallery</li>
<li>Festivities</li>
</ul>
</div>
</div>
</div>
</div>
update css blockico
.blockico {
position:absolute;
transform: translate(-50%,-50%);
left: 50%;
}

.nav-tabs behaving inappropriate when .navbar-brand is assigned to its sibling element

I have commented out the bug(with #characters) in the navigation part of the code where I am getting the issue. Try removing the .navbar-brand as mentioned in the comment and you will get to see.
I'm curious to know that what's happening under the hood when navbar-brand is assigned to its(element with .nav-tabs) adjacent element which conflicting with it
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="author" content="NeelDUnstoppable" />
<meta name="description" content="A rough template for html page created just for enhancing and getting a precise grip over the rules" />
<title>html template</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="css/main.css" rel="stylesheet" />
</head>
<body>
<div class="nav" role="navigation">
<!-- ######## Remove the .navbar-brand class from the below <a> element and the .nav-tabs class in <ul> element works completely fine ######### -->
Blasting off with bootstrap
<ul class="nav nav-tabs">
<li role="presentation" class="active">Tickets</li>
<li role="presentation">Stations</li>
<li role="presentation">About</li>
</ul>
</div>
<div class="container">
<div class="row well well-lg">
<div class="col-md-6">
<h2>The Fastest way to space</h2>
<p class="lead">Make your way to space in the comfort of your own rocket, elevator or transporter.</p>
<button type="button" class="btn btn-lg btn-default">Take the Tour</button>
<button type="button" class="btn btn-lg btn-primary">Book Tickets Now</button>
</div>
<div class="col-md-6 hidden-sm hidden-xs">
<img src="images/img-header.jpg" alt="Blasting off" title="Blasting off image"/>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row text-center features">
<div class="col-sm-4 col-xs-10 col-xs-offset-1 col-sm-offset-0">
<i class="glyphicon glyphicon-briefcase"></i>
<h3>Book Today</h3>
<p>Even if you're traveling tomorrow, you can still get tickets today. We have a number of conveniently located ports around teh globe to service everyone</p>
</div>
<div class="col-sm-4 col-xs-6">
<i class="glyphicon glyphicon-random"></i>
<h3>Go Anywhere</h3>
<p>If you need to get to space today, why not try out a transporter? Despite the claims, there are have been no deaths in the last 6weeks!</p>
</div>
<div class="col-sm-4 col-xs-6">
<i class="glyphicon glyphicon-send"></i>
<h3>RocketBus®</h3>
<p>For cheapest fares, catch the next RocketBus® to the stars. Cheaper on you wallet, and easiest way to make friends</p>
</div>
</div>
</div>
<div class='footer'>
<div class='container'>
<div class='row'>
<div class='col-sm-4 col-md-3 col-xs-6'>
<h4>Who We Are</h4>
<p><i>Blasting Off With Bootstrap</i> is the fastest way to space. <a href='#'>Book your ticket today</a>!</p>
<p><a href='#'>More About Us <i class='glyphicon glyphicon-arrow-right'></i></a></p>
</div>
<div class='col-sm-2 col-xs-6 col-md-offset-1'>
<h4>Links</h4>
<ul class='list-unstyled'>
<li><a href='#'>Home</a></li>
<li><a href='#'>Tickets</a></li>
<li><a href='#'>Stations</a></li>
</ul>
</div>
<div class='clearfix visible-xs'></div>
<div class='col-sm-2 col-xs-6'>
<h4>Stay in Touch</h4>
<ul class='list-unstyled'>
<li><a href='#'>About</a></li>
<li><a href='#'>Contact Us</a></li>
<li><a href='#'>Blog</a></li>
<li><a href='#'>Twitter</a></li>
<li><a href='#'>Facebook</a></li>
</ul>
</div>
<div class='col-sm-4 col-md-3 col-md-offset-1 col-xs-6'>
<h4>Contact Us</h4>
<ul class='list-unstyled'>
<li><i class='glyphicon glyphicon-globe'></i> Orlando, FL<li>
<li><i class='glyphicon glyphicon-phone'></i> 1-555-blast-off<li>
<li><i class='glyphicon glyphicon-envelope'></i> <a href='mailto:#'>blastingoff#codeschool.com</a><li>
</ul>
<p>Blasting Off With Bootstrap ©2214.</p>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
</body>
</html>
The related .css file:
.features .glyphicon {
font-size: 32px;
}
.row {
margin-bottom: 20px;
}
.quote {
background-color: #444;
color: #e1e1e1;
}
.quote blockquote {
border: none;
margin: 0;
}
.quote footer {
color: #c1c1c1;
}
section, header {
background-color: #fff;
}
body {
}
.footer {
padding: 20px 0;
}
/*
#demo-nav {
display: none;
}
.show-nav #demo-nav {
display: block;
}
*/
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 200px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 200px;
}
.footer {
color: #efefef;
background-color: #333;
}
.footer a {
color: #9af7fe;
}
#media only screen and (max-width: 768px) {
body { margin-bottom: 400px; }
.footer { height: 400px; }
}

I have issue with bootstrap

I am new to bootstrap and i have been designing a taxi website . I have a issue with it where the whole container of the website is more towards the right side of the screen , its not in the center of the screen.
I guess the problem may be with jumbotron . The size of the backgroud image is
1400x562 . how can i fix it?
Preview of the website(http://threeguys.us/works/employee.html)
index.html
<div class="container">
<div class="jumbotron">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#"><img src="images/logo/logo.png" width="250px" height="70px"></a>
</div>
<div>
<ul class="nav navbar-nav navbar-right">
<li class="active"><img src="images/navigation_hover/home.png" width="100px" height="70px"></li>
<li><img src="images/navigation/rates.png" width="100px" height="70px"></li>
<li><img src="images/navigation/employee.png" width="140px" height="70px"></li>
<li><img src="images/navigation/contact.png" width="140px" height="70px"></li>
</ul>
</div>
</div>
</nav>
<div class="call_button">
<button type="button" class="btn btn-default">call us</button>
</div>
</div><!--jumbotron end-->
</div><!--container end-->
style.css
.jumbotron
{
background: url(images/car/car.png) no-repeat ;
background-size: 100%;
height: 562px;
width: 1400px;
padding-top: 0px;
}
.navbar {
/* height: 70px; */
background-color: transparent;
border:0px;
}
.navbar-brand {
padding-top: 15px;
}
Several options:
Place the class='jumbotron' outside the class='container';
The class='container' has a specific width (1170px) by default.
so you want your structure to be:
<div class='jumbotron'>content here</div>
<div class='container'>content here</div>
OR
Adjust the width of the 'container' class. Try 75%. I would recommend doing this outside bootstrap or even inline on the tag like:
<div class='container' style='width:75% !important'>
Hope this helps.

set height div to other element height on page

I've created this content with drupal. Below the image you have a next page button.
I also set a button for next image on top of the image (pager) so if the visitor clicks on the image it would go next page.
How can i stretch the link over my image, drupal generated 2 divs and the images are variable in height.
<div class="view-content">
<div class="container12">
<div class="pagerfoto column12">
<h2 class="element-invisible">Pagina's</h2>
<div class="item-list">
<ul class="pager">
<li class="pager-next first">
›
</li>
<li class="pager-last last">
</ul>
</div>
</div>
</div>
<div class="container12">
<ul>
<li class="views-row views-row-1 column12">
<div>
<div class="views-field views-field-field-image">
<div class="field-content">
<img width="900" height="675" alt="" src="http://www.logicaarchitectuur.be/test/sites/default/files/styles/gallery_large/public/desert.jpg?itok=J6D4TAEL" typeof="foaf:Image">
</div>
</div>
</li>
</ul>
</div>
site
.pagerfoto{
z-index:1;
position:absolute;
padding-top:1.71429em;
display:block;
}
.pagerfoto ul li.pager-next a{
display:block;
margin:0 auto;
padding:0;
text-indent: -9999px;
}
This is the current css i use for ma a label.
Try giving this css:
.view-project11 {
position: relative;
}
.item-list {
left: 50%;
position: absolute;
top: 50%;
}
If I understand your question correctly you would like the user to click on the image and then the page will go to the next image.
wrapping your image in the tag will allow you to do that.
example
<a width="900" height="675" href="/test/project11?page=1">
<img width="900" height="675" alt="" src="http://www.logicaarchitectuur.be/test/sites/default/files/styles/gallery_large/public/desert.jpg?itok=J6D4TAEL" typeof="foaf:Image">
</a>

Resources