The bottom CSS property does not function properly on a grid container with a position of fixed

I've created a container that covers the entire screen using the following CSS:

.container {
    display: grid;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}

The issue I'm facing is that changing the value of the "bottom" property doesn't impact the display as expected.

function toggle(){
  var container = document.querySelector(".container");
  container.classList.toggle("pull-down");
}
.container {
  display: grid;
  grid-template-rows: 1fr 100px;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.container.pull-down {
  bottom: -100px;
}

div {
  pointer-events: none;
}

button {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  height: 40px;
  width: 120px;
}
<div class="container">
  <div>first row</div>
  <div>second row</div>
</div>
<button onclick="toggle()">toggle</button>

Clicking the button should move the second row out of the screen. It works correctly on Firefox but not on Chrome version 78.0.3904.108.

Answer №1

There appears to be a bug in the code because resizing the screen seems to fix it. One solution could be to add a script that forces a page refresh:

function toggle(){
  var container = document.querySelector(".container");
  container.classList.toggle("pull-down");
  
  /* Force page redraw*/
  container.style.display="none";
  setTimeout(function(){container.style.display="grid"},1);
  /* */
}
.container {
  display: grid;
  grid-template-rows: 1fr 100px;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.container.pull-down {
  bottom: -100px;
}

div {
  pointer-events: none;
}

button {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  height: 40px;
  width: 120px;
}
<div class="container">
  <div>first row</div>
  <div>second row</div>
</div>
<button onclick="toggle()">toggle</button>

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

The col-xl-6 in bootstrap is malfunctioning as it is not displaying the remaining portion of the content

When I use the code col-xl-6, the remaining portion stays blank and the next content displays on the next line. What could be causing this issue? <div class="raw"> <div class="col-12 col-lg-6"> <p>Lorem Ipsum is s ...

@media queries for min-width and max-width dimensions

My current setup uses @media queries: HTML: <head> <meta name="viewport" content="width=device-width, user-scalable=no" /> </head> CSS: @media screen and (min-width: 769px) { /* ADD STYLES HERE */ } @media screen and (min-devic ...

What are some techniques for animating SVG images?

Looking to bring some life to an SVG using the jQuery "animate" function. The plan is to incorporate rotation or scaling effects. My initial attempt with this simple code hasn't yielded the desired results: $("#svg").animate({ transform: "sc ...

Difficulty loading CSS in PugJS

I can't seem to get my dashboard.pug file to load both dashboard.css and dashboard.js, even though they are all in the same folder. I have already set up express.static correctly for the public folder. const publicpath=path.join(__dirname,'../p ...

How can I add 0-5 images to a column without causing any distortion in the row?

I'm having trouble adding a series of images to rows in my Bootstrap 4 project. The source assets are large by default and I'm struggling with scaling them properly without affecting other columns. Here's a visual representation of what I cu ...

Is there a way to have a border specifically on the top side?

Is there a way to have the border show up only on the top when hovering over it? Here's the current code I'm using: a:hover { border-top: 3px white; border-style: solid; } Even though this code is in place, the border still appears on ...

Creating a responsive layout that sets the window height to 100% and automatically adjusts sibling divs when the content within parent divs exceeds the defined height

<section> <div class="section-wrap"> <h1>page1</h1> </div> </section> <section> <div class="section-wrap"> <h1>page2</h1> </div> </section> My attempt at impleme ...

Can a YouTube video be triggered to play when a specific CSS style is selected?

I am searching for a method to display and play different YouTube videos based on a selected CSS style from a drop-down menu. I believe JavaScript can be utilized to detect the chosen CSS. Include the following in the html header of the page. <script ...

Modify th:hover in CSS to alter the background color

I currently have a table structured as follows: <table class="cedvel"> <caption> count: <%:Html.Encode(TempData["RowsCount"])%></caption> <thead> <tr&g ...

Issues with CSS preventing proper display on mobile devices like iPad and iPhone

My designer recently converted a PSD file, but for some unknown reason, the webpage is not displaying correctly on iPhones or iPads. The only visible element is the div that contains a feedback link. I have been troubleshooting this issue for a while now ...

Eliminating the bottom border of all buttons, except for the last three buttons in the list, solely using pure JavaScript, unless alternative methods are available

I have 3 sets of buttons, with each set containing 9 buttons stacked in 3 columns inside an ordered list (ol) within list items (li). I have removed the bottom border of the buttons to avoid double borders since they are stacked on top of each other withou ...

Positioning two buttons with one on the left and the other on the right

I am currently looking to add an ADD button next to the VIEW button in this layout. An example of what I am trying to achieve can be seen at where you can click on the GRID VIEW icon. <div class="desktop_view product-view grid-list-row-view hide" sty ...

Issue with displaying Font Awesome icons in Bootstrap 4 navbar brand

Recently, I've been setting up a local Laravel website to explore the latest features and changes in Laravel 5.6. However, I've encountered an issue while trying to integrate a Font Awesome icon into the navbar-brand of Bootstrap 4. The icon does ...

What are some ways to modify the appearance of the post title table using CSS?

In this snippet of HTML code- <table style='min-width:60%;height:25px;'> <tr> <td><b><data:post.title></b></td> <td id='date-and-author' style='position: relative;bo ...

Looking to adjust the background-image size of a table cell (td) upon clicking a specific

I have a website where I would like to display logos of different games with links attached to them. I have managed to adjust the size of the image on hover, but now I am looking for a way to keep the size bigger after clicking on the link. Is there a simp ...

What is the best way to create a paginator class that can navigate one page at a time using HTML and CSS?

I recently found the infusion theme online and you can check out some examples of it here There is also a live preview available here However, I am encountering difficulties in getting the paginator class to move. It seems like when one of those elements ...

Update the button text after it has been clicked

https://i.sstatic.net/QJALK.png In my code, I have a function that generates bootstrap rows, each containing an input field, textarea, and a remove button. As I call this function multiple times, I end up with several bootstrap rows. When clicking on the ...

The motion does not adhere to the delay in transition

How come the first animation doesn't have a delay when hovering in and out? It just disappears instantly. I'm attempting to achieve a delay similar to the hue-rotate effect when hovering in and out. https://jsfiddle.net/u7m1Ldq6/15/ <div id ...

Checkbox option to change background color of table cell

$('#selectall1').click(function(event) { if (this.checked) { $('.first').each(function() { this.checked = true; }); $('.second').each(function() { this.checked = false; }); $('.third&apos ...

Tips for selectively applying CSS to a single HTML file

I'm currently working on a website utilizing AngularJS and Plangular to develop a unique Soundcloud Player. This is how I incorporate my template: <body> <div id="container"> <div id="header" ng-controller="HeaderCtrl"><div ...