I'm looking for creating a new project Template in order to convert Wordpress Template to Bootstrap Template.
I'm working on navbar and I'm getting an issue with responsive-design and toggle-navigation
When I'm in laptop device, my navbar is well-defined as I want. But, with smartphone device for example, the toggle-navigation doesn't display my navbar as I would like to get. Especially with navbar-left and navbar-right.
Laptop device :
Smartphone device :
I would like to get in smartphone view all elements aligned vertically and it's not the case for www.coe.int and languages with glyphicons
This is my HTML script :
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collection of nav links and other content for toggling -->
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-left">
<li><a id="coe" href="http://www.coe.int">WWW.COE.INT</a></li>
</ul>
<ul class="nav navbar-nav navbar-middle">
<li><a class="active" href="#">EUROPEAN PHARMACOPOEIA</a></li>
<li>PHARMEUROPA</li>
<li>OTHER PUBLICATIONS</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Languages</li>
<li><a><span class="glyphicon glyphicon-search"></span></a></li>
</ul>
</div>
</div>
</nav>
And my CSS part :
body {
font-family:sans-serif;
font-size: 1.25em;
}
/* ######################## */
/* HEADER PART */
/* ######################## */
header{
background-color: #e8e8e8;
}
header a{
color: #a5a5a4;
}
/* Bootstrap Stuff */
nav.navbar.navbar-default.navbar-static-top {
background-color: #e8e8e8;
}
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
a#coe {
font-weight: bold;
text-decoration: none;
}
ul.nav.navbar-nav.navbar-middle > li > a:hover {
background-color: #1b7eac;
color: black;
transition: all 0.2s;
}
ul.nav.navbar-nav.navbar-middle > li > a:focus{
background-color: #1b7eac;
color: white;
transition: all 0.2s;
}
Could you help me to find a solution ?
My reputation does not allow me to comment unfortunately as this certainly be a comment.
But have you tried simply altering the text size using media queries to get your desired result?
--EDIT-----
I am assuming you already have the toggle button already working.
In which case If you wish to align them vertically you can use the bootstrap operator
col-sm-4 (for three items vertically aligned)
col-sm-3 (for 4 items vertically aligned)
Which will give each element their own space and align them vertically.
But remember you need to have a container then row then this property like so:
<div class="container">
<div class="row">
<div class="col-sm-4">item here</div>
<div class="col-sm-4">item here</div>
<div class="col-sm-4">item here</div>
</div>
</div>
I hope this helps you!
Related
I'm building a personal portfolio and I have a navbar with title, social media icons and navigation links. When viewing on mobile, the social media icons appear vertically under the title. I would like them to show up horizontally next to the title, so in between the title and the icon bar.
HTML:
<nav class="navbar">
<div class="container-fluid">
<!-- Navigation Bar -->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#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>
<div class="navbar-header">
<a class="navbar-brand text-center" href="index.html">Title Website</a>
</div>
<!-- Small social media icons -->
<ul class="nav navbar navbar-nav navbar-left pull-left">
<li></li>
<li></li>
<li></li>
</ul>
<div class="collapse navbar-collapse navbar-right" id="navbar-collapse-1">
<ul class="nav navbar-nav text-center">
<li><b>Home</b></li>
<li><b>Projects</b></li>
<li><b>CV/Resume</b></li>
</ul>
</div>
</div>
</nav>
CSS:
/* Navigation */
.navbar-header {
vertical-align: baseline !important;
}
.navbar-brand {
text-align: center;
font-size: 30px;
vertical-align: baseline !important;
}
.icon-bar {
background-color: black;
}
nav ul {
display: inline;
}
nav li {
display: inline;
padding: 10px;
}
Any help would be appreciated. Also, I would like the title to be vertically aligned when viewing on desktop. I tried navbar-brand {vertical-align: middle !important} but that did not work.
Thank you.
-Z
Got the icons how I wanted them by playing around. New code:
HTML:
<!-- Small social media icons -->
<ul class="nav navbar navbar-nav navbar-left pull-left">
<li id="socmed"></li>
<li id="socmed"></li>
<li id="socmed"></li>
</ul>
CSS:
#socmed {
display: inline-block !important;
float: left !important;
}
When using position: absolute; the navbar collapse does not work properly. When expanding the menu, the other content is not moved down anymore. Also, the button to expand and collapse is not visible (which is why I have made it gray) and does not appear in the correct position.
HTML code for the navbar:
<nav class="bootstrap-iso navbar navbar-default navbar-absolute">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="bootstrap-iso 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="#">DEMO</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" id="navbar-right">
<li>Home</li>
<li>Bruid</li>
<li>Bruidegom</li>
<li>De Winkel</li>
<li>Blog</li>
<li>Contact</li>
<li><button class="btn" id="afspraak">AFSPRAAK MAKEN</button></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
CSS:
navbar-right li {
font-family: Arial;
text-transform: uppercase;
font-weight: bold;
}
#afspraak {
margin-top: 5%;
background-color: #f5758e;
font-family: Arial;
text-transform: uppercase;
font-weight: bold;
color: white;
}
#navbar-right a {
color: white;
}
.navbar-default .navbar-brand {
color: white !important;
font-size: 36px !important;
}
.navbar-default {
background: transparent !important;
border: none !important;
position: absolute;
}
.navbar-toggle {
background-color: grey !important;
}
Many thanks in advance for your help!
YoungStarDC it happens to the best of us...check the first line of the navbar class. You need to add a '<' everything that's open has to be closed and everything that's closed has to be opened. The button will appear when you change the browsers window size once you do that.
<nav class="bootstrap-iso navbar navbar-default navbar-absolute"></nav>
P.S. Bootstraps navbar-collapse only collapses the navbar and shows the button when the screen is too small to hold the navbar
So, I've set my navbar to a custom height of 80px, but now that makes my nav items not centered vertically. I've been searching for an answer to center them vertically in relation to their parent item for awhile now so I figured I'd give StackOverflow a shot.
Screenshot: http://screencast.com/t/zfUuX9SSQK
HTML:
<div class="container-fluid isModified">
<div class="row">
<nav class="navbar isModified" role="navigation">
<div class="col-lg-8 col-lg-offset-2">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#nav-collapse">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar isModified"></span>
<span class="icon-bar isModified"></span>
<span class="icon-bar isModified"></span>
</button>
Tickets
</div>
<div class="collapse navbar-collapse" id="nav-collapse">
<ul class="nav navbar-nav isModified">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</div>
</div> <!-- end col-lg-12 -->
</nav>
</div> <!-- end row -->
</div> <!-- end container -->
CSS:
.navbar.isModified {
height: 80px;
border-radius: 0;
background-color: #cccccc;
}
.icon-bar.isModified {
background-color: #fff;
}
Vertical alignment can be done in a number of ways, as shown in this Stack Overflow question. However, they're fairly situational, meaning there isn't a single approach that can be applied to every case.
For the issue you're facing, I'd suggest the line-height approach, since all of your navigation content is on a single line. Just remove any vertical padding on the elements in questions, and set them to have the same line-height as the desired container height (80px):
.navbar-nav li a {
padding:0 15px;
line-height:80px;
}
.navbar-header a {
padding:0 15px;
line-height:80px;
}
Here's a Bootply to demonstrate. Hope this helps! Let me know if you have any questions.
Alternatively, you can use:
.navbar.isModified a {
padding:0 15px;
line-height:80px;
}
Though you may find this too broad of a CSS selector if you plan on styling other links in your navbar differently.
Note: If you want the mobile version of the menu to look alright, you may need to use media queries to override these styles with more of your own.
You can do this several ways depending on how your nav links need to behave. You probably want to apply line-height to you links so on hover they are still the full height of the navbar above 768px (or not, depends). You can then use another media and add padding to the navbar-header class to have a taller navbar. Don't use a fixed height though because on mobile your toggle nav will have no background color since the navbar has a default value of min-height: 50px.
Working Example:
.navbar.isModified {
background-color: #cccccc;
}
.navbar.isModified .icon-bar {
background-color: #fff;
}
#media (min-width: 768px) {
.navbar.isModified .navbar-brand {
line-height: 50px;
}
.navbar.isModified .navbar-nav > li > a {
line-height: 50px;
}
}
#media (max-width: 767px) {
.navbar.isModified .navbar-header {
padding: 15px 0;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<nav class="navbar navbar-static-top isModified" role="navigation">
<div class="col-lg-8 col-lg-offset-2">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#nav-collapse">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
Tickets
</div>
<div class="collapse navbar-collapse" id="nav-collapse">
<ul class="nav navbar-nav">
<li>Link 1
</li>
<li>Link 2
</li>
<li>Link 3
</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
<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>
I can't seem to figure out how to center the navigation items. I can place them either to the left or right but not center. Is there a simple work around?
<!-- Navigation -->
<div class="navbar navbar-default navbar-static-top">
<div class="container">
<!-- Mobile navigation button -->
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Navigation items -->
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav">
<li>OUR PRODUCTS</li>
<li class="active">ABOUT</li>
<li>OUR TEAM</li>
<li>CONTACT</li>
</ul>
</div>
</div>
</div>
I've tried a few things but they're a little sloppy and caused some issues with mobile version. I'm looking for something a little more proper.
1) Use <ul class="nav nav-justified"... for the menu container.
2) Look at this codepen source:
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li
{
float: none;
display: inline-block;
}
3) Read the answer right there
There are three different ways to do something like You want, choose one.
You could easily find your answer, please try to do this alone next time, bro.
I believe you forgot to add or edit.
On your Bootstrap.css go find this class and edit on text-align:center. This will make your text navbar be centerized.
.navbar.navbar-collapse{
text-align: center;
}
If you still don't get it. You can take a look my example that i do on Bootply.
HTML
<div class="container">
<nav class="navbar navbar-default" 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>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li>OUR PRODUCTS</li>
<li class="active">ABOUT</li>
<li>OUR TEAM</li>
<li>CONTACT</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</div>
CSS
#media (min-width: 620px) {
.navbar .navbar-nav {
display: inline-block;
float: none;
}
.navbar .navbar-collapse {
text-align: center;
}
}
DEMO
You could also use some custom CSS via flexbox.
.nav {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
justify-content: center;
float: none; // overwrites Bootstrap's float value
}
Try this one
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li
{
float: none;
display: inline-block;
}
.navbar-nav > li a{
text-decoration:none;
padding-left:15px;
}
I have an idea and not sure how to get it to work.
I have a bootstrap navbar on my site that has links and a "brand". The brand is centered within the navbar using this modification. Bootply
Instead of setting the navbar up like this:
{ (link)(link)(link)(....bunch of empty space....)(BRAND)(....bunch of empty space....)(link)(link)(link) }
I would like the navbar to set up like the diagram bellow.
{ (....bunch of empty space....) (link)(link)(link)(BRAND)(link)(link)(link) (....bunch of empty space....) }
I am very new to coding so please give me some time on the response to any questions you may have.
Thanks!
Just add padding to the left of the first link.
<nav class="navbar navbar-default" role="navigation">
<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>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Center 1</li>
<li>BRAND</li>
<li>Center 3</li>
</ul>
</div>
</nav>
CSS
#media (min-width: 768px) {
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li {
float: none;
display: inline-block;
}
.navbar-nav > li.navbar-right {
float: right !important;
}
}
Fiddle
http://jsfiddle.net/52VtD/9483/