Adjust the width of a full-page layout within a compact div container

I am working on styling two div elements with different widths: one at 15% and the other at 85%. My goal is to create a pop-up form within the second div that covers the entire page when clicked, but so far it only covers the 85% width. Is there a way to make it cover the full page? The element containing the background for the pop-up has a class of pop-bg and is nested within the #main element.

#sidebar {
  position: fixed;
  height: 100%;
  width: 15%;
  margin: 0px;
  background-color: #111;
  border-radius: 0px;
}

#main {
  width: 85%;
  float: right;
  background: black;
}

/* pop-up background */
.pop-bg {
  background-color: rgba(0, 0, 0, 0.8);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  display: none;
  justify-content: center;
  align-items: center;
}

Below is the JavaScript code:

document.getElementById('button').addEventListener("click", function() {
  document.querySelector('.pop-bg').style.display = "flex";
});

document.querySelector('.close').addEventListener("click", function() {
  document.querySelector('.pop-bg').style.display = "none";
});

Answer №1

Try using 100vw instead of 100% for the width attribute. This will make it equal to the full viewport width.

Answer №2

Perhaps the reason for this issue is that the pop-up was nested within a component that occupied 85% of the page's width. To transform it into a true popup, you can disrupt the regular DOM flow by applying certain properties:

.pop-bg {
  z-index: 1000; // ensuring it displays on top
  position: fixed; // removing it from the normal document flow
  top: 0; right: 0; bottom: 0; left: 0; // expanding it to full width as intended
  .. add any other necessary styles
}

Answer №3

All that is required to include is left: 0.

document.getElementById('button').addEventListener("click", function() {
  document.querySelector('.pop-bg').style.display = "flex";
});

document.querySelector('.close').addEventListener("click", function() {
  document.querySelector('.pop-bg').style.display = "none";
});
body {
  color: white;
  margin: 0;
}

#sidebar {
  position: fixed;
  height: 100%;
  width: 15%;
  margin: 0px;
  background-color: #111;
  border-radius: 0px;
}

#main {
  width: 85%;
  float: right;
  background: black;
}


/* pop-up background */

.pop-bg {
  /* background-color: rgba(0, 0, 0, 0.8); */
  background-color: red;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: none;
  justify-content: center;
  align-items: center;
}
<div id="sidebar">
  Sidebar
</div>

<div id="main">
  Main
  <div class="pop-bg">
    Pop-Up
    <br />
    <button class="close">
      Close
    </button>
  </div>
  <button id="button">Open</button>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

how to dynamically highlight the active page in a menu using php

I am looking to use php to highlight the active page in the menu. The page is currently in a static version where common files such as header.php, footer.php, navigation.php are included using PHP. navigation.php <div class="collapse navbar-collapse" ...

Conceal the div using a sliding left animation

After researching extensively, I have been unable to find a solution to my problem. In order to better illustrate my issue, here is the code for reference: jsfiddle I am looking to create a sliding effect for a calc div where it moves to the left, simila ...

Can I place an anchor tag around the circle element within an SVG element?

Trying to turn an svg circle into a link hasn't been successful. Here's the code that didn't work. <svg height="100" width="100"> <g> <a href="http://www.example.com" target="_blank"> <circle cx= ...

Button click triggers CSS animation

Check out the interactive demo $(document).ready(function(){ $('#btn-animate').click(function(){ animate(); }); $('#btn-remove').click(function(){ $('.to-animate').removeClass('animate'); }); func ...

Unusual behavior encountered while attempting to reset input text using AngularJS

I'm encountering an issue with what I assumed would be a straightforward scenario. Here is the form in question: <form class="form-inline" role="form"> <div class="form-group"> <input type="text" ng-model="customerInput" size="80 ...

Positioning a button beside an input field within a table row

This is how my current table layout appears. Table: https://i.sstatic.net/wcHuz.png I am attempting to position the small x button next to the input textbox. Here is the code I have written so far. <table class="table table-hover"> <thead ...

Combining keyframe properties in a more efficient way using less code

While attempting to develop a LESS mixin for CSS3 keyframes, I encountered the typical way of chaining IDs and classes: #idOne, #idTwo, .classOne, .classTwo { ... } Nothing groundbreaking there. What I'm currently working on is crafting the foll ...

When scrolling, all sections display above the stationary header

On my home page, I have a header that remains fixed at the top of all sections. However, when I scroll down, the contents and sections appear above the fixed header, making it look like a background. Is there a way to ensure that all images and content go ...

Display the sidebar on mobile devices as well

If you're interested in checking out the documentation page I'm working on, you can visit it here. <div class="doc-sidebar col-md-3 col-12 order-0 d-none d-md-flex"> <div id="doc-nav" class="doc-nav"> <nav id="doc-menu ...

Looking for help with cURLing a specific URL

I am attempting to retrieve information from the following link: This link leads to a page that simply displays plain text. Here is the PHP cURL code I am utilizing: function get_web_page( $url ) { $user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8. ...

Effortlessly arranging images in a row with React

QUERY I have a handful of PNG image files saved in the same folder as my React component and have successfully imported them. Now, I am looking for a best practice method to display all these images - let's assume there are 4 images - within their re ...

Having trouble locating an element with Xpath using Selenium Web Driver? Any suggestions for a more efficient way to find this elusive element?

Selenium Web Driver- I'm having trouble locating an element using Xpath. Any suggestions on a better way to locate the element below? <div class="gwt-Label">Declined</div> I attempted to retrieve the text in the element using the followi ...

Unable to interact with a web button using webdriverio

I am currently delving into the world of automation with webdriverio in nodejs, even though my knowledge of jquery in HTML is not extensive. Here's where I stand: I have written a script that successfully logs me into an account and navigates to the ...

Chrome's struggle with displaying multiple backgrounds on retina screens due to CSS complications

My goal is to create top and bottom shadows for a parent container when scrolling through the content. This effect works perfectly everywhere except on Chrome browser with retina screens, where it behaves strangely. The background becomes stuck at the top, ...

HTML header with zero margin

Hi there! I am currently learning the basics of HTML and CSS. I have a question regarding creating a header with no margins on the edges. Any advice would be greatly appreciated as I haven't been able to find a clear solution. Below is my code snippet ...

The design elements are not being implemented on my custom React library built with TypeScript

I recently created a React library called https://github.com/deadcoder0904/react-typical/ and added styles to the component in the examples/ directory. However, I've noticed that the styles are not being applied. Below is the content of the example/i ...

What is the best way to create a responsive two-column layout with drop caps that doesn't require scrollbars?

Currently, I am delving into the fundamentals of HTML and CSS with a goal to construct my own blog entirely from scratch by coding it manually. This hands-on approach is crucial for my learning process as it allows me to grasp the intricacies better. To en ...

CSS: Ensure container stays at the top without setting a fixed height

Is it possible to keep a container fixed at the top without setting a specific height? I have a container positioned on the body with margins all around. The container has an overflow set to auto, causing it to extend beyond the screen's height (with ...

Why isn't the MVC AjaxOption displaying the spinner in the correct location?

I am attempting to display a spinner on an overlay within a partial view while loading another partial view. However, it is displaying where the div was originally declared. Index.cshtml <div id="DivEmailContainer" style="display:block" class="row"> ...

Creating a CSS grid with images: Ensuring row height adjusts to content size (image) in Chrome and Firefox comparison for accurate rendering

I'm encountering a CSS problem. While Firefox is showing the content as I want it, Chrome seems to be collapsing the grid and not displaying the image at its expected height. My goal: The image should take up maximum space without exceeding the colum ...