Issue with Chrome causing linear-gradient background to break when zoomed out

My current design involves utilizing a gradient background to create an alternating pattern for rows that are absolutely positioned.

However, I have run into an issue when zooming out in Chrome. The sizing calculations for the gradient background are not aligning properly with the calculations for the top margins, resulting in a distorted layout.

To demonstrate this problem, I have set up a JSFiddle: http://jsfiddle.net/4y3k2/4/. Zooming out to 75% reveals an offset between the foreground and background elements, which progressively worsens as you scroll down the page.

Below is the code snippet I am using:

#container {
    position: absolute;
    height: 2000px;
    width: 100px;
    background: linear-gradient(red 50%, green 50%, green);
    background-size: 40px 40px;
}
.row {
    position: absolute;
}    

<div id="container">
    <div class="row" style="top: 920px;"></div>
</div>

This issue only occurs in Chrome, as it works perfectly fine in IE and Firefox.

Answer №1

A more efficient way to achieve this is by setting the parent div as a block element with predefined height and width for each row, floating them to the left:

#container {
    position: absolute;
    height: 2000px;
    width: 100px;
    background: linear-gradient(red 50%, green 50%, green);
    background-size: 40px 40px;
    display: block;
}

.row {
    float: left;
    width: 100px;
    height: 20px;
}

Check out this example on jsFiddle.

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

Animate a div once the parent section becomes visible while scrolling

I previously had this function working, but it seems that I have somehow messed it up in the process. My current setup includes a scroll hijack feature that navigates users to a new section or card each time they scroll. The script adds a visible class w ...

React app (storybook) experiencing loading issues with @font-face

I am struggling to load custom fonts from a local directory. Can someone provide assistance? Below is the code I am currently using: @font-face { font-family: 'My Custom Font'; src: url('./fonts/MyCustomFont.eot'); src: url(&apo ...

Retrieve an HTML element that is a select option with jQuery

I have a select input containing different options as shown below: <select id="myArea"> <option class="myClass_1" style="color:red;" value="1">Area 1</option> <option class="myClass_2" style="color:green;" value="2">Area 2& ...

methods for retrieving an array of input values from HTML into JavaScript

I posted a question on salesforce.stackexchange.com and you can find the link below: Link to question After receiving feedback that my question is more related to JavaScript than Salesforce, I am reposting it here. Please review from an HTML and JS stand ...

Can you explain the purpose and significance of addEventListener()?

class MyController{ public myEntities = ko.observableArray(); constructor(modelData) { var me = this; me.onViewLoaded.addEventListener(() => { me.myEntities.push(modelData); }); } The ...

The function did not execute properly, resulting in the express route returning no value

Encountering some issues with Express routes that are behaving inconsistently despite having identical code execution. The goal is to have a client application make API calls like this: async search(){ const query = this.$refs.searchInput.value; ...

Is there a glitch or a misinterpretation of the specifications concerning the use of relative padding

VIEW DEMO At times, I like to create a square (or any rectangle) that maintains its ratio regardless of size, using a technique similar to this method. My Objective: To prevent the square from extending beyond the viewport on devices with limited heigh ...

AngularJS: Optimizing load times by consolidating all partial views/templates for production

My goal is to maintain views in a highly modular way. This entails using numerous small, generalized HTML snippets that come together to form the actual HTML page. While ng-include and custom directives with templateUrl work well for me during development, ...

Pass the chosen option to PHP using Ajax within the same webpage, utilizing HTML

My Goal: I am working on a HTML/PHP page that displays the home page of my website. One section on this page is dedicated to highscores, with data retrieved from a database. Users can use a Select box to choose how the highscores are sorted. View the high ...

Ensuring that your content spans the entire viewport is crucial for optimizing

https://gyazo.com/1440b13007c6e011ec46218ceecabb6a Upon examining the screenshot, it is evident that there is a white border surrounding the main content of the page. Despite my attempts to adjust everything to 100% width, I have not been success ...

The buttons in the Bootstrap modal are unresponsive

I'm attempting to create a modal navigation bar for mobile view but encountering an issue. When I click on the icon bar or menu bar in mobile view, none of the buttons inside the modal are responding. I'm quite stuck on this and would appreciate ...

What is the method to prevent the Submit Button from being active in CSS specifically on Firefox?

When I click this CSS in webpages on Chrome (OS: Windows), it works fine. However, Firefox (OS: CentOS7) does not seem to apply this CSS on webpages. How can I resolve this issue? Should I make adjustments in the CSS code below? #submit .btn.btn-primary ...

Modify the parent variables within an HTML document

Attempting to update the var a within the hardcoded HTML page and then triggering an alert externally, but the value remains unchanged. This code is located in my content.js file. var a; function popUpWindow() { a="Nothing"; alert(a);// Shows "Not ...

Adjust the pagination page size based on the value in the Angular scope dynamically

My goal is to provide the user with the ability to adjust the number of rows displayed in a table. This feature is crucial for our web app, as it needs to be accessible on various devices and should allow users to customize their viewing experience to redu ...

Hover shows no response

I'm having trouble with my hover effect. I want an element to only be visible when hovered over, but it's not working as expected. I've considered replacing the i tag with an a, and have also tried using both display: none and display: bloc ...

The border-radius style will not be effective on the top part of the div

I'm currently developing a landing page for my personal use, but I've encountered an issue. There is a div with a border-radius named .popOut. The border-radius is applied to the bottom of the div but not the header part. Why is this happening? H ...

To style a checkbox with an image (such as a checkmark or X) using CSS and HTML while hovering over it

Hey there, I'm interested in playing around with HTML and CSS while learning. I have a question: is it possible to add an image to a checkbox when it's hovered over? Just to be clear, I only want the image to appear when the checkbox is being hov ...

What is the best way to update the page based on the user input from a prompt?

In my previous question, I was instructed to convert my variables into strings, which I did. However, despite making these changes, the code is still not functioning as intended. The purpose of this code is to prompt the user to select a mood from 1-10, wi ...

What could be the reason for the absence of search results in my searchbox?

Can anyone assist me in identifying the issue with my search box? I have created a JavaScript search box that validates input against a predefined keyword list. If a word matches, the "HARMI-SOIL 8.0/15 Result Box" should be displayed, otherwise it should ...

Issue with flexbox max-width property not being applied when resizing the page width

I'm struggling to make a flex box with max and min width properties work properly. When I reduce the page size, it ends up showing blank space instead of resizing. How can I troubleshoot this issue? .parent{ border: 1px solid red; width: 50%; ...