My question is how you can center the pills?
I've tried to add center block around and also to change the float:left to float:center but nothing helps.
This has gotten much simpler! You just need to use the text-center class on the container, and apply display:inline-block to the ul. Just make sure you have a line break or paragraph tag separating the nav from any other elements within the container.
Done! 2 class additions, 1 line of CSS (don't modify the bootstrap css file!).
HTML:
<div class="col-md-12 text-center">
<p>Copyright stuff</p>
<ul class="nav nav-pills center-pills">
<li>Footer nav link</li>
<li>Footer nav link</li>
</ul>
</div>
CSS:
.center-pills { display: inline-block; }
Edit 2015: As Artur Beljajev has brought up, Flexbox support is now common enough that you may want to use that instead:
.center-pills {
display: flex;
justify-content: center;
}
If you'd like variable width pills in a variable width container, I'd suggest using the inline-block display type and adding a class to the pill container.
Here is how I extended bootstrap for centering pills.
CSS:
.centered-pills { text-align:center; }
.centered-pills ul.nav-pills { display:inline-block; }
.centered-pills li { display:inline; }
.centered-pills a { float:left; }
* html .centered-pills ul.nav-pills { display:inline; } /* IE6 */
*+html .centered-pills ul.nav-pills { display:inline; } /* IE7 */
HTML:
<div class="row">
<div class="span12 centered-pills">
<ul class="nav nav-pills">
<li>derek</li>
<li>brooks</li>
<li>is</li>
<li>super</li>
<li class="active">awesome</li>
</ul>
</div>
</div>
Or flexbox approach:
.nav-pills {
display: flex;
justify-content: center;
}
If you want the pills to be centered instead of left aligned you will need to change the css. You will need to specifiy a width and change the margin to be auto.
For example:
.tabs, .pills {
margin: 0 auto;
padding: 0;
width: 400px;
}
While the answer of #minaz works for a list with a known width, i'd propose a different solution which actually works even if you change the content of the list:
.tabs, .pills {
text-align: center;
}
.tabs li, .pills li {
float: none;
}
Or in SCSS:
.tabs, .pills {
text-align: center;
li { float: none; }
}
This will center the text inside the list, and resets the float property for the list items so they are affected by the text-align property.
A simple solution with Bootstrap 4
Use justify-content-center at <ul> nav
Example:
#import url('https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="mt-5">
<ul class="nav nav-pills mb-3 justify-content-center" id="pills-tab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="pills-home-tab" data-toggle="pill" href="#pills-home" role="tab" aria-controls="pills-home" aria-selected="true">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="pills-profile-tab" data-toggle="pill" href="#pills-profile" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" id="pills-contact-tab" data-toggle="pill" href="#pills-contact" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</a>
</li>
</ul>
<div class="tab-content" id="pills-tabContent">
<div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
<div class="card text-white bg-success mb-3 mx-2 px-2">
<h1>Hi</h1>
</div>
</div>
<div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">
<div class="card text-white bg-info mb-3 mx-2 px-2">
<h1>Hi</h1>
</div>
</div>
<div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">
<div class="card text-white bg-danger mb-3 mx-2 px-2">
<h1>Ni Hao</h1>
</div>
</div>
</div>
</div>
Bootstrap 4 solution is very easy:
<ul class="nav justify-content-center">
https://getbootstrap.com/docs/4.0/components/navs/
Related
this code on mobile view works fine but on desktop view
see the snippet here how the dogs tab content (another collapsible card ,click on Dog 1 red header) can't collapse
<div class="card-body">
<ul class="list-group">
<li class="list-group-item text-bg-danger" aria-current="true" data-bs-toggle="collapse" role="button" data-bs-target="#dog1">Dog 1</li>
<div id="dog1" class="collapse">
<li class="list-group-item d-flex justify-content-between align-items-center">Eyes <span>2</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">Tail<span>short</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">Color <span>black</span>
</li>
</div>
</ul>
<br>
</div>
All collapses in .responsive have display-block set
.responsive-tabs .card .collapse {
display: block;/*OK*/
}
Solution: only set first-child using >
.responsive-tabs .card > .collapse {
display: block;
}
This question already has answers here:
Why don't flex items shrink past content size?
(5 answers)
Closed 1 year ago.
I have 2 tabs and each tab is displaying as flex. My need is if #myTabContent overflow .main-panel due to the list, I want a scroll bar only on the list, not on the whole div.
By this way, the #myTabContent should never overflow.
Here the JSFiddle with the behavior, and the following snippet:
.main-panel{
background: lightblue;
height: 300px;
}
#myTabContent {
margin: 5px;
color: white;
background: #0007;
}
#myTabContent > div {
display: none;
}
#myTabContent .active {
display: flex;
flex-flow: column;
height: 100%;
}
.data-main {
display: flex;
flex-flow: row;
}
.data-left {
flex: 0 1 150px;
background: #a007;
}
.data-right {
flex: 1 1 auto;
background: #0a07;
}
.list-group {
overflow-y: auto;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<div class="main-panel">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="data-tab" data-toggle="tab" href="#data" role="tab" aria-controls="data" aria-selected="true">Data</a>
</li>
<li class="nav-item">
<a class="nav-link" id="preview-tab" data-toggle="tab" href="#preview" role="tab" aria-controls="preview" aria-selected="false">Preview</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="data" role="tabpanel" aria-labelledby="data-tab">
<h3>Data</h3>
<div class="data-main">
<div class="data-left">
<h4>Tabs</h4>
<ul class="list-group">
<li class="list-group-item list-group-item-action py-1">a</li>
<li class="list-group-item list-group-item-action py-1">b</li>
<li class="list-group-item list-group-item-action py-1">c</li>
<li class="list-group-item list-group-item-action py-1">d</li>
<li class="list-group-item list-group-item-action py-1">e</li>
<li class="list-group-item list-group-item-action py-1">f</li>
</ul>
</div>
<div class="data-right">
<h4>Sections</h4>
</div>
</div>
</div>
<div class="tab-pane fade" id="preview" role="tabpanel" aria-labelledby="preview-tab">
<h3>Preview</h3>
</div>
</div>
</div>
Can't you simply set the parent container to have this property?:
height: fit-content
This should always force your parent container to be as high as the child is.
I'm currently trying to create an effect - imagine a fullscreen image which is fixed and will be hidden below the content div on scroll (parallax). Additionally I want the navbar to not move on scroll, hence it's fixed. But I want the navbar to also be hidden below the content div as soon as it's being reached on scroll.
Therefore I've tried to use z-index, but without success. Somehow I'm not able to hide the fixed navbar below the content div.
Header:
<div class="container-fluid position-fixed">
<div class="row m-0 w-100">
<div class="col-2 justify-content-center d-flex offset-5">
<a class="align-self-center" routerLink="">
<h1>NØREBRO STUDIOS</h1>
</a>
</div>
<div class="col-5 pl-5">
<ul class="nav justify-content-start">
<li class="nav-item mr-5">
<a class="nav-link" routerLink="cases">Work</a>
</li>
<li class="nav-item mr-5">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</div>
CSS:
.container-fluid {
z-index: 1;
background-color: transparent;
padding: 3em 0em;
}
Content (upper-container is supposed to hide the header on scroll):
<div class="container-fluid px-0">
<app-transparent-header></app-transparent-header>
</div>
<div class="front-image min-vh-100 min-vw-100">
</div>
<div class="container-fluid upper-container">
...
CSS:
.front-image {
background-image: url("/assets/images/savum/savum-front.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.upper-container {
padding: 15em 15em 0em 15em;
background-color: blue;
}
.container-fluid {
z-index: 9999;
}
If I understand correctly, you want the header to be hidden but you want the navigation bar to be fixed the top of the screen when you scroll:
.nav-parent {
position: sticky;
position: -webkit-sticky;
top: 0;
z-index: 999;
}
Set a parent class over the navigation bar, and assign it those values
I'm using bootstrap 4.1 navbar here. I want my div "#pin_to_top" to be always at the top of the navbar. So that on wider screens it is
Logo - Menu - "#pin_to_top" (all on the same row)
and on smaller devices it is like
Logo - "#pin_to_top#
Menu (menu is under my logo and div)
Also any other piece of advice about my code would be much appreciated :)
.navbar-brand img {
height: 2rem;
}
.phonecall {
border-radius: 2rem;
background-color: #28a745;
font-weight: bold;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-light bg-light d-flex flex-column flex-md-row navbar-expand">
<a class="navbar-brand" href="#">
<p>LOGO</p>
</a>
<div class="d-flex">
<ul class="navbar-nav flex-fill pl-md-5 text-nowrap">
<li class="nav-item "><a class="nav-link" href="#">Menu1</a></li>
<li class="nav-item "><a class="nav-link" href="#">Menu2</a></li>
<li class="nav-item "><a class="nav-link" href="#">Menu3</a></li>
<li class="nav-item "><a class="nav-link" href="#">Menu4</a></li>
</ul>
</div>
<div id="pin_to_top" class="ml-auto d-flex flex-column flex-md-row align-self-start" >
<div class="p-2">
<a class="">Some info here</a>
</div>
<div class="navbar-text text-nowrap phonecall px-2">
<a class="text-white" href="tel:+78005553535">+7-(800)-555-35-35</a>
</div>
</div>
</nav>
Bootstrap 4 includes a fixed-top class to solve your problem. ;)
you should give position fix to your class and give this top:0;
use position absolute for parent and add some css for a good design on small screen
#include media-breakpoint-up(md) {
div#pin_to_top {
position: absolute;
left: auto;
right: 0px;
}
}
I want to eliminate the the margin in the following nested list-items by forcing the inner list-items to fill their parent list-item. See JSFiddle:
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
This is the heading
</div>
<div class="panel-body">
<ul class="list-group parentList">
<li class="list-group-item">
Hello
</li>
<li class="list-group-item nomargin">
<ul class="list-group childList">
<li class="list-group-item nomargin">
Hello.Child 1
</li>
<li class="list-group-item child">
Hello.Child 2
</li>
</ul>
</li>
</ul>
</div>
</div>
And here is the css:
.nomargin {
margin-left: 0px !important;
margin-right: 0px !important;
margin-top: 0px !important;
margin-bottom: 0px !important
}
.parentList {
display: inline-block;
position: relative;
}
.childList {
width: 100%;
}
These spaces caused by padding ,So you need to add padding: 0 not margin
Demo