Help please!
I'm creating a FAQs webpage where theres approx 50 questions. Therefore, I'm using collapsible divs so that the page isn't too long. Below is the code I've used so far.
I'm wondering if its possible to have a hyperlink (e.g. /#question20) where I can jump to a particular div which is automatically expanded by clicking on the hyperlink?
Also, what would be the best way of creating expand all / collapse all buttons?
Thanks in advance!
<div class="panel-group" style="width: 70%; float: right; min-width: 300px;">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>Question 1</strong></h3>
</div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">Answer 1</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>Question 2</strong></h3>
</div>
<div id="collapse2" class="panel-collapse collapse">
<div class="panel-body">Answer 2</div>
</div>
</div>
With only html you can use <details> and <summary> tag
If you want use javascript, you should create a tag and add a load event listener to it.
in the function associated for that listener you can toggle a class called hidden or change directly the style, for example we change the style with a new class called hidden to the divs you can expand and hide:
change your html to add a new class to the hidden div:
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>Question 1</strong></h3>
</div>
<div id="collapse1" class="panel-collapse collapse hidden">
<div class="panel-body">Answer 1</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>Question 2</strong></h3>
</div>
<div id="collapse2" class="panel-collapse collapse hidden">
<div class="panel-body">Answer 2</div>
</div>
</div>
add a new css rule
.hidden {
display: none;
}
and finally the script:
<script>
document.addEventListener('DOMContentLoaded',function() {
var expandLinks = document.querySelectorAll('.panel-heading .panel-title a ');
for(var i = 0; i < expandLinks.length; i++) {
expandLinks[i].addEventListener('click', function(event) {
console.log(event.currentTarget);
var selector = event.currentTarget.getAttribute("href");
var answersDiv = document.querySelector(selector);
answersDiv.classList.toggle('hidden');
});
}
});
</script>
Related
I need to increase the height of the 1st panel which is in ng-repeat
Code
<div class="panel panel-default panel-height" ng-repeat="candidateInfo in aCandidateDetails">
<div class="panel-heading">
<div class="row">
<div class="col-xs-1">
<a style="cursor:pointer">
{{candidateInfo.name}}
</a>
</div>
</div>
<div stop-watch time="xyz" name="candidateInfo.name" time-of-interview="candidateInfo.doi" ></div>
</div>
Here i have applied css to the class .panel-height as below
.panel-height:first-child {
height: 500px;
}
Here the css is not getting applied ,
I cannot figure out where im going wrong .
Any help would be appreciated.
Add a class to 'panel-heading' only when the div satisfies $first and then add height to the class name 'firstChild'.
<div class="panel panel-default panel-height" ng-repeat="candidateInfo in aCandidateDetails">
<div class="panel-heading" ng-class="{'firstChild':$first}"> <!-- Try this line -->
<div class="row">
<div class="col-xs-1">
<a style="cursor:pointer">
{{candidateInfo.name}}
</a>
</div>
</div>
<div stop-watch time="xyz" name="candidateInfo.name" time-of-interview="candidateInfo.doi" ></div>
</div>
It should work, well try this,
.panel-height:nth-child(1) {
height: 500px;
background:#ccc;
}
Here is the code to play with:
Bootply
$('.collapse').on('shown.bs.collapse', function() {
$("span").addClass('glyphicon-chevron-up').removeClass('glyphicon-chevron-down');
});
$('.collapse').on('hidden.bs.collapse', function() {
$("span").addClass('glyphicon-chevron-down').removeClass('glyphicon-chevron-up');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="panel-group" id="accordionMessagesSetup">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordionMessagesSetup" href="#collapseMessagesSetup">
<span class="glyphicon glyphicon-chevron-up"></span>
Message Setup
</a>
</h4>
</div>
<div id="collapseMessagesSetup" class="panel-collapse collapse in">
<div class="container">
<p> my content goes here... </p>
</div>
</div>
</div>
</div>
</div>
How can I remove the borders around my panel, except for the top one? I want the top border but not the ones on left, right or bottom.
Sorry if it seems too simple; I'm just new to whole web dev stack.
Make use of the border-width properties.
Check the CSS in this code: Bootply
I am using bootstrap 3. I am trying to do fragment identifier in html. My problem is when I click on a link(From Image: link1 or link2) the content goes up and placed behind the navbar. I want to show my content below the navbar. How can I do this? Please share with me if anyone have any idea about this. Bootply Link:http://www.bootply.com/FlMIBamLwj
Before click on a link:
After click on a link:
My Codes are here:
CSS:
#media (min-width: 979px) {
body {
padding-top: 60px;
}
}
Html:
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</nav>
<div class="container">
<div class="row clearfix">
<div class="col-md-4 column">
<div class="list-group">
List1
List2
List3
</div>
</div>
<div class="col-md-8 column">
<div class="panel panel-default" id="l1">
<div class="panel-heading">
<h3 class="panel-title">
List 1 title
</h3>
</div>
<div class="panel-body">
list1 content
</div>
<div class="panel-footer">
list1 footer
</div>
</div>
<div class="panel panel-default" id="l2">
<div class="panel-heading">
<h3 class="panel-title">
List 2
</h3>
</div>
<div class="panel-body">
List 2 content
</div>
<div class="panel-footer">
List 2 footer
</div>
</div>
<div class="panel panel-default" id="l3">
<div class="panel-heading">
<h3 class="panel-title">
list3 title
</h3>
</div>
<div class="panel-body">
list3 content
</div>
<div class="panel-footer">
list3 footer
</div>
</div>
</div>
</div>
</div>
Bootply Link: http://www.bootply.com/FlMIBamLwj#
This is an inherent problem with the hash fragment identifiers. It moves the page to the anchor point ignoring margins and paddings. This is even more annoying when using a fixed header like in your case.
You could use this hack, which I have been using with ::before pseudo-element.
Your updated bootply: http://www.bootply.com/KViKzJkfX8
Remove id from your panels. Instead insert an anchor before every such panel with the ids so that they will act as your fragment identifiers. Like this:
Instead of:
<div class="panel panel-default" id="l1">
...
<div class="panel panel-default" id="l2">
...
Do this:
<a id="l1"></a>
<div class="panel panel-default">
...
<a id="l2"></a>
<div class="panel panel-default">
...
The add ::before pseudo-element to each of those anchors:
#l1::before, #l2::before, #l3::before {
content: "";
display: block;
height: 60px;
margin: -60px 0 0 0;
}
This will create a pseudo-element before the anchor with a height equal to your body padding (padding used to offset fixed header). In order to negate the space occupied by this pseudo-element, give it a negative top margin of the same height. This will make it apparently disappeared.
Now, when you click your menu items the page will go the respective anchors, but because of the height of the ::before pseudo-element before it, page will stop there.
Hope this helps.
In order to affix your left menu, you could make use of bootstrap affix.
All you have to do is to add affix class to your list-group:
<div class="col-md-4 column">
<div class="list-group affix" > <!-- Add affix class here -->
List1
List2
List3
</div>
</div>
And provide it a width equivalent to col-md-4 (which you have given to the column) i.e. approx 30%. This is because affix will convert its position to fixed and hence take it out of the flow and hence the width will be auto relative to the content.
Add this single style to your CSS:
.affix { width: 30%; }
That's it. Just two changes. Add class affix to your menu wrapper. Add style for .affix to fix a width.
.
Thats default functionality of an anchor tag. If you are navigating on the same page, the browser will take you to that tag.
If you want only the content section to move, you'll have to separate its content and height from the rest of the page. That can be done by applying a height and an overflow property to it:
#scrollableDiv {
height:100px;
overflow:auto;
}
And add the id to the div that you want scrolling
<div id="scrollableDiv" class="col-md-8 column">
<div class="panel panel-default" id="l1">
...
Working version can be seen here: http://www.bootply.com/JaIlKXHycj
I am using bootstrap's panel to display text and image, but as the text grows, the body of the panel also increases. I want to know how to create the body with fixed height, e.g. 10 rows or at most 10 rows. Here is my code:
<div class="span4">
<div class="panel panel-primary">
<div class="panel-heading">jhdsahfjhdfhs</div>
<div class="panel-body">fdoinfds sdofjohisdfj</div>
</div>
</div>
You can use max-height in an inline style attribute, as below:
<div class="panel panel-primary">
<div class="panel-heading">jhdsahfjhdfhs</div>
<div class="panel-body" style="max-height: 10;">fdoinfds sdofjohisdfj</div>
</div>
To use scrolling with content that overflows a given max-height, you can alternatively try the following:
<div class="panel panel-primary">
<div class="panel-heading">jhdsahfjhdfhs</div>
<div class="panel-body" style="max-height: 10;overflow-y: scroll;">fdoinfds sdofjohisdfj</div>
</div>
To restrict the height to a fixed value you can use something like this.
<div class="panel panel-primary">
<div class="panel-heading">jhdsahfjhdfhs</div>
<div class="panel-body" style="min-height: 10; max-height: 10;">fdoinfds sdofjohisdfj</div>
</div>
Specify the same value for both max-height and min-height (either in pixels or in points – as long as it’s consistent).
You can also put the same styles in css class in a stylesheet (or a style tag as shown below) and then include the same in your tag. See below:
Style Code:
.fixed-panel {
min-height: 10;
max-height: 10;
overflow-y: scroll;
}
Apply Style :
<div class="panel panel-primary">
<div class="panel-heading">jhdsahfjhdfhs</div>
<div class="panel-body fixed-panel">fdoinfds sdofjohisdfj</div>
</div>
HTML :
<div class="span4">
<div class="panel panel-primary">
<div class="panel-heading">jhdsahfjhdfhs</div>
<div class="panel-body panel-height">fdoinfds sdofjohisdfj</div>
</div>
</div>
CSS :
.panel-height {
height: 100px; / change according to your requirement/
}
I have two rows of nested panels inside of a primary panel. The 1st row has 3 panels of unequal heights. How do I make the 3 panels to be the same height of the highest panel (panel #3 in the jsfiddle link)?
Here's the jsfiddle - http://jsfiddle.net/niner911/MgcDU/8905/
I would like panel #1 and panel #2 the same height of panel #3, or whichever the tallest panel would be.
Thanks for the help.
Here's my markup:
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">outer</div>
<div class="row">
<div class="col-xs-4">
<div class="panel panel-info">
<div class="panel-heading">1</div>
<div class="panel-body">
<div class="list-group">
<div class="list-group-item">111</div>
</div>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="panel panel-info">
<div class="panel-heading">2</div>
<div class="panel-body">
<div class="list-group">
<div class="list-group-item">222</div>
<div class="list-group-item">222</div>
</div>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="panel panel-info">
<div class="panel-heading">3</div>
<div class="panel-body">
<div class="list-group">
<div class="list-group-item">333</div>
<div class="list-group-item">333</div>
<div class="list-group-item">333</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="panel panel-info">
<div class="panel-heading">
<span>lower</span>
</div>
<div class="panel-body">
xyz
</div>
</div>
</div>
</div>
</div>
Try using map() to process each item and get the size of the tallest panel. Than apply this height to each panel.
JS
var heightTallest = Math.max.apply(null, $(".panel-info").map(function ()
{
return $(this).outerHeight();
}).get());
$('.panel-info').css({ height: heightTallest + 'px' });
Updated jsfiddle:
http://jsfiddle.net/MgcDU/8915/
using jquery apply height to children of .row
$('.row').each(function(){
var RowHeight = $(this).innerHeight();
$(this).children().css({ height: RowHeight + 'px' });
});
and set .panel height to what size you desire, eg. 100%
If you're okay with the browser compatibility limitations, you could try this CSS flexbox-based experimental code: https://github.com/twbs/bootstrap/pull/11851