Fragment in html content goes behind the navbar, how to prevent this? - html

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

Related

Bootstrap hidden element extends past container when expanded

I have a website that displays many real-time graphs and gauges, all hidden within drawers initially. The graphs are made with the plotly.js library. The gauges are done with JustGage. The code for the containers is as such:
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-5 statistics">
<div class="centered-text">
<div class="container-fluid">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-heading">Statistics Panel</h3>
</div>
<ul class="list-group">
<!-- Base Station Panel -->
<li class="list-group-item">
<div class="row toggle" id="dropdown-detail-1" data-toggle="detail-1">
<div class="col-lg-10 text-left">
Base Station
</div>
<div class="col-lg-2"><i class="fa fa-chevron-down pull-right"></i></div>
</div>
<div id="detail-1">
<hr></hr>
<div class="container-fluid">
<div class="fluid-row">
<div class="col-lg-6">
<div id="happygraph1"></div>
<input id="happybutton1" type="button" value="View History"
onclick="happygraph1.changeMode();"/>
</div>
<div class="col-lg-6">
<div id="happygraph2"></div>
<input id="happybutton2" type="button" value="View History"
onclick="happygraph2.changeMode();"/>
</div>
</div>
<div class="fluid-row">
<div class="col-lg-6">
<div id="happygraph3"></div>
<input id="happybutton3" type="button"
value="View History" onclick="happygraph3.changeMode();"/>
</div>
</div>
<div class="container-fluid">
<div class="fluid-row">
<div class="col-sm-6">
<div id="happygauge1 style="height: 250px; width: 300px;"></div>
</div>
</div>
<div class="col-sm-6">
<div id="happygauge2" style="height: 250px; width: 300px;"></div>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
The issue is that when the page loads, if the data begins appearing on the graphs before the hidden element is expanded, the graphs' containers extend out of the newly expanded element. However, if the element is expanded first, and then the data comes in, it acts exactly how it should. There is no issue with the gauges.
Here is a screenshot of when it's working:
graph containers stay within element
Here is a screenshot of when the element is expanded after the data has started being drawn: graph containers expand out of element
The drawers (and the layout in general) is done up by bootstrap. What is causing the containers to break? I have tried playing with the fluid row and container properties, however to no avail. Thanks in advance.
It seems the issue was not with Bootstrap at all but with some of the layout options set in Plotly. Plotly was sizing the graphs to be much larger than the container only when loaded hidden.

Bootstrap 3 fluid layout with sidebar prevents vertical scroll

I'm trying to design a page with bootstrap 3 that has the main information on the left, and then a small side-bar on the right where additional links and graphs relating to the main info will go:
http://www.bootply.com/ZLB46jDSnU
Problem is if I use container-fluid for the main body (line 55), vertical scrolling is gone even though the sidebar needs it..If I change container-fluid to container, everything works nicely BUT the main body overlaps with my sidebar. Giving me the impression the fluid layout is what I want.
Does anybody know why this interferes with scrolling? Am I taking the wrong approach to have a sidebar divs independent the page content divs?
Got it working with Skelly's help!
<div id="page-content-wrapper">
<div class="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-sm-4" id="right">
<div class="panel panel-default ">
<div class="panel-heading">
<h3 class="panel-title">Shortcuts</h3>
</div>
<!--User details -->
<div class="panel-body">
<li>Milestones --»</li>
<li>Versions --»</li>
<li>CSV Report --»</li>
</div>
</div>
</div>
<div class="col-sm-8" id="left">
<!--All apps -->
<div class="panel panel-default" ng-init="">
<!-- Default panel contents -->
<div class="panel-heading clearfix">
<b>Your Applications</b>
</div>
<div class="panel-body">
<table-here></table-here>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

How to remove space between bootstrap divs

I have three divs like this:
<div class="container-fluid">
<div class="header">
Welcome
</div>
<div class="navbar">
Menu
</div>
<div class="content">
Website content
</div>
</div>
Now, the first div class="container-fluid" is stretched on all browser window. The next class="header has padding/margin of some pixels from his parent element. Now I´d like this div to stretch all browser window out. But I also don´t want next class="menu" or class="content" to be stretched out.
How may I solve this?
Use .container for navbar and content & .row for .header like this: Demo
<div class="row">
<div class="header col-xs-12 col-sm-12 ">Welcome</div>
</div>
<div class="row">
<div class="container">
<div class="navbar">Menu</div>
<div class="content">Website content</div>
</div>
</div>
This sounds like a two-column layout with a full-width header. You tagged Twitter Bootstrap so I'll explain how to use those styles to do what you want.
<div class="row container-fluid">
<div class="header">
Welcome
</div>
<div class="span3 navbar">
Menu
</div>
<div class="span9 content">
Website content
</div>
</div>
The row class is on the element that wraps the columns. span# is the class that gives each column its size. So for a 12-unit width, you could assign span3 to the navbar and span9 to the content area.
Without Bootstrap, this is still relatively simple. You can do this in CSS.
.navbar {
display: inline-block;
width: 25%;
}
.content {
display: inline-block;
width: 75%;
}
<div class="container-fluid">
<div class="header">
Welcome
</div>
</div>
<div class="container">
<div class="navbar">
Menu
</div>
<div class="content">
Website content
</div>
</div>
Use container class outside menu and content. Hope this will help you.
jsFiddle Demo

Proper way to align right panel element inside Bootstrap header

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 -->

How to make Bootstrap Panel body with fixed height

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/
}