Darken screen when modal pops up - html

I'm trying to darken the rest of my screen when my modal pops up. I got the code from here: https://jasonwatmore.com/post/2018/05/25/angular-6-custom-modal-window-dialog-box
What ends up happening is my entire screen goes dark and opaque even before I open the module.
I'm not sure if there is something I'm doing wrong in the CSS or if there is a mistake in the HTML
Here is my code:
....
/* MODAL STYLES
-------------------------------*/
.closed{
display:none;
}
.modal {
/* modal container fixed across whole screen */
background: #fff;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
// top: 0;
// right: 0;
// bottom: 0;
// left: 0;
/* z-index must be higher than .modal-background */
z-index: 1000;
/* enables scrolling for tall modals */
overflow: auto;
.modal-body {
padding: 20px;
background: #fff;
/* margin exposes part of the modal background */
margin: 40px;
}
.modal-header{
padding: 20px;
background: #fff;
/* margin exposes part of the modal background */
margin: 40px;
}
}
.modal-background {
/* modal background fixed across whole screen */
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
/* semi-transparent black */
background-color: #000;
opacity: 0.75;
/* z-index must be below .modal and above everything else */
z-index: 1;
}
body.modal-open {
/* body overflow is hidden to hide main scrollbar when modal window is open */
overflow: hidden;
}
....
HTML:
<modal id="custom-modal-2" >
<div class="modal" style="height:100px; width: 100px;">
<div class="modal-body">
<h1 >A Custom Modal!</h1>
<p>
Home page text: <input type="text" [(ngModel)]="bodyText" />
</p>
<button (click)="closeModal('custom-modal-2');">Close</button>
</div>
</div>
<div class="modal-background"></div>
</modal>

So your modal is set to be displayed automatically and so you are displaying the whole thing once it is added to your page. You can add the "closed" class to your modal as a default, then have the open and close button change that value.
One thing you may want to consider, if you aren't already doing it, is having the modal with a state of isOpen, and then have that be the trigger for whether or not it is displaying the modal. The reason I would suggest this is because that way the logic is based on something you can see in the Javascript itself and control that with {{isOpen}} rather than adding and removing a class.

Related

CSS lightbox content vertical scrolling

I've set up a lightbox using only CSS and my images are longer than the viewport. The background is scrolling but the images won't.
Live site: https://hwestdesign.com
I've tried changing the overflow to various different settings and on different selectors and nothing is working. I'm really new to this and I don't know if I'm just making a simple mistake. I've read threads that have similar problems but the solutions provided aren't working either.
This is the CSS code I currently have active:
.thumbnail {
max-width: 100%;
}
.lightbox {
display: none;
width: 300px;
height: 300px;
overflow: scroll;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
padding:10px;
text-align: center;
background: rgba(0,0,0,0.8);
}
.lightbox img{
max-width: none;
margin-top: 2%;
overflow-y: visible;
height: auto;
}
.lightbox:target {
outline: none;
display: block;
overflow: visible;
}
This is the HTML:
<div class="grid-item item1">
<img src="images/covers/hwest.jpg" class="thumbnail">
<img class="lightbox-content" src="images/hwestbranding.jpg">
</div>
When this loads the light box pops up and there is scrolling but it’s only the background underneath the light box that scrolls. The images are longer and I want to be able to scroll just the images vertically. Right now they are the right size but fixed. I’ve tried changing their position and the overflow but it does nothing
The combination of position:fixed and the overlay size is causing the issue. Setting an element to a fixed position removes it from the scroll context of the rest of the document. To resolve this you need to give the lightbox container a new scroll context by using the overflow property.
Note: you'll need to place the mouse cursor (pointer event) OVER the lightbox/modal specifically to cause the scroll. Otherwise, the "scroll" action will pass through to the document below
Here's an example:
And a link to codepen since its a bit difficult to see here.
body {
min-height:300vh;
background: url(https://images.unsplash.com/photo-1559291001-693fb9166cba) left top repeat;
}
.modal {
/* dark background overlay helps to position content */
position: fixed;
top:0; right:0; bottom:0; left:0;
background-color: rgba(0,0,0,0.6);
}
.modalInner {
/* put the white box in the right place */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
/* define how big it is before scrolling */
width: 80vw;
height: 80vh;
overflow-y: scroll;
/* look & feel */
background-color: #ffffff;
padding: 20px;
border: 1px solid #000;
}
<div class="modal">
<div class="modalInner">
<img src="https://images.unsplash.com/photo-1560010871-220685e68662" width="100%" />
</div>
</div>

Overlay button not clickable

I am trying to make web-based slides myself, but I stumble on making a toolbar appear above each slide: the buttons are not clickable.
I reproduced this problem on this quasi-minimum working example. If you click on the button, it will not do anything, except click on the slide. However, the z-index of the button is greater than of the slide.
How can I leave the elements where they are (in the tree) and have the button to be clickable?
#fullscreenbutton {
z-index: 1001;
}
.slides {
display: block;
width: 100%;
padding-bottom: 56.25%; /* 16:9 */
position: relative;
overflow: hidden;
}
.slide {
position: absolute;
top: 0; bottom: 0; left: 0;
width: 100%;
font-size: 1.5vw;
padding: 20px;
box-sizing: border-box;
z-index: 1000;
}
<div id="app">
<div class="slides" id="slides">
<button id="fullscreenbutton" onclick="this.style.color='red'">Make me red</button>
<div class="slide" ignore-position="current">
this slide overrides everything
</div>
</div>
</div>
One way to resolve this is by removing non-css actions from the underlying element:
.slide {
...
pointer-events: none
}
Fiddle Example
div.slide is in front of the button and captures all the events.
I think it would make sense to put all the controls in a separate, absolute .div that is positioned in front of the slides.
Ok I found it, I just needed to set up
position:absolute;
on the button #fullscreenbutton.

How can I place a div in <form> at the bottom right corner of modal dialog?

I know that this kind of questions already been asked in the site but my situation is different. I am designing a responsive chat application and I want to make the sign up form in a modal dialog that I create using html and css and JS.In the modal content I have a header containing a heading <h1> ,and bellow it a sign up form.
In the form I have two buttons and I want to place them at the bottom right corner of the modal dialog. I tried to position the parent div as relative and then position the child div as absolute with the properties : right:0; bottom:0; but that did not work. Also tried positioning the child div as fixed but then I got it out of the modal being at the bottom right of the window.
HTML:
<!-- The Modal -->
<div class="modal">
<!-- Modal content -->
<div class="modal-content">
<form>
<div class="p-div">
<labe>Email:</labe>
<input type="text" name="email" required>
<div class="c-div">
<button type="button">Reset</button>
<button type="submit">Sign up</button>
</div>
</div>
</form>
</div>
</div>
CSS:
/* The Modal (background) */
.modal {
display: block;
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content {
background-color: rgb(200, 200, 200);
margin: 8% auto;
border-radius: 1px;
width: 88.7%;
height: 89.3%;
}
.p-div{
padding: 16px;
position: relative;
}
input{
display:block;
}
.c-div{
position: absolute;
right: 0;
bottom: 0;
}
Here's a fiddle
Any suggestions?
Thanks in advance!
Here is a fork of your fiddle, I broke the c-div out of the p-div container and then absolutely positioned it.
https://jsfiddle.net/e1z07xat/3/
.c-div {
position: absolute;
right: 0;
bottom: 0;
width: 165px;
}

How can I make a modal message box with AngularJS?

I have this code:
<body>
<div>
xxx
</div>
<div id="error"
ng-show="er.msg">
<div style="color: white; background-color: purple; height: 2rem; display: flex; align-items: center;">
<div style="width: 90%; margin-right: auto; margin-left: auto;">{{ er.msg }} </div>
</div>
</div>
<div>
xxx
</div>
</body>
Is there a way that I can make a mask appear over the whole page to prevent user input while the error dialog is showing? Note this is angular so I can make a div show with ng-show="er.msg" or I can hide a div with ng-show="!er.msg".
If you look at bootstrap modal implementation, you can easily achieve that yourself.
You will mainly need 3 css classes
//To cover the whole page with transparent window, clicking this should close the modal window.
.modal-backdrop {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1040;
background-color: #000;
opacity: 0.5;
}
//Actual modal window above transparent window with higher z-index
.modal {
overflow: auto;
overflow-y: scroll;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1050;
}
// This is to attach to body tag to remove scroll bar, to prevent double scroll bar. when dialog is closed this class should be removed.
.modal-open {
overflow: hidden;
}

Create static toolbar on webpage that follows scroll in HTML

How do you make a toolbar like object in HTML that follows the user's scroll so that it is always at the top of the viewable page?
Thanks in advance!
css
.selector
{
position: fixed;
top: 0;
left: 0;
width: 100%;
}
html
<div class="selector">
... content for bar here ...
</div>
Do you specifically need it to scroll (animate) or just a static (toolbar like) object?
EDIT:
Ok so to add a static(toolbar like) object that has a width which is 100% of the page, and a height of say 25px, you would do this.
HTML
<div id="toolbar">
<p>Some content...</p>
</div>
CSS
#toolbar {
position: fixed;
width: 100%;
height: 25px;
top: 0;
left: 0;
padding: 5px 10px; /* some styling, please note overall height of the object will be 35px due to 5px padding on top/bottom. */
background: #ccc; /* some styling */
border-bottom: 1px solid #333; /* some styling */
}
Please note that this might overlap any content that you have at the top of the page, so use a top margin to push it down under the toolbar or simply set:
body {
margin-top: 35px;
}