Bootstrap centered-processing-modal on a DIV/Form - html

Please see this: http://bootsnipp.com/snippets/featured/centered-processing-modal
It is a modal for letting the user know that something is going on in the backend, so please wait. How can I have this only on a form/div and not the whole page in Bootstrap3?
Thanks for helping

Just do it as they did it, you can use the chrome inspector for that, but i'll describe the technique for you.
1) Create a div (or any element that you want, as long as if its not a block element you change its display to block) inside a container, in this case your form or a div containing that form.
2) Set the position of that container as relative and the modal position to absolute, if you don't set the parent position to relative, the modal will be relative to the body tag.
3) Set a fixed widht and height for your modal, lets say 200px for both, then add a top and a left property for the modal of 50%, this will center your element top-left corner relative to its parent, since you want the center of the element in the middle and not the corner, you need to do an offset adjustment, by moving up and left half its size, for this you'll use margin-top: -100px; and margin-left:-100px; which is the negative of widht/2 and height/2
Here is how your html should look like:
<div class="container">
<!-- your form here -->
<div class="custom-modal">
<!-- loading gif here -->
</div>
</div>
And here is how your css should look like:
.container{
position:relative;
}
.custom-modal {
width: 200px!important; /* Use !important in case you want to override another val*/
height: 200px;
position: absolute; /*You can use fixed too*/
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
display:none; /* You want it to be hidden, and show it using jquery*/
}
Now, you should set it as hidden, and when do your ajax request, you can set its visibility back with javascript.
Jquery example
// Store your modal object in a variable
var $myModal = $('.custom-modal');
// On ajax call or any event call this
$myModal.fadeIn();
// When your ajax call is done, then hide it again on the callback
$myModal.fadeOut();

Related

Position 'anchor' in same place over image at all breakpoints

I'm trying to position the anchor 'Link' in the centre of the red section of the image at all times (all breakpoints). Here I have set the position: absolute; and adjusted it to be perfect.
However if I was add more text to the 'paragraph section' or adjust the current breakpoint, the position of this link would move. I put all my code on CodePen here:
https://codepen.io/anon/pen/PrVQgm?editors=1100
Hard positioning as below;
.hero-hub-image .btn-tertiary {
left: 175px;
top: 120px; }
If you are trying position element on fluid background image you have to use fluid units, so try use calc() function with %units to best fit your elements, e.g.
left: calc(15% + 100px);

resizing window and keeping div in same place

I have currently having issues keeping my div in the same place when the window is resized. In the example, it is .add div. The issue I am having is that it is going above the view region of the page, and I can't scroll to that portion of the page so I can't even see that when I resize.
Here is the code.
http://jsbin.com/kazizeruxi/1/
This is the part that I have tried dealing with
<div class = "add" align = "center">
<!--Everything inbetween -->
</div>
Ideally I am trying to keep the entry (in the farthest up left) to stay in the upper left no matter how it is resized.
I have tried messing around with media queries, but to no avail. It just turned out to be very inefficient with different browser sizes.
Any suggestions?
Just give them a absolute position.
.add {
position: absolute;
}
The proper way to do that is to give your element the position : fixed then it will have a fixed position from the root element or the body not the parent.
let us say you want it to be centered on the screen you can use this
.add{
position: fixed;
top: 50%;
left: 50%;
transform: translate3d(-50%,-50%,0)
}
of if you have a fixed with and height you can use margin instead of transform
.add{
position: fixed;
top: 50%;
left: 50%;
margin: -50% 0 0 -50%
}
if you give it an position: absolute and the parent has a position: relaive then it will move with the parent element on resize

Positioning when parent isn't position: relative

I have a button inside of a parent div. I would like the button to be in the upper-right of the div.
If the parent div had its CSS position set to relative, I would just make the button's position: absolute and top: 0px and right: 0px or something along those lines (right would actually be dynamically based on the size of the button).
The problem is, someone else made the div, it has no position attribute, and I can't change its style. How can I still position this button where I want it?
Example HTML:
<div id="someone_elses_div">
<button id="my_button">Hello World</button>
</div>
You could use the css calc() to calculate left margin for the button according the the div's width: FIDDLE
as you can see, almost all current browsers support calc(): CALC()
css:
#someone_elses_div{
background:red;
height:100px;
width:70%;
}
#my_button{
width:100px;
margin-left:calc(100% - 100px);
}
I'm not sure if this will help, but are you unable to change the parent's position due to not having access alone? If so, you could just use some jQuery to add the position.
$(document).ready(function () {
$('#someone_elses_div').css({
'position':'relative'
});
});

Position HTML element relative to bottom of parent element using CSS?

I have several stacked HTML <section>s with background images. Within each <section>, I have a panel with content inside.
JSFiddle: http://jsfiddle.net/victorhooi/zRFzb/1/
JSFiddle Full-screen output: http://jsfiddle.net/victorhooi/zRFzb/1/embedded/result/
Ideally, I would like the main title (#proclaim) and the panels (.contentbox) to be a set pixel distance from the bottom of each background image.
However, I can't seem to achieve this.
I did try the position: relative; with an inner position: absolute; trick, combined with a value for bottom and that didn't seem to work at all - it actually sent all the boxes to the top of the page.
Currently, I'm using a mish-mash of positioning to try to get everything to fit.
However, when you change the browser window size or the resolution, the panels and text move everywhere.
Is there a way to affix the main heading, and the panels to a set distance from the bottom of their respective background images?
works just fine
section {
position: relative;
}
.contentbox, #proclaim {
bottom: 10px; // your value
position: absolute;
}

Confused over DIV Z-index, plus logic of visible/hidden DIVs

I've spent all morning trying to write what I thought was a simple bit of code.
Two long columns of content, only column 1 is visible
On click of a link, column 1 is hidden and column 2 becomes visible
Both are in exactly the same position, however both have different and varying lengths
I decided to use the target pseudo-class to switch between the columns, setting the visibility of one to show.
This seems to work, but I don't fully understand what I've done. Plus, content below these columns seems to be placed beneath them on the z-axis rather than below them on the y-axis.
My two (related) issues:
I'm not sure exactly what the logic is of what I've created, I could do with a plain english explanation.
I don't understand why the DIV underneath the two columns and container is not appearing below them on the y-axis.
Here's my CSS:
#container
{
background-color: red;
position: relative;
}
#schools-list
{
width: 400px; /* Set the width of the visible portion of content here */
height: 600px; /* Delete the height, let the content define the height */
background-color: purple;
position: absolute;
top: 0;
left: 0;
}
#boards-list
{
width: 400px; /* Set the width of the visible portion of content here */
height: 700px; /* Delete the height, let the content define the height */
background-color: green;
position: absolute;
top: 0;
left: 0;
visibility: hidden;
}
#container:target #schools-list
{
visibility: hidden;
}
#container:target #boards-list
{
visibility: visible;
}
Here's my HTML:
<div id="container">
<div id="boards-list">
Boards List<br>
Switch to Schools List
Here's some content
</div>
<div id="schools-list">
Schools List<br>
Switch to Boards List
Here's some other content
</div>
</div>
<div>Why is this beneath everything?</div>
Absolute positioning removes an item from the flow of the page. This is what is causing your bottom div to appear underneath.
Visibility removes the element from sight but the element will still take up space.
My suggestion is to use display rather than visibility.
Toggle your elements between display:block and display:none and remove the absolute positioning and you should be able to achieve the functionality you desire.
Both #borad-list and #school-list is taken out of normal page flow by position: absolute, that's why your container height should be 0px as there is nothing that takes any space vertically.
I could explain it better but now writing with my phone so... i'll try just to give you starting point.
By positioning the containers using position:absolute, you're removing them from the normal flow of the page. In other words, your other content acts like those containers aren't even there, and those containers magically appear in front of the content.
Instead, what you'll likely want to do is remove the position, top, and left of the containers, and use display:block to show and display:none to hide the containers. You can also remove the height from the containers and allow the content to decide on its own how much room is needed.