I made a Navbar with Bootstrap 3. My questions is how to have it be shaded when selected?
Everything works fine otherwise. I believe it required some JavaScript, but I don't know how to implement it.
This is my code:
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<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>
<div style="font-family:Webdings;">
<%= link_to "lalala", root_path, class: 'navbar-brand' %>
</div>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li><%= link_to "laaa", lal_path %></li>
<li class="dropdown">
lala<b class="caret"></b>
<ul class="dropdown-menu">
<li><%= link_to "lala", laa_path %></li>
<li><%= link_to "lalala", lala_path %></li>
<li><%= link_to "lalala", lala_path %></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
Follow #lalala
</li>
<li>
<div class="fb-like" data-href="lalala" data-width="600" data-layout="button_count" data-show-faces="true" data-send="false"></div>
</li>
<li><%= link_to "lala", contact_path %></li>
<li><%= link_to "lalalala", register_path %></li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
CSS3 is all you need! Go here: http://css3generator.com/. After you generate the shadow, gradient or text shadow you like, apply that css3 chunk of code to the element by adding :active selector. See here for :active selector: http://www.w3schools.com/cssref/sel_active.asp
NB: :active MUST come after :hover (if present) in the CSS definition in order to be effective!
Related
I am learning Bootstrap and am trying to implement it within a Ruby on Rails projects I have. I am using the bootstrap navbar and am trying to integrate that with rails. I have a search bar that I am trying to make responsive. I want the width of the search form to fill up the available space, and shrink/grow as the screen size changes. The navbar in bootstrap already has a lot of CSS styles applied to it and I feel like trying to add a feature like this to an existing navbar is difficult.
Here is the code for my form...
application.html.erb
<nav class="navbar navbar-default navbar-fixed-top" style="background-color: #228822;">
<div class="container-fluid">
<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>
<!-- overriding to HTTP GET because turbolinks causes issues with pagination infinite scroll -->
<%=link_to "The Pragmatic Bookshelf", store_index_path, :class => "navbar-brand", method: :get, style: "color:#bbffbb" %>
</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><%= link_to t('.questions'), store_index_path, style: "color:#bbffbb" %></li>
<li><%= link_to t('.news'), store_index_path, style: "color:#bbffbb" %></li>
<li><%= link_to t('.contact'), store_index_path, style: "color:#bbffbb" %></li>
</ul>
<form class="navbar-form navbar-left">
<div id="search_bar" >
<%= form_tag(store_index_path, method: :get) do %>
<div class="search_bar_text">
<%= text_field_tag :search, '', id: 'search_bar_text' %>
</div>
<div class="search_bar_image">
<%= image_submit_tag 'search.png', id: 'search_bar_image'%>
</div>
<% end %>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
Admin <span class="caret"></span>
<ul class="dropdown-menu">
<% if session[:user_id] %>
<li><%= link_to "Orders", orders_path%></li>
<li role="separator" class="divider"></li>
<li><%= link_to "Products", products_path%></li>
<li role="separator" class="divider"></li>
<li><%= link_to "Users", users_path%></li>
<li role="separator" class="divider"></li>
<li><%= link_to "Logout", logout_path, method: :delete%></li>
<% else %>
<li><%= link_to "Login", login_path%></li>
<% end %>
</ul>
</li>
<li class="dropdown">
Language <span class="caret"></span>
<ul class="dropdown-menu">
<% LANGUAGES.each do |language|%>
<li><%= link_to language[0].to_s, store_index_url(locale: language[1]) %></li>
<% end %>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
I got most of this code from an example in the bootstrap documentation and have been implementing some erb into it to integrate it with my Rails project. The form class="navbar-form navbar-left" is where the search bar starts. The behavior I want is for this to fill up the remaining space between the unordered lists to the right and left and adjust its size based on the current screen size.
I have experimented with display flex and flex-grow, floating, & overflow. Cant seem to get anything working. I wont include my CSS file since its only some font/color changes, most of the CSS is from bootstrap anyways.
Any help/guidance is appreciated :)
I'll ask the dumb question... do you have the following in your < head > section?
<meta name="viewport" content="width=device-width, initial-scale=1.0">
without it, Bootstrap won't be responsive.
Bootstrap includes a grid system. Maybe you can use this to define the width of the search field.
The grid system divides the width into 12 columns. So you could use for example:
.col-sm-12 .col-lg-4
You can play around with the values.
This question already has answers here:
Bootstrap align navbar items to the right
(24 answers)
Closed 4 years ago.
My navbar wont go towards the right side. I set the div as you can see. However, div still is staying on the left side of the navbar.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">BudLyfe</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="nav navbar-nav navbar-right">
<% if (!user_signed_in?) %>
<li><%= link_to "Login", new_user_session_path %></li>
<li><%= link_to "Sign Up", new_user_registration_path %></li>
<% else %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"
role="button" aria-haspopup="true" aria-expanded="false">
<%= current_user.email %> <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Edit Profile", edit_user_registration_path %></li>
<li><%= link_to "Log out", destroy_user_session_path, method: :delete %></li>
</ul>
</li>
<% end %>
</ul>
</div><!--/.nav-collapse -->
</nav>
It looks like bootstrap 4 uses utility classes for navbar spacing instead of the bootstrap 3 version of navbar-right. In the future, be sure you are looking at the correct documentation for the specific version of bootstrap that you are using.
Using ml-auto in place of navbar-right pushes that list to the right side of the navbar. This ml-auto class stands for margin-left: auto; which is the individual css rule you would use to achieve this effect without bootstrap.
Example codepen here: https://codepen.io/anon/pen/QzBKPe
I am using bootstrap navbar and I have a collapsible navbar. But I am facing a strange problem, whenever I am going to open my site on small devices i.e mobile phone or tablet (actually for which devices I need the collapsible navbar), it is by default opening the navbar. This should not happen. If I click on the navbar button (three line button) then only the navbar should expand. But my navbar is expanding first time by default on small devices.
Here is my code:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header"><%= image_tag("logo.png", alt: "industryPrime") %></div>
<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>
<div class="navbar-collapse collapse in" id="myNavbar">
<ul class="navigation pull-right">
<li class="dropdown">
<div class="dropdown">
<button id="feature_button" class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" style="background-color: transparent; color: #51a3af; border: none; font-size:11px;">FEATURES
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>Paperless purchase</li>
<li>Efficient stores</li>
<li>Peace of mind</li>
</ul>
</div>
</li>
<li>
<%= link_to "Case Study", user_maan_case_study_path %>
</li>
<li class="req_demo">
<%= link_to "Request Demo", user_request_demo_page_path , :onclick => "demo_clicked()" ,:onmouseover => "start_count()" , :onmouseout => "stop_count()" %>
</li>
<li id="Login button section"><%= link_to 'Login', {controller: 'sessions', action: 'new'} %></li>
<li>Contact Us</li>
<li><%= image_tag("contact_us.png") %>+91 98302-15353</li>
</ul>
</div>
</div>
</div>
</nav>
My website link is http://www.industryprime.com
please help me to fix it.
Thanks in advance!!!
Please remove class in in <div class="navbar-collapse collapse in" id="myNavbar"> . Hope it will help you.
I was wondering how I could collapse the content of my navbar on a mobile devise so it could have a home link and then the three dashes that when clicked drop down and show all the other links. Here is my _navigation.html.erb file:
<nav class="navbar navbar-default 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>
</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 nav-pills">
<li><%= link_to "Home", root_path %></li></a>
<li><%= link_to "About Me", about_path, target: :_blank %></li>
<li class="dropdown">
Music<span class="caret"></span>
<ul class="dropdown-menu">
<li><a target="_blank" href="https://soundcloud.com/officialyungdremusic">Soundcloud</a></li>
</ul>
</li>
<li class="dropdown">
Social Media<span class="caret"></span>
<ul class="dropdown-menu">
<li><a target="_blank" href="https://www.youtube.com/user/OfficialYungDreMusic">Youtube</a></li>
<li><a target="_blank" href="https://twitter.com/yungdremusic">Twitter</a></li>
</ul>
<li><%= link_to "Pictures", pictures_path, target: :_blank %></li>
<li><%= link_to "Contact Me", contact_path, target: :_blank%></li>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-->
</nav>
What I'm trying to accomplish works when I resize my desktop window. But for some reason on a phone(720x1280 pixels) it doesn't resize. I am familiar with media queries in css, would I just need another media query that would be just for screens of 720 and bigger?
Any help is greatly appreciated!
Default breakpoint for bootstrap navbar is 768px. I tried to reproduce your example and it does collapse below 768px. However, there are tablets with screen size of 768px or more where it won't collapse. You have to either write your own media query or change the default value of #grid-float-breakpoint bootstrap variable.
Check Changing the collapsed mobile navbar breakpoint on bootstrap guide for further information.
I have an is_active? helper to define the active link in my nav bar. It works fine. But I have a clients page that has many clients in it (in a sidebar list), and when I click through each client, the page reloads and gets the url for the client id (/clientes/1, /clientes/2 ...). My is_active? only works for the first client (id=1). When I click the other clients the active class disappears.
my header view looks like this:
<nav class="navbar navbar-inverse navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="container" id="container-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>
<%= link_to "Zetta Comunicação", root_path, class: "navbar-brand logo img-responsive" %>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="<%= is_active?(servicos_path) %>">
<%= link_to "A Empresa", servicos_path %>
</li>
<li class="<%= is_active? (cliente_unique_path(1)) %>">
<%= link_to "Clientes", cliente_unique_path(1) %>
</li>
<li class="<%= is_active?(new_contato_path) %>">
<%= link_to "Contato", new_contato_path %>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div>
</nav>
the helper looks like this
def is_active?(link_path)
if current_page?(link_path)
"active"
else
""
end
end
I know that I am calling the first id (id=1) in my header view. But I don't know how to make this call the other ids..
If I take the (1) of the cliente_unique_path it works perfect for the clients page, but I get the following error in my other pages:
No route matches {:action=>"cliente_unique", :controller=>"clientes"}
missing required keys: [:id]
Any ideas?
I would use jQuery in these situations. Like,
function activate(i){
("ul.nav li").removeClass("active");
("ul.nav li#" + i).addClass("active");
}
put that code in application.js.
give ids to all your li items.
and in every page call that function in a script tag passing the id of the li that you want to activate.
(typing from phone, so forgive the readability)