Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3: Create an overlay on panel-body

I want to display some information on the panel for which I need a overlay which should be displayed on user raised event.

I've created a demo on BootPly:

HTML of a single panel:(Rest is written in the link.. NOt relavent to my question)

<div class="panel panel-primary" style="box-shadow: 5px 5px 2px #888888;">
                            <div class="panel-heading">
                                <h3 class="panel-title">
                                    Vehicle Status Comparison <span class="pull-right"><i class="glyphicon glyphicon-fullscreen"
                                        data-toggle="tooltip" data-placement="left" title="Show Full Screen"></i>&nbsp;
                                        <i class="glyphicon glyphicon-pushpin" data-toggle="tooltip" data-placement="left"
                                            title="Show options"></i>&nbsp; <i class="glyphicon glyphicon-info-sign" data-container="body"
                                                data-toggle="popover" data-placement="bottom" title="Information" data-content="This is a very useful information. But I do not know what to write here.">
                                            </i>&nbsp; <i class=" glyphicon glyphicon-retweet" data-toggle="tooltip" data-placement="left"
                                                title="Toggle Chart"></i>&nbsp; </span>
                                </h3>
                            </div>
                            <div class="panel-body">
                                <div id="c_VehicleStatusFull">
                                </div>
                                <div class="overlay" style="display: none">
                                </div>
                            </div>
</div>

CSS:

.overlay
 {
     position: absolute;
     top: 0;
     left: 0;
     right: 0;
     bottom: 0;
     background-color: rgba(0, 0, 0, 0.85);
     z-index: 9999;
     color: white;
     display: inline-block;
 }

JS:

The use of JS is to show and hide the ".overlay" div

$('.glyphicon-pushpin').click(function () {
     $('.overlay').toggle();
});

Note:

Please note that in the link I've given, I've hardcoded the .panel-body height to 100px but in actual it is adjusted at runtime.

Problem:

On cliking the "Show options" icon.. The overlay is spread all over the div but I want it to stay within 'div .panel-body'

Improper Overlay

like image 628
writeToBhuwan Avatar asked Feb 24 '14 12:02

writeToBhuwan


People also ask

How do I make an overlay?

One of the ways of creating an overlay is by absolutely positioning an HTML element on the page. We create <div> element in the markup then position it absolutely with the position property. After it, we give the <div> high z-index value to make it on top of all other elements on the page with the z-index property.

How do I overlay images in bootstrap?

Image Overlay: Image overlay generally refers to the image being a background image and inserting texts, and links inside of that image. It can be done using the 'card-img-overlay' property that is present in bootstrap. Also, we can do it with normal CSS along with a bootstrap theme.

How do I overlay an image in a div?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).

What is overlay bootstrap?

Overlay componentsBootstrap includes several components that function as an overlay of some kind. This includes, in order of highest z-index , dropdowns, fixed and sticky navbars, modals, tooltips, and popovers.


1 Answers

Please try this css

.panel-body { height:100px; position:relative; }
like image 126
Nimmi Avatar answered Sep 28 '22 10:09

Nimmi