Is Chrome not correctly using 100% viewport width (vw)?

I've been attempting to recreate the functionality of this codepen, and I've encountered an issue with the vw declaration in Chrome. Despite setting GalleryGrid to 100vw, it doesn't display correctly in Chrome, while Firefox and Safari work fine. Any insights on why this behavior is occurring?

Chrome https://i.sstatic.net/5kLQZ.png

Safari/Firefox https://i.sstatic.net/7dhSM.png

HTML

<div class="front margin">
  <GalleryGrid>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
  </GalleryGrid>
</div>

CSS

    GalleryGrid{
      --content-width: 100vw;
      --gutter: 1.5em;
      --columns: 1;
      --width-size: calc(
        ( var(--content-width) - (var(--gutter) * (var(-- 
      columns) - 1))
        ) / var(--columns)
      );
      --row-size: calc(
        ((var(--width-size) * 3)/ 2));
      display: grid;
      width: 100%;
      max-width: var(--content-width);
      grid-template-columns: repeat(var(--columns), 1fr);
      grid-auto-rows: var(--row-size);
      grid-column-gap: var(--gutter);
      grid-row-gap: var(--gutter);
    }

    .item {
      position: relative;
      box-shadow: 0 4px 8px 0 rgba(0,0,0,0.12),
                  0 2px 4px 0 rgba(0,0,0,0.08);
     }
   .front {
     font-family: Noto Sans, Arial, sans-serif;
     padding: 3em 0;
     margin: 0;
     display: flex;
     flex-direction: column;
     align-items: center;
     justify-content: center;
   }
    .margin{
        margin-left: 4%!important;
        margin-right: 4%!important;
    }

Answer №1

When you place GalleryGrid within a div labeled with the class margin, make sure to take note that this container includes left and right margins. These margins are affecting the overall layout as you have designated the width of GalleryGrid as 100% instead of 100vw.

Answer №2

While this post may be from over 4 years ago, I recently encountered an issue with my website displaying differently on Chrome compared to other browsers. It turns out that the culprit was setting the body width to 100vw. Upon further investigation, I realized that Chrome interprets 100vw as the width of the window including the space taken up by the vertical scroll bar. This caused a noticeable rocking motion on my web pages when viewed in Chrome. However, when the page fit vertically within the screen and no scroll bar was present, the issue disappeared. It seems that using 100% instead of 100vw accounted for the width of the scroll bar, making it a more reliable practice for consistent width display on Chrome.

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

Effective Methods for Implementing CSS Variables within nth-child Selectors

Objective: To pass a variable successfully as a parameter to nth-child. The task is to make the third line turn green in the example provided. Dilemma: Currently, the parameter is being disregarded as a variable. Inquiry: Is achieving this possible? If s ...

Modify the color of the lower border and dropdown indicator in Material UI's Autocomplete feature

https://i.stack.imgur.com/oXKQm.png I'm struggling to figure out how to change the color of the line underneath 'Search' and the arrow on the right to white. I've tried applying styles to the .MuiAutocomplete-root css class, but it did ...

Streaming video to multiple clients concurrently using NodeJS

We are currently facing an issue with serving a video stream. Due to the fact that HTML5 video tag does not support udp to multicast, we have been attempting to repurpose an existing ffmpeg stream and broadcast it to multiple responses. Unfortunately, thi ...

Dynamic jQuery backstretch feature: automatic image cycling and reversing

I am currently using backstretch on my website and attempting to create a continuous loop of the moving image by automatically shifting it from left to right and back. However, I am facing difficulties as the background only moves in one direction. I am se ...

CSS3 Marquee Effect - puzzled

After trying numerous solutions for the marquee effect, I find myself at a dead end. Even webkit examples have failed me, as the demos don't seem to work either. My browser of choice is Chrome, but my website needs to function properly in both Chrome ...

Flot Graphs: A unique dual-axis line chart with the ability to stack data on one axis

Is it possible to utilize the FLOT Javascript library for creating a chart with dual axis and three data sets? I am specifically looking to have one data set on the left axis and two on the right axis. Ideally, I want to stack the two datasets on the right ...

Switching the class from "untoggled" items to the selected item in React

Recently, I developed a toggle component known as Accordion. Within this component, I am iterating through an array of objects and displaying them in the following format: {object.map((o) => ( <Accordion key={o.id} title={o.question} className="i ...

Customize jQuery Datepicker to default to 01-01-1970 if input box is left empty

Hey everyone, I'm having a problem with the Datepicker in my input box labeled "Order Date." Here is what my input field looks like: Whenever I submit my form with an empty date field, it automatically sets to 01-01-1970. It looks like this: So, wh ...

I desire a three-column layout where the middle column will expand in width if columns 1 and 3 are vacant

I have a three-column layout designed without using tables. <div id="main"> <div id="left"></div> <div id="content"></div> <div id="right"></div> </div> This is the CSS code: #left {width: 200px;fl ...

I am looking to create a side menu that will allow for dynamic class changes upon clicking

I'm looking to create a dynamic side menu that changes class on click event. My goal is to have jQuery add a class to a clicked "li" element that doesn't already have the class "active", while removing the class from other "li" elements. I want ...

having numerous collapsible elements that trigger a single django view function, each one submitting a distinct value

I have multiple collapsible items that need to trigger the same Django function when submitted with different values. https://i.sstatic.net/1BO19.png Is there a way to achieve this without using a dropdown menu in Django forms? What modifications should ...

Ways to verify if one div in jQuery contains identical text to another div

I need help with a jQuery script to remove duplicate text in div elements Here's the requirement: If div1 contains the text "hi" and div2 also contains "hi", then div2 should be removed Below is my current code snippet: <script src="https:/ ...

Looking to connect information

I have written the following code and I am trying to bind data to ng-model. When I use ng-model = "value", I can see the value in the text field, but I want to update the value when the text input is changed. <tbody ng-repeat="action in model.editAct ...

What are the steps to display the entire image instead of a cropped version?

Currently in the process of constructing a website using HTML/CSS/Bootstrap/Js. I have encountered an issue while attempting to overlay a jumbotron on a container with a background image utilizing z-index. Unfortunately, the background image I am using k ...

What is the reason for preserving the height to width ratio in the <img> tag?

When I write a simple code like this: <img src="mycat.jpg" height="300px";> I noticed that if the image is very large, the height will be reduced to 300px, and the width will automatically adjust to fit the new height. I expected ...

The ajax call I made is not retrieving any data, only returning an empty array

I am having trouble passing data from JavaScript to PHP through AJAX. Even though I have passed some data, the output is showing as an empty array. Can someone please assist with this issue? <html> <head> <title></title> ...

Is there a way to get rid of the tiny black line beside the Instagram icon?

Here is the display on my website This is the code that was used I am struggling to identify the source of the small black "-" line next to the Instagram icon logo. ...

What is the recommended way to handle passing props to child components in React - should all props be passed down, or only specific props

When it comes to passing props to child components, which approach is more efficient: Method 1. Utilize {...props} to pass all props, for example: ParentComponent = (props) => { return <ChildComponent {...props}> } Method 2. Explicitly pa ...

What is the reason behind getElementsByClassName not functioning while getElementById is working perfectly?

The initial code snippet is not functioning correctly DN.onkeyup = DN.onkeypress = function(){ var div = document.getElementById("DN").value document.document.getElementsByClassName("options-parameters-input").style.fontSize = div; } #one{ heigh ...

"Creating a cohesive design: Using CSS to ensure the navigation background complements

I am working on a project with a horizontal navbar that I want to stay fixed while scrolling. The main window has different colored divs as you scroll down, and I would like the navbar to match the image of the main div while scrolling, creating a looping ...