How to resolve the issue of a visible line between a clipped div and its parent div

When I zoom in, a faint, transparent line appears between the triangular div and its parent div. It seems like this issue is caused by anti-aliasing in the browser. Any suggestions on how I can fix this would be greatly appreciated. I've already attempted using SVG instead of clip-path, but the problem persists.

<script src="https://cdn.tailwindcss.com"></script>

<div class="bg-red-500 h-[30rem] relative">
  <div class="w-1/2 h-10 md:h-20 bg-inherit absolute transform -translate-y-full [clip-path:polygon(0%0%,100%100%,0%100%)]"></div>
  <div class="w-1/2 h-10 md:h-20 bg-inherit absolute transform -translate-y-full right-0 [clip-path:polygon(100%0%,100%100%,0%100%)]"></div>
  <div class="w-1/2 h-10 md:h-20 bg-white absolute bottom-0 [clip-path:polygon(0%0%,100%100%,0%100%)]"></div>
  <div class="w-1/2 h-10 md:h-20 bg-white absolute bottom-0 right-0 [clip-path:polygon(100%0%,100%100%,0%100%)]"></div>
</div>

The visibility of the line is more pronounced when viewed directly rather than from an image found at https://i.sstatic.net/60Xzf6BM.png

Answer №1

Encounter the issue exclusively on Chrome, and my suspicion is that subpixel rendering inconsistencies are the root cause.

The problem seems to arise only when the div's position is adjusted to a y-position with subpixels (like having a previous sibling with height:80vh and a screen height that cannot be evenly divided by 1.25). This explains why zooming in or out can make the issue appear or disappear.

For instance, in Chrome, the following snippet will exhibit thin spaces under specific screen sizes and zoom levels:

<script src="https://cdn.tailwindcss.com"></script>

<div class="h-[80vh] border-2 border-sky-500 m-2"></div>
<footer>
  <div class="bg-red-500 h-[30rem] relative">
    <div id="top-left" class="w-1/2 h-10 md:h-20 bg-inherit absolute transform -translate-y-full [clip-path:polygon(0%0%,100%100%,0%100%)]">
    </div>
    <div class="w-1/2 h-10 md:h-20 bg-inherit absolute transform -translate-y-full right-0 [clip-path:polygon(100%0%,100%100%,0%100%)]">
    </div>
    <div class="w-1/2 h-10 md:h-20 bg-white absolute bottom-0 [clip-path:polygon(0%0%,100%100%,0%100%)]"></div>
    <div class="w-1/2 h-10 md:h-20 bg-white absolute bottom-0 right-0 [clip-path:polygon(100%0%,100%100%,0%100%)]" gt;
    </div>
  </div>
</footer>

If your issue does stem from subpixel rendering, you can resolve it by enforcing GPU rendering, such as utilizing will-change-transform as depicted below. (Additionally, applying a slight rotation enforces subpixel rendering, like setting --tw-rotate in this case.)

<script src="https://cdn.tailwindcss.com"></script>

<div class="h-[80vh] border-2 border-sky-500 m-2"></div>
<footer>
  <div class="bg-red-500 h-[30rem] relative will-change-transform">
    <div id="top-left" class="w-1/2 h-10 md:h-20 bg-inherit absolute transform -translate-y-full [clip-path:polygon(0%0%,100%100%,0%100%)]">
    </div>
    <div class="w-1/2 h-10 md:h-20 bg-inherit absolute transform -translate-y-full right-0 [clip-path:polygon(100%0%,100%100%,0%100%)]">&ht;
    /div>
    <div class = "w-1/2 h-10 md-h-20 bg-white absolute bottom-0 [clip-path:polygon(0%0%,100%100%,0%100%)]" >& lt;/div >
    </div>;
    <div class = "w-1/2 h-10 md-h-20 bg-white absolute bottom-0 right-0 [clip-path:polygon(100%0%,100%100%,0%100%)]" >& lt;]/div>
         </div>{
             </ footer >
                 

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 toggle elements using CSS slide animations?

Is there a way to make a div slide in and out from the left to right when the user clicks on "clickthis"? Here is an example of CSS code: .container{width:100px; position:absolute; left:-70px;} .container .open{left:0px;} .button{display:block; top:0px; ...

Using Jquery slideToggle is creating additional spacing between inline-block divs

I am struggling with displaying a list of cities in an inline format. <div class="accordion-container"> <a href="#" class="accordion-toggle">London</a> <div class="accordion-content"> <p>Inform ...

JavaScript: Understanding the concept of closure variables

I am currently working on an HTML/JavaScript program that involves running two counters. The issue I am facing is with the reset counter functionality. The 'initCounter' method initializes two counters with a given initial value. Pressing the &a ...

Designing a drop-down selection interface

http://jsfiddle.net/367ms/1/ I need assistance with my code. My goal is to have a blue border that appears 10 px below the text when hovered over. Additionally, I have a submenu that opens on hover, but it automatically closes when trying to navigate down ...

Tips for rearranging a span following an image?

Looking for a solution to rearrange a span element after an image within automatically generated HTML. Sample HTML: <span>closed</span> <img alt="Click to reset" src="xxx" class=""> Currently, the span appears before the img in the cod ...

Is manually coding HTML for email necessary, or are there any practical tools or converters available?

Creating HTML emails is a different challenge compared to designing websites, as it requires working with tables instead of CSS. I'm in need of recommendations for tools specifically designed for HTML email creation, preferably from individuals who h ...

Is there a way to adjust the label size for a material ui TextField component?

My TextField element is defined like this: <TextField id="standard-with-placeholder" label="First Name" className={classes.textField} margin="normal" /> It currently appears as shown in the image below: https://i.sstatic.net/aYi1a.png How ...

The popup is unable to remain in the center of the screen because the background page keeps scrolling back to the top

Whenever I click a button to open a popup window, the page unexpectedly scrolls to the top. It's frustrating because if I'm at the bottom of the page and press the 'submit' button, the popup doesn't display in the center as intende ...

Create a stunning MUI App bar with a blurred effect below a fixed Navbar

Is there a method to apply a blur effect to the background of my material-ui AppBar component, creating a visually appealing overlay below the fixed navbar? I have experimented with using filter: blur(0) but it does not achieve the desired result. I am lo ...

How can we toggle a function to expand or collapse fields generated in an ngFor loop?

One of my challenges involves managing a div that is repeated using *ngFor in Angular. This results in multiple divs on the page, each containing collapsible fields that can toggle. Essentially, I have nested collapsible fields within other collapsible fie ...

Upon selecting the checkbox, the user will be redirected to an input textbox

Can I make it so that when I check a checkbox, it automatically directs me to a textbox as if I pressed the TAB key? Is there a way to achieve this using only HTML and CSS? ...

Changing the CSS class of list items in a navigation: Tips and tricks

Looking to create a navigation menu that changes the CSS class to 'active' when selected? Take a look at the code below: <ul class="smallmenuContainer"> <li><a class="active" href="index.html#red">Home</a></li&g ...

Setting the maximum height for a div element

Struggling to understand how a div can occupy the entire height of a container. In this particular scenario, I am aiming for the "photo" div to take up the full height, with the yellow and green content appearing on the right side of the photo. Below is th ...

Display only distinct items in a v-for loop in Vue.js

I am attempting to show icons based on specific v-for and v-if conditions. However, the icons are appearing multiple times when I only want them to display once. I attempted using v-if = 'index === 0', but this did not resolve the issue. <di ...

Adjusting image dimensions before delivery for a mobile site

On my desktop website, I currently use images with a size of 500*500. However, when it comes to the mobile version of my site, downloading such large images takes an excessive amount of time. Simply specifying width & height attributes in <img> doesn ...

Is there a way to align these blocks in a single row?

Having trouble aligning these buttons horizontally. Any suggestions? I've been tinkering with this for a couple of hours now, so decided to seek help here. The desired effect should resemble the image below, but it's not quite there yet. Thank yo ...

"Is it possible to include a button for horizontal scrolling in the table

I have a bootstrap table with overflowing set to auto within its container, along with a locked first column. While a horizontal scroll bar allows for viewing additional data, I am looking to incorporate buttons for navigation as well. Users should have th ...

What is the most efficient method of organizing form components together?

After exploring numerous tutorials, I have yet to discover the ideal solution for properly marking up a form that contains logical groupings of elements such as labels, controls (input or select), and previous values - essentially single fields. My prefer ...

Deploying an Azure Blob Trigger in TypeScript does not initiate the trigger

After successfully testing my Azure function locally, I deployed it only to find that it fails to trigger when a file is uploaded to the video-temp container. { "bindings": [ { "name": "myBlob", "type&qu ...

The toast feature in Bootstrap 5 seems to be malfunctioning as it does not display properly despite the absence of any

Why isn't the Toast displaying in the code snippet below? I'm using bootstrap 5. I'm puzzled because there are no errors in the developer's tools. Any assistance would be greatly appreciated. <!DOCTYPE html> <html lang="en"& ...