Not able to use modal in parent element with position as fixed - javascript

Hi am try to use bootstrap modal inside of fixed positioned parent element.
But seems like its not working as expected.
Here is an example,
<div class="fixed">
<div>
<div>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-target="#myModal" data-toggle="modal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
https://codepen.io/anon/pen/yMPOpo
Note: I would like to keep my HTML structure as it is.

You just have to lower the z-index of backdrop of modal,
Try this simple CSS and you are good to go
.modal-backdrop{
z-index:-1;
}

What is the issue? it's not clickable?
Trying setting the modal to position:relative and give it a z-index.
See here:
https://codepen.io/anon/pen/wJPWdr
.modal-backdrop.in {
position:relative;
z-index:100;
}

Short answer: Remove fixed class
Codepen: https://codepen.io/anon/pen/dvZXVG
Here, a question with the same issue: z-index not working with fixed positioning
or MDN documentation: The stacking context

Related

How to make just a part of html 'tabbable'? (Modal Dialog)

I have an Angular App and a custom Modal Dialog implementation. How can I limit the 'tabbablity' of the page so that i can just tab through the Modal, and not everything else in background?
I have set aria-hidden="true" for all other elements directly under the body tag, and thought that has to handle that, but no success. tabindex="-1" also did not work..
Actually I want the exact tab-behaviour of this bootstrap modal:
https://getbootstrap.com/docs/4.0/components/modal/
Click: "launch demo modal" and tab through the modal elements..
How can I achieve this?
Edit: I look at the bootstrap modal, and they do not set anything to other elements, but just to the modal container div (with class="modal fade show") tabindex="-1". And after the last element in modal, tab sets focus to this modal container div. After that the focus is set again to the first modal element. In my case tabindex="-1" strangely does not bring anything, after the last element focus jumps to the Browser's URL Input field and goes on.
I dont know what code you have...but this tabindex behavior works well with bootstarp example.
.modal-backdrop {
background-color: transparent !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/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://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal (with tab only on modal elements)
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
coucou
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<br><br><br>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal2">
Launch demo modal (with tab on all document elements)
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal2" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
coucou
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>

use same class for data target modal in same page

im have a profile list page. inside the page it have modal with data-target .popupmessage. the problem is i will using the same class as much as the profile i have. how to make specific when client press the modal? because when i click the button modal to show the modal, all the modal got show up
<div class="col-xs-3">
<div class="profile thumbnail">
<img src="http://placehold.it/450x150">
<button class="btn btn-yellow peopleMessage" data-toggle="modal" data-target=".popUpMessage">
Message
</button>
<div class="modal fade popUpMessage" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span class="fa fa-times" aria-hidden="true"></span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-3">
<div class="profile thumbnail">
<img src="http://placehold.it/450x150">
<button class="btn btn-yellow peopleMessage" data-toggle="modal" data-target=".popUpMessage">
Message
</button>
<div class="modal fade popUpMessage" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span class="fa fa-times" aria-hidden="true"></span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
heres the example
http://www.bootply.com/95vPZK1rN8
i want to add a number at the end of .popUpMessage
so like a looping every .popUpMessage will be like this .popUpMessage1, .popUpMessage2, .popUpMessage3, .popUpMessage. but i kindly stuck.
heres the script
var start=1;
var max=9999;
for(start;start<=max;start++){
//i stuck on the condition
}
As far as I know, Bootstrap doesn't support multiple modals in this way. Every data-target property has to point out to a specific and unique modal. Else (and that's what your problem right now is), Bootstrap will simply show up all of them.
A simple approach could look like this, by just renaming your individual data-target and container class to popUpMessage(x, y, z).
That being said, you've also mentioned you're affraid of having too many classes. In this case, you may use some JavaScript magic and define your classes dynamically after loading up your page.
EDIT:
Since you are using Bootstrap, you can also make use of jQuery and it's .each() function. By doing so, you can iterate through every element (specified through your selector) and change it's attributes like data-target and class.
Take a look into this.

Bootstrap Modal not popping up

I'm really new to bootstrap and I am trying to add a popup using Modals. I added the code and the scripts, but when you click on the button its not popping up. I can tell something is coming up because the background fades a little but a popup is not coming up. So I need a little bit of help figuring out why its not popping up.
My JavaScript links:
<script src="js/jquery-1.10.2.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
Code for Modals:
<div class="modal hide fade" id="myModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
Close
Save changes
</div>
</div>
<a class="btn" data-toggle="modal" href="#myModal" >Launch Modal</a>
This is a compatibility issue v2.X vs v3.X
Bootstrap 3.0 New Classes & Elements
Modal markup has changed .modal-header .modal-body .modal-footer now get wrapped in .modal-content and .modal-dialog
Modal Migration
How to convert from a 2.x to 3.0 modal:
remove .hide from the .modal (it's now hidden by default)
wrap .modal-header .modal-body .modal-footer inside .modal-content
wrap .modal-content inside .modal-dialog
Events are namespaced. For example to handle the modal 'show' event, use 'show.bs.modal'.
Reference
Bootstrap 3 modal example:
<a data-toggle="modal" href="#myModal" class="btn btn-primary">Launch modal</a>
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
Content for the dialog / modal goes here.
</div>
<div class="modal-footer">
Close
Save changes
</div>
</div>
</div>
</div>
JSFiddle
What I usually do for modals with just JavaScript and Bootstrap is to have an onClick event on the button that executes a JavaScript method that displays the modal.
In your HTML:
<button onclick="myFunction()">Click me</button>
<script>
function myFunction(){
$('#myModal').modal('show')
}
</script>
Just change the function name myFunction to the name you want and myModal to the id of your modal.
Here is the bootstrap docs, where the modal stuff is located, for future reference getbootstrap.com/javascript/
Complete Example using CDN. SO that you can download the latest version from Url
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css">
<script type="text/JavaScript" src="http://code.jquery.com/jquery-1.11.2.js"></script>
<script type="text/JavaScript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.js"></script>
<body>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</body>
</html>

Bootstrap 3 modal not working correctly when placed inside a fixed parent

I'm attempting to launch a form from the header of a website I'm designing, using a Bootstrap 3 modal window. Here's the link; the modal should launch from 'email signup':
http://pamaphilly.wpengine.com/
The issue is that the 'fixed logo ribbon' should be a persistent and fixed element at the top of the page. When I use fixed positioning, though, the modal doesn't work correctly. However, if I removed fixed positioning, it functions as expected. See this video: http://screencast.com/t/LeFCDXuf0GrE
The CSS class I'm changing is:
.fixed-logo-ribbon {
background-color: #e41535;
height: 4.75em;
width: 100%;
min-height: 5em;
top: 0;
border: 0;
}
Also, the html is just the standard modal demo:
<div class="fixed-logo-ribbon">
<div class="container logo-container">
<a href="http://pamaphilly.wpengine.com/">
<img class=logo-PAMA type="image/svg+xml" src="<?php bloginfo('template_url'); ?>/img/PAMA-logo-2014-masthead.svg" height="40" width="360" alt="PAMA-logo">
</a><!-- end logo div -->
<div class="social-media-icons pull-right">
<div class="join-us less-margin">
<a data-toggle="tooltip" data-placement="bottom" title="Join the AMA Now" class="join-link" target="_blank" href="http://www.jointheama.com/">join now</a>
</div>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg join-us" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Does anyone have any idea how I can get the modal to work while still having a fixed header, as intended?
Thanks in advance for any help...
Dave
Per the official docs:
Modal markup placement
Always try to place a modal's HTML code in a top-level position in your document to avoid other components affecting the modal's appearance and/or functionality.
Your mistake is also known as Bootlint problem ID E022.
The fix is move the <div class="modal ...">...</div> so that it's a direct child of the <body>, rather than being a descendant of the navbar.

Extra scrollbar on modal of Bootstrap 3

I have looked through various questions on this site and other sites and tried their respective fixes but I haven't got any of them working for me. Whenever I open up my modal, an extra scrollbar is added. The extra scrollbar is of the modal, I know that, what I want to do is to hide the background-page's scrollbar so that it could prevent the background from scrolling. Right now, when the scroll of the modal is finished the background starts to scroll.
This is my modal's code:
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalTitle">Modal title</h4>
</div>
<div class="modal-body">
<p id="myModalContent"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-thumbs-up"></span>
</button>
<button type="button" class="btn btn-default center"> <span class="glyphicon glyphicon-thumbs-down"></span>
</button>
</div>
</div>
</div>
</div>
Demo.
How could I prevent the background from scrolling?
Just add
body.modal-open {
overflow: hidden!important;
}
to your CSS.
Updated Fiddle

Categories