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/
}
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;
}
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've been spinning my wheels on trying to get a div panel element to appear on the top right of the page, on the same line as the h1 element:
<div class="container">
<div class="page-header">
<h1>
<img src="logo.png"> Page title
</h1>
<div class="panel panel-primary">
...content...
</div>
</div>
...
</div>
I'm a bit of an amateur with CSS/HTML, but I've tried the pull-left/right classes along with every permutation of display/position, etc. The outcome is always garbled. Any suggestions?
you have to add pull-left to the h1 too.. to have both of them floated..
also add a .cleafix class to the page-header div
<div class="container">
<div class="page-header clearfix">
<h1 class="pull-left">
<img src="logo.png"> Page title
</h1>
<div class="panel panel-primary pull-right">
...content...
</div>
</div>
...
</div>
I wouldn't use the .page-header for this, it doesn't clear and it's meant for text. Use the grid system so that you can set a size for your panel as they are not a set width and requires a wrapper to have a width. It will layout very cleanly this way.
Just a note: when you use the .pull-right and .pull-left classes on anything in Bootstrap these cover all viewport sizes and the results can look pretty yucky as the viewport gets smaller.
DEMO: http://jsbin.com/sadup/1
<div class="container">
<div class="row">
<div class="col-sm-8">
<img src="http://placehold.it/200x75/444444/FFFFFF&text=logo" class="img-responsive" alt="Logo">
</div>
<!--/.col-sm-8 -->
<div class="col-sm-4">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Panel title</h3>
</div>
<div class="panel-body">
Panel content
</div>
</div>
</div>
<!--/.col-sm-4 -->
</div>
<!--/.row -->
</div>
<!--/.container -->
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
Im working on bootstrap but unsure if im using the columns correctly
I cant seem to get the margin and padding correct.
Please see image below and JS Fiddle
<div class="row">
<!-- MAIN LEFT CONTENT! -->
<div class="col-lg-9">
<div class="panel panel-default">
<div class="panel-body">
<div class="alert alert-info">
<p><span>Pending approval</span>.Your profile is bring approved. This means others can't search for you just yet.</p>
</div>
<div class="col-lg-5 col-sm-4 col-xs-5 hot-not">
<div class="row">
<div class="thumbnail">
The rule .col-xs-5 (line 793) is fixing the width:
.col-xs-5 {
width: 41.66666666666667%;
}
Set it to 50%:
.col-xs-5 {
width: 50%;
}