I want to apply an amount of space before an element in an unordered list. Here is the URL:http://hottdoggfilms.com. I try to centralize the dog's picture with logo in between the other list elements. But there is uneven space between the elements "Recent Work" and "About Us". My markup is:
<div id="navbar" class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<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>
<h1><a class="brand" id="cf" href="#"><img class="bottom" src="hottdogg.png" data-min-width-481="hottdogg.png" alt="Tipit"><img class="top" src="hottdogg.png" data-min-width-481="hottdoggHover.png" alt="Tipit"></a></h1>
<nav class="nav-collapse collapse" role="navigation">
<h2 class="visuallyhidden">Navigation</h2>
<ul class="nav">
<li class="active">Home</li>
<li>Recent work</li>
<li class="divider"></li>
<li style="margin-left:20px">About us</li>
<li>Contact us</li>
</ul>
</nav>
</div>
</div>
</div>
And the CSS:
#navbar .nav {
font-size: 0;
text-align: center;
white-space: nowrap;
float: none;
margin: 0;
}
#navbar .nav li {
display: inline-block;
float: none;
}
#navbar .nav a {
margin-bottom: 0;
font-size: 16px;
line-height: 37px;
height: 37px;
padding-left: 1.4em;
padding-right: 1.4em;
}
#navbar .divider {
width: 186px;
}
To me, the nav is quite confusing, with the divider and all.
Why not to go for a simpler solution?
http://codepen.io/anon/pen/IeLCf
nav {
margin:0 auto;
border:1px dashed black;
text-align:center;
}
nav a {
position:relative;
top:-100px;
display:inline-block;
vertical-align:middle;
padding:10px;
text-align:left;
}
<nav>
Home
LOOOOOOONG
<img src="http://hottdoggfilms.com/hottdoggHover.png" alt="" />
shrt
LOOONG
</nav>
Try to add width to #about-us' element 100px and lower the width of the .divider element to 145px.
I agree with the above answer, having the image as part of your navigation is a better solution.
However, if you want to keep what you have now, you can use the :nth-child selector.
http://www.w3schools.com/cssref/sel_nth-child.asp
https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child
in your case:
.nav > li:nth-child(3) {
margin-left: 60px; //as much as you need
}
//and for when the menu collapses
.nav > li:nth-child(3).small-screen {
margin-left: 0; //or whatever the default is
}
Related
I want to move the last li to right side but my CSS is not working.
.gCountryFlag {
margin-left: 0;
padding-left: 0;
}
ul li {
list-style: none;
}
.navbar-collapse ul li:last-child {
float: right;
}
.gCountryFlag li {
float: left;
display: inline-block;
margin: 5px;
}
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<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><a runat="server" href="/">Home</a></li>
<li><a runat="server" href="/About.aspx">About</a></li>
<li><a runat="server" href="/Contact.aspx">Contact</a></li>
<li>
<div class="flagChangeCountry">
<asp:Image CssClass="topFlag" runat="server" ID="currentCultureFlagImage" />
<%--<asp:Literal runat="server" Text="<%$Resources:LocalisedText, ChangeCountryText %>" />--%>
</div>
</li>
</ul>
</div>
</div>
</div>
i want to move this image to right side which is in div. here it is.
<li>
<div class="flagChangeCountry">
<asp:Image CssClass="topFlag" runat="server" ID="currentCultureFlagImage" />
<%--<asp:Literal runat="server" Text="<%$Resources:LocalisedText, ChangeCountryText %>" />--%>
</div>
</li>
Also, I want to align the flag image with other text in same line. Here is screenshot for how the flag is looking which is not right side and also which is not aligned with other text.
All you need is to set float: right for the last li item. And don't forget about clearfix.
ul {
border: 1px solid red;
padding: 0;
margin: 50px;
}
ul:after {
/* clearfix */
content: "";
display: table;
clear: both;
}
li {
float: left; /* all li items */
padding: 0;
margin: 0;
border: 1px solid green;
list-style: none;
}
li:last-child {
float: right; /* last li item */
}
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
I would use display: flex instead of float. You have more control over your elements in display flex. In display flex you can easily adjust your element inside the box. Use flex grow to make an element bigger or smaller.
Please take a look at this guide-to-flexbox.
Try add this in class .navbar-nav
.navbar-nav {
width: 100%;
}
.navbar-collapse ul li:last-child {
float: right;
}
This is because bootstrap.css has overwritten your css file.
You need to set a width to the ul, like this:
ul{
float:left;
width: 100%;
}
and here's a working example in jsfiddle:
https://jsfiddle.net/d7dtm4we/
Edit: I copied the jsfiddle, to the code snippet, and added the width 100% vs no set width
.gCountryFlag {
margin-left: 0;
padding-left: 0;
}
ul.nav{
margin: 0;
padding: 0;
float:left;
width: 100%;
}
ul.nav2{
margin: 0;
padding: 0;
float:left;
}
ul li {
list-style: none;
float:left;
padding: 5px
}
ul li:last-child {
float: right;
}
.gCountryFlag li {
float: left;
display: inline-block;
margin: 5px;
}
<ul class="nav navbar-nav">
<li><a runat="server" href="/">Home</a></li>
<li><a runat="server" href="/About.aspx">About</a></li>
<li><a runat="server" href="/Contact.aspx">Contact</a></li>
<li>
<div class="flagChangeCountry">
<img src="http://satyr.io/32x20?flag=gbr" />
</div>
</li>
</ul>
<ul class="nav2 navbar-nav">
<li><a runat="server" href="/">Home</a></li>
<li><a runat="server" href="/About.aspx">About</a></li>
<li><a runat="server" href="/Contact.aspx">Contact</a></li>
<li>
<div class="flagChangeCountry">
<img src="http://satyr.io/32x20?flag=gbr" />
</div>
</li>
</ul>
Have you tried clear:left; before setting it float: right;
.navbar-collapse ul li:last-child {
clear:left;
float: right;
}
I try to design a centered logo navigation but i have some output problems
.navbar {
background-color: #231f20;
min-height: auto;
position: relative;
top: 0px;
font-size: 13px;
width: auto;
border-bottom: none;
margin-bottom: 0px;
padding: 40px 0px;
}
.navbar-brand {
padding: 0 15px;
height: 96px;
}
#media (min-width: 768px) {
.navbar-nav {
position: relative;
right: -50%;
}
.navbar-nav > li {
position: relative;
left: -50%;
}
.navbar-nav > li a {
line-height: 126px;
vertical-align: middle;
padding: 0 24px;
}
}
#media (min-width: 992px) {
.navbar-nav > li a {
padding: 0 40px;
}
}
#media (min-width: 1200px) {
.navbar-nav > li a {
padding: 0 50px;
}
}
/////
<nav class="navbar navbar-default">
<div class="container-fluid">
<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 hidden-sm hidden-md hidden-lg" href="#"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Who We Are</li>
<li>Our Food</li>
<li class="hidden-xs"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></li>
<li>Book a Table</li>
<li>Promotions</li>
</ul>
</div>
</div>
</nav>
Also, demo at http://codepen.io/anon/pen/egqxjW
What is the problem that is causing that white space?
PS: Is there a better way to get the same result? What should i do to include the logo only once in the source code?
right: -50%; moved the ul 50% to the right of where it should be. Its width stay the same (100% of the container), and it's moved by 50% to the right, so 50% of the ul is outside of the container, bleeding out of screen.
I made some change to achieve the same result you want, using text-align: center and display: inline-block instead. They are marked with /* change */ in the CSS.
#import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
.navbar {
background-color: #231f20;
min-height: auto;
position: relative;
top: 0px;
font-size: 13px;
width: auto;
border-bottom: none;
margin-bottom: 0px;
padding: 40px 0px;
}
.navbar-brand {
padding: 0 15px;
height: 96px;
}
#media (min-width: 768px) {
ul.navbar-nav {
position: relative;
float: none;
/* change */
text-align: center;
/* change */
}
ul.navbar-nav>li {
position: relative;
display: inline-block;
/* change */
vertical-align: middle;
float: none;
}
ul.navbar-nav>li a {
line-height: 126px;
vertical-align: middle;
padding: 0 24px;
}
}
#media (min-width: 992px) {
.navbar-nav>li a {
padding: 0 40px;
}
}
#media (min-width: 1200px) {
.navbar-nav>li a {
padding: 0 50px;
}
}
<nav class="navbar navbar-default">
<div class="container-fluid">
<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 hidden-sm hidden-md hidden-lg" href="#"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Who We Are</li>
<li>Our Food</li>
<li class="hidden-xs">
<img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" />
</li>
<li>Book a Table</li>
<li>Promotions</li>
</ul>
</div>
</div>
</nav>
You have in your style a rule which is setting right: -50% on the navbar. Unfortunately, since the UL navbar displays as a block you wind up with an element that is 100% moving to the right 50% and winding up offscreen.
Instead of messing with right relative positioning you should try the navbar-right bootstrap class. Like so:
<ul class="nav navbar-nav navbar-right">
Most of the layouts from bootstrap play with floats, so you can't just use relative positioning expecting it to behave the same way.
Lastly you should compare it with the official documentation responsive navbar example here: https://getbootstrap.com/components/#navbar
You can see the resulting example here: http://codepen.io/anon/pen/NdQJRb
Can someone help me center the links on my nav bar please. I have been trying for the last 45 minutes.
Every time I use display: flex and justify-content: center it works until the hamburger button appears and is clicked on and then it all floats to the left.
Any help would be massively appreciated.
Thank you
Reece
.navbar {
background-color: #000;
justify-content: center;
height: auto;
font-family: Gill Sans, Verdana;
font-size: 15px;
line-height: 18px;
text-transform: uppercase;
letter-spacing: 2px;
font-weight: bold;
}
nav li:hover {
background-color: #C00;
margin: 0;
}
<nav>
<div class="navbar-container">
<!--NAVBAR CONTAINER START -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-header">
<button aria-controls="navbar" aria-expanded="false" class="navbar-toggle" data-target="#navbar" data-toggle="collapse" type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"></a>
</div>
<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav">
<li class="active">
<strong>HOME</strong>
</li>
<li>
<strong>MEET THE BAND</strong>
</li>
<li>
<strong>PHOTOS</strong>
</li>
<li>
<strong>VIDEOS</strong>
</li>
<li>
<strong>GET IN TOUCH</strong>
</li>
</ul>
</div>
</div>
<!-- NAVBAR CONTAINER END -->
</nav>
Check out this pen http://codepen.io/Danstan/pen/ENajRb the links will be at the center
ul.nav.navbar-nav {
display: table;
margin: 0 auto;
float: none !important;
}
.navbar {
background-color: #000;
height: auto;
font-family: Gill Sans, Verdana;
font-size: 15px;
line-height: 18px;
text-transform: uppercase;
letter-spacing: 2px;
font-weight: bold;
text-align:center;
}
.navbar .navbar-header {
display:table;
width:auto;
margin:auto;
}
nav li:hover {
background-color: #C00;
margin: 0;
}
Try this:-
/* Center Nav Bar */
#nav ul {
text-align: center;
}
link:-http://themes.typepad.com/guide/2011/12/navbar-center.html
I have my logo on the left with a white background in the header but my navbar keeps going underneath this on the right. I don't understand why this is happening. Also I don't think my navbar list is going straight across.
body {
background-color: #832040;
}
.navbar-default {
width: 100%;
height: 100px;
margin: 15px 0 0;
padding: 0;
background-color: #FFF;
}
.navbar ul.nav li a {
font-family: 'Righteous', sans-serif;
font-size: 38px;
color: #000;
padding: 25px;
margin: 0;
}
.navbar ul.nav li a:hover {
background: #000;
color: #fff;
height: 40px;
}
.logo {
width: 320px;
padding: 15px;
}
<div class="navbar-default">
<div class="logo">
<img src="HairSite/KatiesKuts-Logo.png">
</div>
<div class="navbar">
<div class="navbar nav pull-right">
<ul class="nav navabar-nav">
<li>Home</li>
<li>Bio</li>
<li>Appointments</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
you have missed out some proper html structure and classes bootstrap requires.
<div class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<div class="logo">
<img src="HairSite/KatiesKuts-Logo.png">
</div>
</div>
<div class="navbar">
<ul class="nav nav navbar-nav navbar-right">
<li>Home</li>
<li>Bio</li>
<li>Appointments</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
you could refer the following links for further references;
Logo Nav by Start Bootstrap
Navbar example form Bootstrap
This might help or give you some ideas. You're missing some HTML and I don't believe navbar-default was a class in 2.3.2.
body,
html {
background-color: #832040;
}
.navbar .navbar-inner {
background: white;
border: none;
border-radius: 0;
}
.navbar .navbar-inner .nav > li > a {
font-family: 'Righteous', sans-serif;
font-size: 15px;
color: #000;
padding-top: 50px;
padding-bottom: 50px;
}
.navbar .navbar-inner .btn-navbar {
margin-top: 45px;
}
.navbar .navbar-inner .nav > li > a:hover {
background: #000;
color: #fff;
}
#media (max-width: 991px) {
.navbar .navbar-inner .nav > li > a {
padding-top: 10px;
padding-bottom: 10px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" />
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<button type="button" 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>
</button>
<a class="brand" href="#">
<img src="http://placehold.it/320x100/000">
</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li>Home
</li>
<li>Bio
</li>
<li>Appointments
</li>
<li>Contact
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
</div>
I am trying to make my navigation bar stay in the same position even after resizing the window. It continues to move on resize and therefore the Navigation Bar and Nav brand are not aligned the way I want:
HTML:
<div class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="logo">
<center>
<a class="navbar-brand" href="#"><img src="Final.png"/></a>
</center>
</div>
<div>
<div class="navbar-header">
<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>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Services</li>
<li>Our Prices</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
</div>
</div>
</div>
CSS:
.nav, .navbar-nav {
display: inline-block;
margin:0;
float:none;
margin-top: -15px;
}
.navbar-nav li {
padding-left: 20px;
padding-right: 20px;
}
.navbar-nav li:hover {
background-color: #3c3c3c;
}
.navbar-nav {
color:red;
}
.navbar-brand {
float: none;
}
.navbar-center {
position: absolute;
width: 100%;
left: 0;
top: 0;
text-align: center;
margin: auto;
height:100%;
}
.navbar .navbar-collapse {
text-align: center;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
background-color: #f5f5f5;
}
.logo img {
height:80px;
margin-top: -15px;
}
.logo {
width: 40%;
margin: 0 auto;
}