I've implemented the solution here which almost solves my problem, however, I need the <ul class="nav"> to be centered between the entire navbar and not just the elements adjacent to it (<a class="brand"> and <p class="navbar-text pull-right"> in my case).
Important: I customized my navbar to be 96px instead of the default 40px, and I want the <ul class="nav"> to appear centered and "underneath" the other elements as it will have its own background-color etc.
Here is my code so far:
<div class="navbar navbar-inverse navbar-fixed-top center">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="/home"><img src="http://jayeshcp.files.wordpress.com/2013/03/twitter-bootstrap.jpg" style="width:400px;height:60px;" /></a>
<div class="nav-collapse collapse">
<ul class="nav">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
<p class="navbar-text pull-right">
<input class="span2" type="text" placeholder="Email">
<input class="span2" type="password" placeholder="Password">
</p>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
Note the extra center class that I added - that is from the solution that I linked to. It looks like this:
.center.navbar .nav,
.center.navbar .nav > li {
float:none;
display:inline-block;
*display:inline; /* ie7 fix */
*zoom:1; /* hasLayout ie7 trigger */
vertical-align: top;
}
.center .navbar-inner {
text-align:center;
}
.center .dropdown-menu {
text-align: left;
}
How do I center the ul and give it padding above without breaking everything else in Bootstrap? Would offer more than bounty if there was another currency!
edit: jsfiddle is here (I pasted the whole minified css file (with the customized navbar height) instead of referencing it, sorry. Underneath it are the other customizations.)
p.navbar-text
{
float: none;
position: relative;
text-align: right;
}
.navbar .nav
{
display:block !important;
float: right !important;
width: 100%;
}
jsfiddle: http://jsfiddle.net/C7LWm/103/
Here's the solution for placing it underneath instead of below:
.navbar .nav
{
position: absolute;
left:0;
right:0;
width: 100%;
background-color:yellow;
}
p.navbar-text
{
width: 440px;
text-align:right;
position:relative;
z-index:2
}
.navbar .brand
{
position: relative;
z-index:2;
padding: 0;
width: 30%;
height: 60px;
background-image: url('http://placehold.it/400x60&text=Your Logo Here');
background-repeat: no-repeat; background-size: contain;
margin: 18px 0;
background-position: center left
}
.navbar .brand img
{
display:none;
}
Jsfiddle: http://jsfiddle.net/C7LWm/109/
Related
I'm struggling with the alignment in the following navbar that uses Bootstrap 3.
Problem: The Login and Signup elements are on different rows. Whats the correct way to adjust them so that they are both on the same line? display: inline-block; and white-space: nowrap; does not appear to work on the li elements.
Note that the input element should fill up the space between the logo and the Login/Signup elements.
Bootply: http://www.bootply.com/Bh5TBV9vS0
<nav class="navbar navbar-default navbar-fixed-top">
HTML
<a class="brand" href="#">
<img src="https://upload.wikimedia.org/wikipedia/commons/4/4a/Logo_2013_Google.png" width="100">
</a>
<form role="form" class="form-horizontal search-form">
<!-- <i class="fa fa-search"></i> -->
<input type="text" class="form-control" placeholder="Search">
</form>
<ul class="nav navbar-nav">
<li>Login</li>
<li>Sign up</li>
</ul>
</nav>
CSS:
.brand {
width: 170px;
height: 80px;
background-color: #ccc;
display: inline-block
}
.navbar.transparent.navbar-inverse .navbar-inner {
background: rgba(0,0,0,0.4);
}
.search-form {
width: 100%;
height: 30px;
display: inline-block;
}
.search-form {
margin-top:10px;
padding: 0 10px;
}
nav { display: flex; }
Remove float:left for your list items and apply dispaly:inline-block and apply the style white-space:nowrap for your ul element.
ul.navbar-nav{ white-space:nowrap;}
.navbar-nav li{display:inline-block; float:none;}
I have updated width of .search-form from 100% to 76% and now it works fine.
Check here
I am setting a responsive layout for my personal website, which has worked in a simple example. However I am not getting the same results. It may have something to do with including the Bootstrap files in my html. Below is the html and css code for the responsive layout:
HTML:
<header>
<a href="/" id="logo">
<h1>Brian Weber</h1>
<h2>Engineer | Python Programmer</h2>
</a>
<!-- Navigation bar -->
<nav class="navbar navbar-default" role="navigation">
<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="#">Brian Weber</a>
<p>Engineer</p> -->
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Portfolio</li>
<li>About</li>
<li>Resume</li>
<li>Contact</li>
</ul>
</div>
</div>
</header>
CSS:
#media screen and (min-width: 660px) {
/*********************************
HEADER
*********************************/
.navbar .navbar-default {
float: right;
background: none;
font-size: 1.125em;
margin-right: 5%;
text-align: right;
width: 45%;
}
#logo {
float: left;
margin-left: 5%;
text-align: left;
width: 45%;
}
#logo h1 {
font-size: 2.5em;
}
#logo h2 {
font-size: 1.7em;
margin-bottom: 20px;
}
header {
border-bottom: 5px solid #599a68;
margin-bottom: 60px;
}
}
When I check the code in a browser, the h1 and h2 text do not appear. However when I inspect the element there are placeholders for where the text should be. The text color is already set to black in the main.css. My question is how would I fix this problem so that the layout looks like the picture below? I am thinking maybe there is an issue with the bootstrap files where they are overriding the CSS code.
Correct format for header and navbar
h1 and h2 text disappearing
Add this in your style
#logo
{
z-index:1;
position:relative;
}
The z-index property specifies the stack order of an element.
An element with greater stack order is always in front of an element with a lower stack order. and in your style navbar-default hide the h1 and h2 that's why it's not looking
Make .navbar-default float right when in the larger views. It was covering up the left floating div that contained your name etc.
Add position:relative; and z-index for logo.
#logo {
float: left;
margin-left: 5%;
text-align: left;
width: 45%;
position: relative;
z-index: 1;
}
I'm trying to finish up my portfolio page right now. Having an issue getting the top/bottom padding spacing to stay the same on 24" and 13". As you can see from the images below, the 24" inch currently looks how I want it to, with all my elements on the right side directly in the middle. When it becomes 13", the spacing is off and the elements aren't centered. How do I fix this?
24" - http://i988.photobucket.com/albums/af6/jtbitt/jay-portfolio-24-inch-spacing_zpsenaqpzp4.png
13" - http://i988.photobucket.com/albums/af6/jtbitt/jay-portfolio-13-inch-spacing_zps45ygidew.png
HTML FRONT PAGE -
<body ng-app="jayPortfolio">
<!-- NAVBAR -->
<header>
<nav class="navbar navbar-inverse 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="/">JAY BITTNER</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>ABOUT</li>
<li>PORTFOLIO</li>
<li>EXPERIENCE</li>
<li>CONTACT</li>
</ul>
</div>
</div>
</nav>
</header>
<!-- LOAD OTHER PAGES HERE -->
<main>
<div id='ng-view' ng-view></div>
</main>
</body>
HTML FRONT PAGE PARTIAL -
<section id="about" ng-controller="aboutController">
<div class="container-fluid">
<div class="row">
<div class="about-left col-lg-6 col-md-6 col-sm-12 col-xs-12">
</div>
<div class="about-right col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="about-content">
<div class="about-content-title">
<h1><strong>I'M JAY.</strong></h1>
</div>
<br />
<div class="about-content-info" ng-model="about.firstParagraph">
<p ng-if="about.firstParagraph"><strong>An entrepenurial minded, Full Stack Developer. Whenever I'm up against a challenge that I care about, it gives me a rush. Focusing on the big picture is important to me, but I never forget the smaller details. Anything that is not challenging is boring, and makes me yawn. Anything that is seemingly impossible interests me a lot. I'm ready to get to work.</strong></p>
<p ng-if="!about.firstParagraph"><strong>Currently seeking a Javascript position, using the MEAN stack, in New York City. Being innovative, ambitious, and hard working are values that are very important to me. I want to join a company that has similar values and has goals of reaching ridiculous levels of success, not just modest realistic ones. I love working with a solid team.</strong></p>
</div>
<br />
<div class="about-button">
<button ng-if="about.firstParagraph" class="label label-success" ng-click="about.switchParagraph()"><strong>MORE =></strong></button>
<button ng-if="!about.firstParagraph" class="label label-success"><strong>VIEW PORTFOLIO</strong>
</div>
<br />
<div class="about-personal-info">
<h4><strong>Email: jaybittner#gmail.com</strong></h4>
<br />
<div class="about-icon" ng-repeat="profile in about.profiles">
<img src="{{ profile.icon }}" />
</div>
</div>
</div>
</div>
</div>
</div>
</section>
CSS -
#about {
height: 100%;
width: 100%;
background-image: -webkit-gradient(linear,left top,right bottom,color-stop(0.12, #061419),
color-stop(0.61, #36875F)
);
background-repeat: no-repeat;
}
#about .container-fluid, #about .container-fluid .row {
height: 100%;
width: 100%;
}
.about-left {
height: 100%;
background-image: url('../../images/jay-ocean.jpg');
background-repeat: no-repeat;
background-position: 0 100%;
border-right: 3px solid black;
}
.about-right {
width: 50%;
height: 100%;
}
.about-content {
width: 50%;
height: 100%;
margin: 0 auto;
padding-top: 20%;
padding-left: 5%;
text-align: center;
}
.about-content-title h1{
font-size: 3.4vw;
}
.about-content-info p {
font-size: 1vw;
word-spacing: 0.3vw;
}
.about-button button {
color: gray;
border: 1px solid black;
background-color: black;
}
.about-button a {
color: gray;
}
.about-personal-info h4 {
font-size: 1vw;
word-spacing: 0.3vw;
}
.about-icon {
display: inline;
word-spacing: 0.3vw;
}
.about-icon img {
width: 30px;
height: 30px;
border-radius: 10px;
border: 1px solid black;
}
Your problem seems to be in the navigation bar, where there is a solid container, when your page content lies in container-fluid.
It's hard for me to throw a straight off working code for you by now, but your issue is the placement of your navbar-brand. You could try to center it or adjust it's position via padding or margin in media queries.
To do so, put this in your CSS:
#media (max-width: 1199px)
{
.navbar-brand {
padding-left: 100px;
}
}
The max width in media query calculates the screen viewport and changes the appearance of the site for something desired by the exact width or height of the page on screen.
With max-width: 1199px this media query uses this padding-left attribute to .navbar-brand when the screen (or the browser window) is showing the page below this width.
You can also work around with this to use with min-width or even height related viewport settings in CSS.
When my web page is shown on small devices the menu collapses as expected but when you click on the collapsed menu icon the menu does not appear. There is a slight adjustment of the vertical height of the page below the menu and the last menu item half appears along the top of the page but the rest of the menu is nowhere to be seen.
My Bootstrap code looks like this:
#myNavbar {
position: relative;
border:none;
}
#myNavbar .nav {
position: absolute;
bottom: 0;
right: 0;
margin-bottom: -10px;
}
.navbar-nav.navbar-right:last-child {
margin-right: 0;
}
.navbar-default {
background:#FFFFFF;
border-left:none;
border-right:none;
border-top:none;
border-bottom:solid;
border-bottom-width:2px;
border-color:#01B6AC;
width:100% !important;
margin-right:0px;
padding-right:0px;
border-radius: 0 !important;
-moz-border-radius: 0 !important;
}
<nav class="navbar navbar-default">
<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>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img class="img-responsive" src="/assets/img/outa.png" 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>
</ul>
</div>
</div>
</nav>
Anyone know what I am doing wrong?
You problem is here
#myNavbar .nav {
position: absolute;
}
When you use position:absolute; the element will be positioned absolutely from the first positioned parent div, if it can't find one it will position absolutely from the window. You can refer to THIS question for further info. So what you can do is add #media query and set a size over certain pixels where the position will be absolute. So something like
#media(min-width: 400px) {
#myNavbar .nav {
position: absolute;
bottom: 0;
right: 0;
margin-bottom: -10px;
}
}
just give proper reference of bootstrap.css and bootstrap.js and your code will work fine.
I need to modify the dropdown-menu provided in Bootstrap, using the navbar-fixed-top, to appear on hover not vertically but horizontally li { display: inline-block } (that's easy), but so I need the actual ul.dropdown-menu to stretch the full width of the page. I can't seem to figure it out.
Don't give me a megamenu plugin or anything, please, just how can I fix it to stretch the width of the whole page? (not the page container either, the window)
Will probably need to wrap another element too, actually, as the ul needs to be centered.
So does anyone know how to do this?
EDIT: Figured it out (like 5 minutes after posting this) and with no added elements:
.nav { margin-bottom: 0; }
.dropdown { position: static; }
.dropdown-menu { width: 100%; text-align: center; }
.dropdown-menu>li { display: inline-block; }
and there you have it!
First you shouldn't wrap the navbar component in a div.container then update the css with the following Code:
.nav > li.dropdown.open {
position: static;
}
.nav > li.dropdown.open .dropdown-menu {
display:table; width: 100%; text-align: center; left:0; right:0;
}
.dropdown-menu>li {
display: table-cell;
}
check the demo here http://www.bootply.com/8EgGsi4F7w
<li class="dropdown open" style="position: initial;">
<ul class="dropdown-menu" style="width: 100%;">
just use the position: initial in the main li(dropdown) of your nav and in the child ul dropdown-menu set width 100%
Here the alternative that worked for me.
I just tried option 2. The key is:
Adding class position-static along with (the) dropdown class, which is the parent class of dropdown-menu as follows:
<li class="nav-item dropdown position-static">
Credit to its author: VigneshKannan3 from GeeksforGeeks
It looks like this answer to a similar question has the same approach.
Check this
.nav > li.dropdown.open {
position: static;
}
.nav > li.dropdown.open .dropdown-menu {
display: table;
border-radius: 0px;
width: 100%;
text-align: center;
left: 0;
right: 0;
}
.dropdown-menu > li {
display: table-cell;
height: 50px;
line-height: 50px;
vertical-align: middle;
}
#media screen and (max-width: 767px) {
.dropdown-menu > li {
display: block;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<div class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<div class="navbar-brand">Blackcat</div>
<button class="navbar-toggle" data-toggle="collapse" data-target=".btnCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse btnCollapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Shop</li>
<li class="dropdown">
Artist <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Rich</li>
<li>Shay</li>
<li>Jose</li>
<li>Marie</li>
<li>Simon</li>
<li>Jamie</li>
<li>Andrew</li>
<li>Teddie</li>
</ul>
</li>
<li>FAQs</li>
<li>Contact</li>
</ul>
</div>
</div>
<!-- end container -->
</div>
<!-- end navbar navbar-inverse navbar-static-top -->
<!-- container -->
<div class="container">
<div class="row">
<p>Site content here...</p>
</div>
<!-- End row -->
</div>
<!-- End container -->