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;
}
Related
I have 2 nav pill buttons that are supposed to change the layout when clicked. Both layouts include the sidebar which doesn't change.
Nav pill 1 changes the layout to:
sidebar | column 1 | column 2
Nav pill 2 changes the layout to:
sidebar | col 1 | column 2 | col 3
Right now what happens is that one column will show up next to the sidebar but the others will be under it and i'm not sure why this happens
#sidebar {
/* width: 250px; */
min-height: 100vh;
max-height: 100vh;
}
#sidebar_sub_header a {
border-radius: 0;
}
#sidebar_main_content::-webkit-scrollbar {
width: 0;
height: 0;
overflow-y: scroll;
scrollbar-width: none;
-ms-overflow-style: none;
overflow-x: hidden;
}
#sidebar_main_content img {
/* border: 1px solid white; */
border: 1px solid rgba(255, 255, 255, 0.1);
height:100px;
width:100px;
}
#sidebar_footer {
align-items: center;
text-align: center;
}
#main_body_channels {
height: 100vh;
}
#main_body_token_requirement_confirmation {
height: 100vh;
}
#main_body_roles {
height: 100vh;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<div class="container-fluid px-0">
<div class="row gx-0">
<nav class="col p-0 d-flex flex-column gap-1 bg-dark text-white" id="sidebar">
<!-- sidebar header -->
<div class="bg-dark text-white p-3" style="text-align: center; align-items: center;">
<h4>
sidebar header
</h4>
<div class="dropup-center dropdown p-1">
<a href="#" class="align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
username
</a>
<ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
<li><a class="dropdown-item" href="#">Delete User Info</a></li>
<li><a class="dropdown-item" href="#">Logout</a></li>
</ul>
</div>
</div>
<hr>
<!-- sidebar sub header -->
<div class="bg-dark text-white text-center" id="sidebar_sub_header">
<ul class="nav nav-pills flex-column mb-auto text-white" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<a href="#" class="nav-link text-white active" id="server_wide_button" data-bs-toggle="tab" data-bs-target="#server_wide_requirements_pane" type="button" role="tab" aria-controls="server_wide_requirements_pane" aria-selected="true">
button 1
</a>
</li>
<li class="nav-item" role="presentation">
<a href="#" class="nav-link text-white" id="channel_specific_button" data-bs-toggle="tab" data-bs-target="#channel_specific_requirements_pane" type="button" role="tab" aria-controls="channel_specific_requirements_pane" aria-selected="false">
button 2
</a>
</li>
</ul>
</div>
<br>
<!-- sidebar main content -->
<div class="flex-grow-1 overflow-auto bg-dark text-white" style="align-items: center;" id="sidebar_main_content">
<ul class="nav flex-column mb-auto align-items-center">
<li class="nav-item">
<a href="#" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="test tooltip">
<img src="https://cdn.pixabay.com/photo/2020/02/10/11/12/smiley-4836191_1280.png" class="rounded-circle">
</a>
</li>
<br>
<li class="nav-item">
<a href="#" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="test tooltip">
<img src="https://cdn.pixabay.com/photo/2020/02/10/11/12/smiley-4836191_1280.png" class="rounded-circle">
</a>
</li>
<br>
<li class="nav-item">
<a href="#" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="test tooltip">
<img src="https://cdn.pixabay.com/photo/2020/02/10/11/12/smiley-4836191_1280.png" class="rounded-circle">
</a>
</li>
<br>
<li class="nav-item">
<a href="#" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="test tooltip">
<img src="https://cdn.pixabay.com/photo/2020/02/10/11/12/smiley-4836191_1280.png" class="rounded-circle">
</a>
</li>
<br>
<li class="nav-item">
<a href="#" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="test tooltip">
<img src="https://cdn.pixabay.com/photo/2020/02/10/11/12/smiley-4836191_1280.png" class="rounded-circle">
</a>
</li>
<br>
<li class="nav-item">
<a href="#" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="test tooltip">
<img src="https://cdn.pixabay.com/photo/2020/02/10/11/12/smiley-4836191_1280.png" class="rounded-circle">
</a>
</li>
<br>
<li class="nav-item">
<a href="#" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="test tooltip">
<img src="https://cdn.pixabay.com/photo/2020/02/10/11/12/smiley-4836191_1280.png" class="rounded-circle">
</a>
</li>
<br>
</ul>
</div>
<!-- sidebar footer -->
<div class="p-3 bg-dark text-white" id="sidebar_footer">
<a href="#" class="btn btn-primary" id="add_bot_button" role="button" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="custom-tooltip" data-bs-title="test tooltip?">
test button
</a>
</div>
</nav>
<!-- TAB 1 -->
<div class="col tab-pane fade show active" id="server_wide_requirements_pane" role="tabpanel" aria-labelledby="server_wide_button" tabindex="0">
<div class="text-dark bg-danger" id="main_body_token_requirement_confirmation">
big main body column
</div>
<div class="p-0 d-flex flex-column gap-1 bg-secondary text-dark" id="main_body_roles">
right sidebar column
</div>
</div>
<!-- TAB 2 -->
<div class="col tab-pane fade" id="channel_specific_requirements_pane" role="tabpanel" aria-labelledby="channel_specific_button" tabindex="0">
<div class="p-0 bg-primary text-dark" id="main_body_channels">
column next to sidebar - same size?
</div>
<div class="bg-danger text-dark" id="main_body_token_requirement_confirmation">
big middle main body column
</div>
<div class="p-0 bg-secondary text-dark" id="main_body_roles">
right sidebar
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
using bootstrap 5.3.0 alpha-1
For Bootstrap tabs to work every tab-pane needs to be wrapped in a tab-content container.
For your columns; add the class container-fluid to each tab-pane, then add a row that contains your columns. In my basic example all columns are equal in width, but its easily adjustable.
I am assuming you want a full-page layout, so in CSS do:
#sidebar,
main {
height: 100vh;
max-height: 100vh;
}
Then give each container-fluid in <main> the class h-100, which is equal to height: 100%.
Next, give each row the class h-100. Add flex class align-items-stretch to make each column stretch the full available height.
Note: This snippet is build upon my answer of your previous question, not upon the code in your question.
#sidebar,
main {
height: 100vh;
max-height: 100vh;
}
.tab-pane .row .col {
background: tomato;
}
.tab-pane .row .col:nth-child(2) {
background: lightyellow;
}
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</head>
<body>
<div class="container-fluid px-0">
<div class="row gx-0">
<div class="col-4 d-flex flex-column gap-1 bg-dark text-white" id="sidebar">
<div class="p-2">
<h5>
Sidebar header
</h5>
</div>
<nav class="">
<ul class="nav nav-pills flex-column text-center" role="tablist" aria-orientation="vertical">
<li class="nav-link rounded-0 active" data-bs-toggle="tab" data-bs-target="#tab-1" type="button" role="tab" aria-controls="tab-1" aria-selected="true">Tab #1 - 2 Columns</li>
<li class="nav-link rounded-0" data-bs-toggle="tab" data-bs-target="#tab-2" type="button" role="tab" aria-controls="tab-2" aria-selected="false">Tab #2 - 3 Columns</li>
</ul>
</nav>
<div class="flex-grow-1 overflow-auto">
sidebar scroll
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
end sidebar scroll
</div>
<div class="">
Sidebar footer
</div>
</div>
<main class="col tab-content overflow-auto">
<div class="container-fluid h-100 tab-pane fade active show" id="tab-1" role="tabpanel" aria-labelledby="tab-1" tabindex="0">
<div class="row h-100 align-items-stretch">
<div class="col">
Col 1
</div>
<div class="col">
Col 2
</div>
</div>
</div>
<div class="container-fluid h-100 tab-pane fade" id="tab-2" role="tabpanel" aria-labelledby="tab-2" tabindex="0">
<div class="row h-100 align-items-stretch">
<div class="col">
Col 1
</div>
<div class="col">
Col 2
</div>
<div class="col">
Col 3
</div>
</div>
</div>
</main>
</div>
</div>
</body>
</html>
I have a div which is 200px in height. How do I divide the ul items in equal rows? They always align on top. I have colored the div green to make it obvious. Eventually I would be using ngFor in my ul, so I do not know how many rows are going to be there
<div style="height:200px">
<ul class="list-group list-group-flush">
<li class="list-group-item border-0 bg-transparent ">
test
</li>
<li class="list-group-item border-0 bg-transparent">
test1
</li>
</ul>
</div>
If you want to divide the content of your div then its best you should use table
<table style="height: 200px;">
<tbody>
<tr *ngFor="let hero of heroes">
<td class="align-baseline">
<td>{{hero.name}}</td>
</td>
</tr>
</tbody>
</table>
This is another way by which can give height to li
<ul class="list-group list-group-flush" style="line-height:180%">
<li class="list-group-item border-0 bg-transparent ">
test
</li>
<li class="list-group-item border-0 bg-transparent">
test1
</li>
</ul>
Would a flexbox solution work for you?
https://codepen.io/panchroma/pen/ExWpdeK
HTML
<div class="wrap">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
CSS
.wrap ul {
display: flex;
flex-direction: column;
justify-content: space-around;
height: 200px;
}
.wrap {
background-color: green;
}
I'm working on a Bootstrap 4 project where I have a nav bar with a centered logo and tagline, then some links to the left and right. It works pretty much as I would like, only ideally I would like the logo to stay centered after the nav links collapse.
Here is the code I have so far:
<nav class="navbar navbar-expand-lg navbar-light bg-white justify-content-between">
<div class="container-fluid ">
<div class="d-flex flex-column text-center order-lg-2">
<a class="navbar-brand" href="#">
<img src="http://via.placeholder.com/350x150" alt="">
</a>
<h2 class="tagline navbar-text">eco freindly clothing</h2>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-nav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse dual-nav w-50 order-lg-3">
<ul class="nav navbar-nav ml-auto">
<a class="nav-link" href="#">our ethics</a>
<a class="nav-link" href="#">contact</a>
<a class="nav-link" href="#">shop</a>
</ul>
</div>
<div class="navbar-collapse collapse dual-nav w-50 order-lg-1">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="">instagram</a></li>
<li class="nav-item"><a class="nav-link" href="">facebook</a></li>
<li class="nav-item"><a class="nav-link" href="">pinterest</a></li>
</ul>
</div>
</div>
</nav>
Currently after the links collapse the navbar toggle is on the right and logo and tagline on the left. How can I retain the logo and tagline in the center?
Here is a codeply
Thanks for any help!
The flexbox parent of the brand, logo, navbar toggler and 2 collapsable menus is .container-fluid, not the <nav>. So you need to do flex-direction: column; on small screens and flex-direction: row; with justify-content: space-between; on larger screens.
You can use bootstrap built-in classes for that too.
<nav class="navbar navbar-expand-lg navbar-light bg-white">
<div class="container-fluid flex-column flex-lg-row justify-content-lg-between">
...
</div>
</nav>
fiddle: http://jsfiddle.net/aq9Laaew/144985/ (don't want to register with codeply)
You can do this really simply by creating a "centered" class for the div containing your logo and header text.
.centered {
margin:auto;
display:block;
}
Is this what you had in mind? See the codepen below.
https://www.codeply.com/go/nss8DJRYN3
Using Bootstrap 4.
I'd like to display a Twitter 'share' button within each accordion item when it's expanded.
I can get the button to display outside of the accordion, just not inside.
I think it has something to do with the class=="collapse" on the accordion <div>, because when I remove it the button displays. I have demonstrated this in my code, class="collapse" has been removed from one accordion item and it works.
My code is below, and a link the a fiddle.
I have commented the code showing where the button works and doesn't work.
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<div class="row">
<div class="col-md-12">
<div id="accordion" role="tablist">
<!-- works here outside accordion -->
Tweet #share
<div class="card list-view-brand">
<div class="card-header" role="tab">
<p title="Click to expand">
<a data-toggle="collapse" id="#4367" href="#4367" aria-expanded="false" aria-controls="4367" class="collapsed">
item 1
</a>
</p>
</div>
<div id="4367" class="" role="tabpanel" data-parent="#accordion" style="">
<div class="card-body">
<ul class="list-group mb-3">
<li class="list-group-item d-flex justify-content-between lh-condensed">
<div>
<small class="text-muted">ID</small>
<p class="my-0">4367</p>
</div>
</li>
<li class="list-group-item d-flex justify-content-between lh-condensed">
<div>
<small class="text-muted">Language</small>
<p class="my-0">fre</p>
</div>
</li>
<li class="list-group-item d-flex justify-content-between lh-condensed">
<!-- works here when class="collapse" removed from parent div -->
Tweet #share
</li>
</ul>
</div>
</div>
</div>
<div class="card list-view-brand">
<div class="card-header" role="tab">
<p title="Click to expand">
<a data-toggle="collapse" id="#4368" href="#4368" aria-expanded="false" aria-controls="4368" class="collapsed">
item 2
</a>
</p>
</div>
<div id="4368" class="collapse" role="tabpanel" data-parent="#accordion" style="">
<div class="card-body">
<ul class="list-group mb-3">
<li class="list-group-item d-flex justify-content-between lh-condensed">
<div>
<small class="text-muted">ID</small>
<p class="my-0">4368</p>
</div>
</li>
<li class="list-group-item d-flex justify-content-between lh-condensed">
<div>
<small class="text-muted">Language</small>
<p class="my-0">ita</p>
</div>
</li>
<li class="list-group-item d-flex justify-content-between lh-condensed">
<!-- doesnt work here -->
Tweet #share
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
Any advice is appreciated.
What you can do is change the class of the share link.
From class="twitter-hashtag-button" to class="fa fa-twitter"
So the code would look something like this :
<!-- doesnt work here -->
Tweet #share
After doing this just style the .fa class like
.fa {
padding: 20px;
font-size: 30px;
width: 50px;
text-align: center;
text-decoration: none;
}
.fa-twitter {
background: #55ACEE;
color: white;
}
The updated fiddle
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/