Bootstrap accordion icons not working on collapsed states - twitter-bootstrap-3

I am working on a accordion in Bootstrap V 3.37. I have icons on the accordion which change with open and closed states. When I the state set to collapse init works fine. But when I have the accordion with none of them accordions collapsed in the icons are not working properly.
The icons should be working as:
Arrow facing down on closed state
Arrow facing up on open state
My code is as follows so far:
HTML Structure
<!-- Panel list accordion -->
<div class="panel-group">
<div class="panel-heading-one panel-main-heading-one">
<h4 class="panel-title panel-main-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
<img src="../images/image.svg" class="panel-icon">
<p>Title here</p>
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body panel-bodymain-one">
<p>Text body here</p>
</div>
</div>
<div class="panel-heading-one panel-main-heading-one">
<h4 class="panel-title panel-main-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
<img src="../images/image.svg" class="panel-icon">
<p>Title here</p>
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body panel-bodymain-one">
<p>Title body here</p>
</div>
</div>
<div class="panel-heading-one panel-main-heading-one">
<h4 class="panel-title panel-main-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
<img src="../images/image.svg" class="panel-icon">
<p>Title here</p>
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body panel-bodymain-one">
<p>Text body here</p>
</div>
</div>
</div>
</div>
<!-- End panel list accordion -->
CSS
.panel-heading-one .accordion-toggle:after {
/* symbol for "opening" panels */
font-family: 'Glyphicons Halflings';
content: "\e113";
float: right;
color: #ffffff;
height: 24px;
width: 40px;
background-color: #000000;
}
.panel-heading-one .accordion-toggle.collapsed:after {
/* symbol for "collapsed" panels */
content: "\e114";
}
Screenshots attached also.
Closed state - still point up:
Open state is fine as it points up:
Any help would be great.

Change your css to:
.panel-heading-one .accordion-toggle:after{
font-family: 'Glyphicons Halflings';
content: "\e114";
float: right;
color: #ffffff;
height: 24px;
width: 40px;
background-color: #000000;
}
.panel-heading-one .accordion-toggle[aria-expanded="true"]:after {
/* symbol for "opening" panels */
content: "\e113";
}
.panel-heading-one .accordion-toggle[aria-expanded="false"]:after {
/* symbol for "collapsed" panels */
content: "\e114";
}
And it will work perfectly.
Extra: In your accordion you have used same href='#collapseThree'
for last and second last item. When you will click on last element, it
will open second last item. So change your href in last element.

Related

Bootstrap accordion (On click of an accordion should close other accordions)

My current accordion functionality is when we click on '+' sign it opens the accordion and leaves it open even though we click on the '+' sign of other accordion.
What i need is on click of one accordion other open accordions should close.
Below is my Codepen link.
<aside class="col-md-4">
<section class="sidebar-tools">
<h4 class="my-4">My</h4>
<nav>
<a class="tile-link" data-toggle="collapse" href="#myDoctor">
My
</a>
<div class="collapse sidebar-collapse" id="myDoctor">
Viewr
Change
</div>
<a class="tile-link" data-toggle="collapse" href="#IDcards"> Cards</a>
<div class="collapse sidebar-collapse" id="IDcards">
View
Change
</div>
<a class="tile-link" href="#">nformation</a>
<a class="tile-link" href="#"> Estimator</a>
</nav>
<h4 class="my-4">My Tools</h4>
<nav>
<a class="tile-link" href="#">Cards</a>
<a class="tile-link" href="#">Enformation</a>
<a class="tile-link" href="#"> Estimator</a>
</nav>
</section>
</aside>
Thanks
CodePen
You can achieve this by using data-parent to your link, here is the snippet with your code
var $myGroup = $('#myGroup');
$myGroup.on('show.bs.collapse','.collapse', function() {
$myGroup.find('.collapse.in').collapse('hide');
});
.sidebar-tools a {
color: white;
}
a.tile-link {
text-decoration: none;
}
.tile-link {
-js-display: flex;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #2980b9;
padding: 10px;
margin: 2px 0;
}
.tile-link:hover {
background-color: #2980b9;
}
.tile-link[data-toggle]:after {
content: '\f067';
font-family: 'fontawesome';
transition: all .25s ease-in-out;
float: right;
}
.tile-link[aria-expanded="true"]:after {
transform: rotate(45deg);
}
.sidebar-collapse {
background-color: #95a5a6;
margin-top: -2px;
}
.sidebar-collapse .sidebar-collapse-link {
color: white;
display: block;
padding: 10px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/2.0.4/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/2.0.4/js/bootstrap.min.js"></script>
<aside class="col-md-4" id="myGroup">
<section class="sidebar-tools">
<h4 class="my-4">My</h4>
<nav>
<a class="tile-link" data-toggle="collapse" href="#myDoctor" data-parent="#myGroup">
My
</a>
<div class="collapse sidebar-collapse" id="myDoctor">
Viewr
Change
</div>
<a class="tile-link" data-toggle="collapse" data-parent="#myGroup" href="#IDcards"> Cards</a>
<div class="collapse sidebar-collapse" id="IDcards">
View
Change
</div>
<a class="tile-link" href="#">nformation</a>
<a class="tile-link" href="#"> Estimator</a>
</nav>
<h4 class="my-4">My Tools</h4>
<nav>
<a class="tile-link" href="#">Cards</a>
<a class="tile-link" href="#">Enformation</a>
<a class="tile-link" href="#"> Estimator</a>
</nav>

Active state on Bootstrap Acccordion click

I am using Bootstrap accordion to show/hide content using the code below. The javascript code applies an active class to the panel heading to change the background colour to green, with white font. This works ok but I need the .question span class to also change font color when the panel heading is clicked. I have tried targeting the .question class to add the active class but it has no affect?
HTML
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse1">
<span class="question">Q:</span>First Question</a></h4></div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">
<span class="answer">A:</span> Text </div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse2">
<span class="question">Q:</span>Second Question</a></h4></div>
<div id="collapse2" class="panel-collapse collapse">
<div class="panel-body">
<span class="answer">A:</span> Text</div>
</div>
</div>
JS
$('.panel-heading').click(function() {
$('.panel-heading').removeClass('active');
$(this).addClass('active');
$('.question').removeClass('active');
$(this).addClass('active');
});
CSS
.active {
background-color: green!important;
color: white!important;
}
.question {
color: blue
}
You can achieve that with pure CSS, just use bootstrap set attribute aria-expanded:
.panel-heading a[aria-expanded='true']>span.question {
color: red;
}
.panel-heading a[aria-expanded='false']>span.question {
color: blue;
}

Bootstrap Nav with 2 rows of links on desktop

I need to create a responsive nav with 2 rows of links. I would prefer to use bootstrap since it's already being used on the site. Any help to point me in the right direction would be greatly appreciated!
What I need it to look like
Just create something like this:
<nav>
<div class="container">
<div class="row">
<div class="col-md-*">
</div>
</div>
<div class="row">
<div class="col-md-*">
</div>
</div>
</div>
</nav>
Also just take a look at bootstrap's docs. Here is the link to Bootstrap's site
You need to spend some time looking at Bootstrap Navbar section also spend some time hacking around the examples and you will soon get the hang.
If you want a BIG, deep menu have a look at Yamm (yet another mega dropdown menu) or something similar. There are lots out there just search for bootstrap menus or dropdown menus... But the basic nav is very flexible.
After searching around for several hours, I was able to find a few different sources that ended up helping me figure it out.
Here's what my code ended up looking like. It's not perfect yet, but almost there.
Thanks everyone!
#nav-div { /*This is the div that wraps the entire logo and nav content*/
width:100%;
position: fixed;
top:0;
left:0;
z-index: 10;
margin: 0;
padding:0;
}
#nav-wrapper { /*This is the div that sizes the nav down to a col-md-9*/
padding:0;
margin:0;
}
#nav-container{
padding:0px;
}
#nav-top-row {
background-color: #6D6E70;
color: #fff;
padding: 0px 10px;
}
#nav-top-row a {
color:#fff;
padding-top:5px;
padding-bottom:5px;
font-size: 12px;
}
#nav-top-row a:hover {
background-color: #CCCCCC;
}
#nav-bottom-row {
background-color: #009578;
padding:0px 10px;
}
#nav-bottom-row a {
color:#fff;
}
#nav-bottom-row .dropdown-menu li {
background-color:#00806B;
}
#nav-bottom-row .dropdown-menu li a:hover {
background-color:#009578;
}
#nav-bottom-row li.dropdown.open a.dropdown-toggle {
background-color:#00806B;
}
#logo {
margin-top:35px;
width:90%;
max-width:250px;
margin-right:auto;
margin-left:auto;
}
#logo-div {
padding:0px;
background:rgba(255,255,255,.8);
}
.push-down { /*invisible div with no content that pushes down the main body content*/
margin-top:75px;
}
<div id="nav-div"class="">
<div id="logo-div" class="col-md-3">
<a href="#">
<img src="HM-Logo_Grn.png" id="logo" class="img img-responsive">
</a>
</div>
<div id="nav-wrapper" class="col-md-9">
<!-- Fixed navbar -->
<nav id="full-nav" class="navbar navbar-default">
<div id="nav-container" class="container-fluid">
<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="#">Project name</a> -->
</div>
<div id="navbar" class="navbar-collapse collapse">
<div id="nav-top-row" class="row">
<ul class="nav navbar-nav navbar-right ">
<li>SERVICES</li>
<li>ACCESS REPORT</li>
<li>REQUEST INSPECTION</li>
</ul>
</div>
<div id="nav-bottom-row" class="row">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
COMPANY <span class="caret"></span>
<ul class="dropdown-menu">
<li>PRESS RELEASES</li>
<li>NEWSROOM</li>
<li>AWARDS</li>
<li>MEDIA ASSETS</li>
</ul>
</li>
<li>RESOURCES</li>
<li>BUYERS</li>
<li>SELLERS</li>
<li>AGENTS</li>
</ul>
</div>
</div><!--/.nav-collapse -->
</div>
</nav>
</div>
</div>
<div class="push-down"></div>

Stacked progress bars with labels and min-width

I've got my stacked progress bars looking nice, with percentage labels on each, but I'm not sure how to solve when a percentage causes the bar to be too small for the label.
Setting a min-width works for non-stacked progress bars, but breaks stacked ones.
How can I fix this without hacking up bootstrap too much?
Example fiddle: http://jsfiddle.net/nimh/kx7hvxyz/
<div class="container-fluid">
<div class="row-fluid">
<div class="panel panel-default max-width">
<div class="panel-body">
<div class="progress">
<div class="progress-bar progress-bar-success" style="width: 89.74%">
<div class="text-left">+89.74%</div>
</div>
<div class="progress-bar progress-bar-danger" style="width: 10.26%">
<div class="text-right">-10.26%</div>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-success" style="width: 10.26%">
<div class="text-left">+10.26%</div>
</div>
<div class="progress-bar progress-bar-danger" style="width: 89.74%">
<div class="text-right">-89.74%</div>
</div>
</div>
</div>
</div>
</div>
Had a night to think about it and realized i can add a max-width percentage, as well as a min-width percentage, to keep stacked progress bars at least wide enough to show a label on both.
.progress-bar {
min-width: 15%;
max-width: 85%;
}
http://jsfiddle.net/nimh/kx7hvxyz/8/
It's not perfect (may look funny with a 99% and 1%), but will work for showing a label at all times for our needs.
How about playing with the line-height and font-size?
[1]: http://www.bootply.com/Tq7YbaeOX5
/* CSS used here will be applied after bootstrap.css */
.max-width {
max-width: 25em;
}
/* .progress-bar {
min-width: 4em;
} */
.progress-bar {
padding: 4px;
line-height: 12px;
}
.text-Left {
font-size: 12px;
float: left;
}
.text-left, .text-right {
font-size: 7px;
padding-right:5px;
}
.text_Right {
float: right;
}
<div class="container-fluid">
<div class="row-fluid">
<div class="panel panel-default max-width">
<div class="panel-body">
<div class="progress">
<div class="progress-bar progress-bar-success" style="width: 89.74%">
<div class="text-Left">+89.74%</div>
</div>
<div class="progress-bar progress-bar-danger" style="width: 10.26%">
<div class="text-right">-10.26%</div>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-success" style="width: 10.26%">
<div class="text-left">+10.26%</div>
</div>
<div class="progress-bar progress-bar-danger" style="width: 89.74%">
<div class="text_Right">-89.74%</div>
</div>
</div>
</div>
</div>
</div>
</div>

How can I place a div below a navbar

I need to place a div below my top navbar which should not scroll with the page content just like the navbar.
I've tried to create it as a second navbar but it is still scrolling or causing a blank area above the two navbars.
How can I do this?
UPDATE
In this sample the green bar is on top of the navbar, but I need it to stay below the navbar: http://jsfiddle.net/julianonunes/y8YqK/
If I move the green bar code (code sample below) before the navbar, it is hidden by the navbar.
Ex:
<div class="navbar navbar-decoration navbar-fixed-top"></div>
<div class="navbar navbar-default navbar-remote navbar-fixed-top">
<div class="navbar-header"> Brand
</div>
</div>
Ok. The problem is your second div includes 'navbar-fixed-top' which is glueing it to the top of your screen. You don't want it fixed to the top - you just want it fixed in place below the main navbar. Change your html for the second nag to:
<div class="navbar navbar-default navbar-remote navbar-decoration ">
And add to your navbar-decoration class:
width: 100%
position: fixed;
You may have tried this already, but in the css for the second navbar put
position: fixed;
If you don't want to add to your stylesheet, you can put it in the div like this:
<div style="position: fixed;"> </div>
I am not sure, but you may also have to add display:block like this:
<div style="position: fixed; display: block;"> </div>
With Bootstrap, use this logic within their html/css:
<div class="navbar" style="position: fixed; display: block;">
<div class="navbar-inner">
<a class="brand" href="#">Title</a>
<ul class="nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
My last guess:
<div class="navbar" style="margin-top: 10px;">
<div class="navbar-inner">
<a class="brand" href="#">Title</a>
<ul class="nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
Hope one of those works.
I've got it fixed by adding margin-top to the second navbar with navbar-fixed-top.
<div class="navbar navbar-default navbar-remote navbar-fixed-top">
<div class="navbar-header"> Brand
</div>
</div>
<div class="navbar navbar-decoration navbar-fixed-top"></div>
CSS
.navbar-decoration {
margin-top: 50px;
min-height: 5px;
max-height: 5px;
/* ... */
}