Modal causing double scroll Bar - html

Opening a modal on my site is causing a double scroll bar (both vertical) issue. The modal uses position: fixed and overflow: auto. I know it is overflow: auto causing the issue, but I need this style, as my modal contains a lot of content which in most cases could not fit in the users viewport, therefore scrolling the content is a requirement.
.enquire-nav {
font-family: inherit;
top: 0;
left: 0;
z-index: 999;
position: fixed;
width: 100%;
height: 100%;
overflow: auto;
background: rgba(36, 32, 33, .97);
}
Thanks in advance :]

In the end I found that the best solution was to toggle a class on the body when the modal is opened, this class would add overflow-y: hidden. This allows me to scroll the content of the modal if it overflows the body, but doesn't allow scrolling of the body itself at the same time. No more double scroll bars.
The jQuery:
$(".menu-trigger, .primary-nav-item, .hamburger-one").click(function () {
$(".mobilenav").fadeToggle(500);
$(".top-menu").toggleClass("top-animate");
$(".mid-menu").toggleClass("mid-animate");
$(".bottom-menu").toggleClass("bottom-animate");
$('body').toggleClass("no-scroll");
});
The CSS:
.no-scroll {
overflow-y: hidden;
}

So I've solved this issue before while building out my own jQuery modal plugin. Here's a link to the github repo, for reference: https://github.com/thecox/bw-box. I'll dig around and find some of the relevant styling that resolved the issue. Here's the main structure:
HTML
<div id="default-modal" class="bwbox__modal">
<div class="bwbox__modal__outer">
<div class="bwbox__modal__middle">
<div class="bwbox__modal__inner">
CLOSE X
<div class="bwbox__modal__inner__content">
<!-- Content Goes Here -->
</div>
</div>
</div>
</div>
</div>
CSS
.bwbox__modal {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0, 0, 0, .8);
overflow-y: scroll;
z-index: 9999;
}
.bwbox__modal__outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.bwbox__modal__middle {
position: relative;
display: table-cell;
vertical-align: middle;
}
.bwbox__modal__inner {
position: relative;
background: #fff;
font-size: 1em;
font-weight: 300;
text-align: left;
color: #555;
width: 90%;
max-width: 885px;
z-index: 9999;
padding: 2em 2% 1em;
margin: 30px auto;
.bwbox__modal__inner__content {
width: 100%;
height: 100%;
z-index: 9999;
text-align: center;
}
.bwbox__modal__inner__close {
position: absolute;
color: #555;
top: 10px;
right: 20px;
font-size: .9em;
text-decoration: none;
}
Basically, the outer, middle, and inner containers center the container vertically and horizontally in the frame in such a way that if they expand beyond the window height, you can still scroll. Maybe pull it down and check out the demo.Let me know if you have any questions.

In Angular, similar to Leon Burman's answer:
setBodyModalHidden(isHidden: boolean) {
document.getElementsByTagName('body').item(0).style.overflowY = isHidden ? 'hidden' : '';
}

Related

How to make header fixed even when keyboard is up on mobile web?

I am making a web screen for mobile. I fixed the header as position:fixed,
When the keyboard is raised, the header rises above the screen. How can I fix the header even when the keyboard is raised?
I've been facing this same problem, you can use window.visualViewport to get only the Viewport Height (minus Keyboard Height)
Here you go.
Just need to use position: fixed with a header.
.main {
position: relative;
overflow-x: hidden;
}
body {
overflow-x: hidden;
margin: 0;
padding: 0;
}
header {
position: fixed;
top: 0;
left: 0;
height: 50px;
width: 100%;
background: red;
color: #fff;
}
main {
margin-top: 50px;
height: 100vh;
width: 100%;
background: green;
color: #fff;
}
footer {
height: 50px;
width: 100%;
background: yellow;
color: #fff;
}
<div class="main">
<header>This is header</header>
<main>This is main section</main>
<footer>This is footer</footer>
</div>

Scrollbar Visible on Preloading

I am using a preloader before the website loads. also, I want to make sure that there is no scrolling happening or any scrollbar present while the contents are loaded. I'm using the below code.
<div id="preloader"></div>
#preloader
{
position: fixed;
overflow-y: hidden !important;
-webkit-scrollbar: none;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url(../images/preloader.gif) center no-repeat #fff;
}
But still there is scrollbar visible and the page is scrollable.
I would add a class to the <body> during loading and remove once completed.
body.loading {
overflow: hidden;
}
enter code he
body.loading{overflow:hidden}
#preloader
{
position: fixed;
overflow-y: hidden !important;
-webkit-scrollbar: none;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url(../images/preloader.gif) center no-repeat #fff;
}
<div id="preloader"></div>
re

1-px distance between a div and its vertical scrollbar, making visible the coloured background

If you run the following code snippet in Full page (Run > Full page), you'll see a vertical red 1-pixel border near the vertical scrollbar, in Chrome / Windows. Why?
I've found workarounds (see Note2 below), so my goal is not only to avoid it, but to understand the reason for this red border. There normally should be no distance between div #popup and its scrollbar (or am I wrong?) Why is this border there?
body, html { height: 100%; width: 100%; }
* { margin: 0; padding: 0; }
#popup { position: fixed; top: 0; left: 10%; width: 80%; height: 100%; background-color: white; z-index: 10; overflow-y: auto; outline: 0; }
#popupmain { height: 100%; width: 100%; font-size: 0.9em; padding: 5%; box-sizing: border-box; outline: 0; border: 0; }
#popupclose { top: 5px; right: 5px; position: fixed; cursor: pointer; color: white; }
#popupdarkbg { position: fixed; z-index: 5; left: 0; top: 0; width: 100%; height: 100%; overflow: hidden; background-color: red; }
<div id="popup">
<div id="popupmain">
<p id="popuplongdescription">a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a</p>
</div>
<div id="popupclose">X</div>
</div>
<div id="popupdarkbg"></div>
Note: the #popupdarkbg div is normally black, with some opacity: background-color: rgba(0,0,0,.75);, and the #popup (by default: hidden) is normally triggered/opened by a click on a link, with Javascript. I removed this part here to show only the core problem in this minimal example.
Note2: a solution to remove this border is to remove the #popupclose div or to move it out of #popup div. It works, but why?

Html page is not showing full in mobile view

I need Help, as my html page is showing only half height in Mobile page view. in browser it looks ok but in mobile view only half a page is being displayed.
div.container {
width: 100%;
border: 1px solid gray;
}
a {
color: white;
text-decoration: none;
}
.adds {
position: relative;
overflow: hidden;
}
.fluidMedia {
position: relative;
padding-bottom: 56.25%; /* proportion value to aspect ratio 16:9 (9 / 16 = 0.5625 or 56.25%) */
padding-top: 30px;
height: 0;
overflow: hidden;
}
.fluidMedia iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;
color: white;
text-decoration: none;
}
sidebar {
margin-left: 0px;
padding: 1em;
overflow: hidden;
}
<div class="container">
<header>
<h1>Income Tax Act 1961</h1>
</header>
<sidebar>
<div class="fluidMedia">
<iframe src="http://www.incometaxact1961.com/Income_Tax/Sections/section2.html" frameborder="0"> </iframe>
</div>
</sidebar>
<footer>Copyright © <a href="http://www.incometaxact1961.com/" >Incometaxact1961.com</a></footer>
I just need post to display full in mobile and web page.
Any help code will be highly appreciated, I need to load a html page in another html page.
If the enough content does not reach the device's height,it will come like this, You can fix this by two ways.
Set a min-height for the sidebar or make the footer sticky to the bottom of the container.
Setting minimum height will vary for different devices.So you need a sticky footer for this case.It is possible in CSS3 using flex layout.Try the given code.
html,body{
height: 100%;
}
.container{
display: flex;
flex-direction: column;
height: 100%;
}
header{
flex: 0 0 auto;
}
sidebar{
flex: 1 0 auto;
}
footer{
flex:0 0 auto;
}
It will act as sticky footer whenever your content on the page cannot fits the device height.
What you could do is giving your footer position: absolute; to make it stick to the bottom, like so:
div.container {
width: 100%;
border: 1px solid gray;
}
a {
color: white;
text-decoration: none;
}
.adds {
position: relative;
overflow: hidden;
}
.fluidMedia {
position: relative;
padding-bottom: 56.25%; /* proportion value to aspect ratio 16:9 (9 / 16 = 0.5625 or 56.25%) */
padding-top: 30px;
height: 0;
overflow: hidden;
}
.fluidMedia iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;
color: white;
text-decoration: none;
}
sidebar {
margin-left: 0px;
padding: 1em;
overflow: hidden;
}
footer {
position: absolute;
width: 100%;
bottom: 0;
}
<div class="container">
<header>
<h1>Income Tax Act 1961</h1>
</header>
<sidebar>
<div class="fluidMedia">
<iframe src="http://www.incometaxact1961.com/Income_Tax/Sections/section2.html" frameborder="0"> </iframe>
</div>
</sidebar>
<footer>Copyright © <a href="http://www.incometaxact1961.com/" >Incometaxact1961.com</a></footer>
You can try setting initial scale of viewport to 1 by inserting this meta to html head
<meta name="viewport" content="width=device-width, initial-scale=1.0">
In order to fix your issue yo do not need to add any extra code or CSS properties. Instead, you have to delete a few, in particular, remove these:
.fluidMedia {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
overflow: hidden;
}
.fluidMedia iframe {
position: absolute;
top: 0;
left: 0;
}
Please, note that I said REMOVE these, not that your CSS should keep them. So this section of your CSS will look like:
.fluidMedia {
/* You can remove this, since it is empty. I added it for clarity purposes */
}
//This is what is left of the iframe CSS properties
.fluidMedia iframe {
width: 100%;
height: 100%;
}
I really hope this helps!

How to place a true fixed position div inside fixed position div

I've got a modal style I'm using from http://tympanus.net/codrops/ but I've created a custom close button (.md-close) that I want to be truly fixed in the top right as the user scrolls the content of the modal window.
Code here: http://codepen.io/jeremypbeasley/pen/upzrB
Right now when you scroll, .md-close leaves the visible area, making it hard to close without scrolling up. How can I force this to stay put?
I realize this is something to do with the position property but I've tried every possible combination of the parents and children. Might this have something to do with the transform property I'm using?
Any help?
Full css i used :
or live : http://codepen.io/anon/pen/lynBm
.md-close {
position: fixed;
top: 3vw;
right: 3vw;
height: 50px;
border: 0px;
cursor: pointer;
width: 50px;
background: black;
text-indent: -9999px;
overflow: hidden;
display: block;
background: blue url(http://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/VisualEditor_-_Icon_-_Close.svg/120px-VisualEditor_-_Icon_-_Close.svg.png);
background-size: 100%;
z-index: 99999;
}
.md-trigger {
width: 300px;
height: 300px;
background: blue;
text-indent: -99999px;
margin: 100px auto;
}
.md-modal {
width: 100%;
max-width: 100000000000px;
max-height: 100%;
position: absolute;
top: 0;
left: 0;
transform: none;
backface-visibility: visible;
}
.md-content {
max-height: 100%;
overflow: auto;
padding: 10% !important;
}
.md-show.md-effect-12 ~ .md-overlay {
background-color: black;
}
I solved this problem by adding a max-height of 100vh to .md-content