Force Navbar elements to stay in one line - html

I wan't the elements of my Bootstrap Navbar to stay in one line at every width.
I know this question has already been asked several times and I've tried various solutions, but no one worked for my case.
Here's my code:
#head-navbar {
width: 100%;
white-space: nowrap;
display: inline-block;
overflow: hidden;
}
.nav>li {
display: inline-block;
white-space: nowrap;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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>
<nav class="navbar navbar-inverse navbar-fixed-top navbar-collapse" id="head-navbar">
<ul class="nav navbar-nav">
<li><a class="#" href="#">Home</a>
</li>
<li>Page 1
</li>
<li>Page 2
</li>
</ul>
<ul class="nav navbar-nav pull-right">
<li>DE
</li>
<li>IT
</li>
</ul>
</nav>
I want my Navbar to look like this on a smaller screen:
and not like this:

Just add display: inline-block; to your li and they will be displayed inline.
.nav>li {
display: inline-block;
}
Also if you want to display both ul in the same line you can do the same thing to the ul elements.Here you have a jsfiddle for both ul inline.
Also in firefox you will have a breakpoint in 768px so you should remove the white-space:nowrap
#head-navbar {
white-space: normal;
}
P.s : i don't know if it is a TYPO but you should use .pull-right instead of .navbar-right to float right an element

It's because of media queries, so on smaller screens it changes the style. Just add these:
.navbar-nav {
float: right;
margin: 0;
}
.navbar-nav > li {
float: right;
}

Add the below css, This should work for you.
#head-navbar {
width: 100%;
white-space: nowrap;
display: inline-block;
overflow: hidden;
}
.nav>li {
display: inline-block;
width:initial;
float:left;
white-space: nowrap;
}
.nav {
display: inline-block;
}
#media screen and (max-width:768px)
{
.nav.navbar-nav.pull-right { float:none !important; }
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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>
<nav class="navbar navbar-inverse navbar-fixed-top navbar-collapse" id="head-navbar">
<ul class="nav navbar-nav">
<li><a class="#" href="#">Home</a>
</li>
<li>Page 1
</li>
<li>Page 2
</li>
</ul>
<ul class="nav navbar-nav pull-right">
<li>DE
</li>
<li>IT
</li>
</ul>
</nav>

.pull-right{
float:right;
}
#head-navbar {
width: 100%;
white-space: nowrap;
display: inline-block;
overflow: hidden;
}
.nav>li {
display: inline-block;
width:initial;
float:left;
white-space: nowrap;
}
.nav {
display: inline-block;
}
#media screen and (max-width:768px)
{
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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>
<nav class="navbar navbar-inverse navbar-fixed-top navbar-collapse" id="head-navbar">
<ul class="nav navbar-nav">
<li><a class="#" href="#">Home</a>
</li>
<li>Page 1
</li>
<li>Page 2
</li>
</ul>
<ul class="nav navbar-nav pull-right">
<li>DE
</li>
<li>IT
</li>
</ul>
</nav>

Related

CSS :before width

Simple question here I can't figure out (probably the solution is ultra-easy I just cannot see it). If you hover the mouse on the a-element, the :before style takes the width till the end of the page.
Why is that? Any solutions to make it inherit the width from the li-element only (make it always as wide as the navigation link)?
/* navbar style */
#sidebar-wrapper {
}
.navbar {
padding: 0px;
}
.navbar li:before {
content: '';
position: absolute;
top: 0px;
height: 3px;
width: 100%;
background-color: #aaa;
transition: 0.2s ease;
z-index: -1;
}
.navbar li:hover:before {
height: 100%;
}
.navbar li:first-child:before {
background-color: #ec1b5a
}
.navbar li:nth-child(2):before {
background-color: #3DEC1B
}
.navbar li:nth-child(3):before {
background-color: #D3EC1A
}
.navbar li:nth-child(4):before {
background-color: #1B9AEC
}
<head>
<meta charset="utf-8">
<title>Matt Chowski's portfolio</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/popper.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<nav class="nav justify-content-between" id="sidebar">
<ul class="nav">
<li class="navbar-brand"><a class="nav-link">Mateusz Wojciechowski</a></li>
</ul>
<ul class="nav navbar" id="navlinks">
<li><a class="nav-link active" href="#">Home</a></li>
<li><a class="nav-link" href="#">About</a></li>
<li><a class="nav-link" href="#">Gallery</a></li>
<li><a class="nav-link" href="#">Contact</a></li>
</ul>
</nav>
</div>
</body>
Thank you for all the help <3
Check out this code.
All I did is added position: relative; to li and also added display: flex to ul
https://codepen.io/Izulito/pen/xXmOqq

How do I center bootstrap tabs in a div?

I've been trying to figure this out for so long and I've finally given up... I've already defined a div and I would like to center some tabs in it, but nothing seems to work. Any suggestions?
HTML:
<section class="area">
<div class="container">
<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#tab1">TAB 1</a></li>
<li><a data-toggle="tab" href="#tab2">TAB 2</a></li>
<li><a data-toggle="tab" href="#tab3">TAB 3</a></li>
</ul>
</div>
</div>
</div>
</section>
CSS:
.area{
border: 2px solid #9A9A9A;
border-radius: 3px;
background-color: #FFFFFF;
height: 70%;
width: 75%;
margin: auto;
margin-bottom: 20px;
overflow-y: auto;
overflow-x: hidden;
}
.nav-tabs > li {
float: none;
display: inline-block;
zoom: 1;
}
.nav-tabs {
text-align: center;
}
Thanks in advance.
There is a problem with your code , you have set width to area 75% the container width 1170px , container pull out the area div, thats why you got this problem, i just put the area div into container, please check with the snippet. i have solved your issue.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
.area{
border: 2px solid #9A9A9A;
border-radius: 3px;
background-color: #FFFFFF;
height: 70%;
width: 100%;
margin: auto;
margin-bottom: 20px;
overflow-y: auto;
overflow-x: hidden;
text-align:center;
}
.nav-tabs > li {
float: none;
display: inline-block !important;
zoom: 1;
}
.nav-tabs {
text-align: center;
}
</style>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="area">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#tab1">TAB 1</a></li>
<li><a data-toggle="tab" href="#tab2">TAB 2</a></li>
<li><a data-toggle="tab" href="#tab3">TAB 3</a></li>
</ul>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
Put you parent class name before the bootstrap inbuilt classes. May b your css file is not overriding the bootstrap css file.
.area .nav-tabs > li {
float: none;
display: inline-block;
zoom: 1;
}
.area .nav-tabs {
text-align: center;
}
Try this:
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#tab1">
<center>TAB 1</center>
</a></li>
<li><a data-toggle="tab" href="#tab2"><center>TAB 2</center></a></li>
<li><a data-toggle="tab" href="#tab3"><center>TAB 3</center></a></li>
</ul>
In order to centrally align the tabs you need to add the following:
.area .nav {
text-align:center;
}
.area .nav-tabs>li {
float: none;
display:inline-block;
}
https://jsfiddle.net/tghLqu24/2/ - fiddle created for you to see it working.

How to change in bootstrap navbar height?

I want to change height of navbar in bootstrap. My code:
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<div class="navbar-brand">MyDatoo</div>
</div>
<ul class="nav navbar-nav">
<li>Home</li>
<li>Page 1</li>
<li>Page 2</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</nav>
I want to change this navbar height:
.navbar {
height: 100px !important; /*i assume your navbar size 100px*/
}
if you dealing with mobile
#media only screen and (min-width: 600px) {
.navbar {
height: 100px !important;
}
}
#media only screen and (min-width: 768px) {
.navbar {
height: 120px !important;
}
}
You can add this css
.navbar {
height: YOUR_SIZE !important;
}

How can I display an inline list with a fixed position?

I'm trying to display an inline list, with the first 5 elements pulled left, and the last 2 elements pulled right, as shown below:
This inline list needs to cling to the top of the screen when the user scrolls past it, and so I need to set position: fixed and top: 0px. However, when I try to do this, the left side of the list ends up stacking onto the right side, as shown below:
Is there any way to preserve the inline display of the list while using a fixed position? If not, what are other solutions to this issue?
Here's my code, sorry if it's a mess or not formatted correctly. I've just started playing around with web dev:
CSS:
.menu-header {
background-color: #2658C9;
}
.menu-header .pull-left {
margin-left: 10%;
overflow: hidden;
white-space: nowrap;
}
.menu-header .pull-right {
margin-right: 10%;
overflow: hidden;
white-space: nowrap;
}
.menu-header ul {
padding-left: 0px;
display: inline;
}
HTML:
<div class="menu-header">
<div class="row">
<ul class="menu-header-list">
<div class="pull-left">
<li>Home</li>
<li>Tech</li>
<li>Tutorials</li>
<li>Articles</li>
<li>Papers</li>
</div>
<div class="pull-right">
<li>About</li>
<li>Contact</li>
</div>
</ul>
</div>
</div>
Any help would be much appreciated, as I've been trying to fix this for hours. Changing the display & using floats hasn't fixed the problem. Thanks!
Try this Fiddle
.navbar {
background: #2658C9;
color: white;
position: fixed;
top: 0;
width: 100%;
}
.navbar-default .navbar-nav > li > a{
color: white;
}
<nav class="navbar navbar-default">
<div class="container-fluid">
<ul class="nav navbar-nav pull-left">
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
<ul class="nav navbar-nav pull-right">
<li>Link</li>
<li>Link</li>
</ul>
</div>
</nav>
The problem is caused because you didn't set width:100% to your header.
.menu-header{
width:100%;
}
Look into these CSS:
.menu-header {
background-color: #2658C9;
width:100%;
overflow:hidden;
}
.menu-header .pull-left {
float:left;
}
.menu-header .pull-right {
float:right;
}
.menu-header ul {
padding-left: 0px;
}
.menu-header ul li {
display:inline-block;
}
float pull left and right and display li in inline-block
this is the solution for you
.row{
width:100%;
position:fixed;
}
fix your .row not the 'ul'
for the complete code , I have created a complete code.if you want you cant try it.
<!DOCTYPE html>
<html>
<head>
<title>working with bootstrap offline</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="index.css">
<style type="text/css">
div.menuone ul li{
list-style-type: none;
display: inline;
margin:20px;
}
div.menutwo ul li{
ist-style-type: none;
display: inline;
margin: 30px;
}
div.menuone ul li a, div.menutwo ul li a{
color: white;
}
div.menuone{
padding-top: 30px;
}
div.menutwo{
padding-left: 50px;
padding-top: 30px;
}
</style>
</head>
<body>
<div class="menu-header">
<div class="row" style="background-color:blue;">
<div class="col-md-8 menuone">
<ul>
<li>Home</li>
<li>Tech</li>
<li>Tutorials</li>
<li>Articles</li>
<li>Papers</li>
</ul>
</div>
<div class="col-md-4 menutwo">
<ul>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</ul>
</div>
</div>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</body>
</html>

Bootstrap Nav Disappears on Resize

I have a Bootstrap 3 navbar. When I scale the browser window to a low resolution or access the page with my mobile I have no menu. Usually, with Bootstrap I have a collapsed navigation but it is nowhere to be found.
Here is the HTML:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.php"><img src="images/logo.png"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li class="aktiv" >Advertisers</li>
<li>Publishers</li>
<li>About</li>
<li>Press</li>
</ul>
</div>
</div>
</nav>
CSS:
.navbar {
background-color: #333E48;
border: 0;
display: block!important; /* From Stack Overflow */
}
.navbar-brand > img,
.navbar-brand {
padding:0px;
margin:0;
}
.navbar-brand > img {
padding: 4px;
height: 50px;
margin: auto;
vertical-align: middle;
display: inline-block;
}
.navbar-brand,
.navbar-nav li a {
line-height: 90px;
height: 90px;
padding-top: 0px;
}
.nav-collapse.collapse {
height: auto !important; /* From Stack Overflow */
overflow: visible !important; /* From Stack Overflow */
}
I added display: block!important; to .navbar after reading Nav disappears after resize
I added height: auto !important; overflow: visible !important; to .nav-collapse.collapse after reading Twitter bootstrap responsive navigation disappears after opening and closing
Issue still persists.
It isn't clear in your question but your missing the toggle button to open and close the menu when your viewport is reduced, otherwise the mobile menu will always be open.
nav.navbar-default {
background: #333E48;
border: 0;
}
.navbar-default .navbar-brand > img,
.navbar-default .navbar-brand {
padding: 0px;
margin: 0;
}
.navbar-default .navbar-brand > img {
padding: 4px;
height: 50px;
margin: auto;
vertical-align: middle;
display: inline-block;
}
.navbar-default .navbar-brand,
.navbar-default .navbar-nav li a {
line-height: 90px;
height: 90px;
padding-top: 0px;
}
.navbar-default .nav-collapse.collapse {
height: auto !important;
/* From Stack Overflow */
overflow: visible !important;
/* From Stack Overflow */
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-collapse" 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="index.php">
<img src="http://placehold.it/100x50/fff/fff" />
</a>
</div>
<div class="collapse navbar-collapse" id="bs-collapse">
<ul class="nav navbar-nav navbar-right">
<li>Home
</li>
<li class="aktiv">Advertisers
</li>
<li>Publishers
</li>
<li>About
</li>
<li>Press
</li>
</ul>
</div>
</div>
</nav>
Just have to remove the collapse class on div#navbar
Here is a fiddle
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.php"><img src="images/logo.png"></a>
</div>
<div id="navbar" class="navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li class="aktiv" >Advertisers</li>
<li>Publishers</li>
<li>About</li>
<li>Press</li>
</ul>
</div>
</div>
</nav>
And rewrite the css for the xs view