The functionality of CSS clip-path is not fully realized when working with complex multi-path shapes

I have designed an SVG file with three different paths

https://i.sstatic.net/H8K8j.jpg

My intention is to utilize the left, middle, and right sections of the image and apply clipping to each of them individually, achieving this effect: https://i.sstatic.net/slxZw.jpg from its original state shown here: https://i.sstatic.net/U67zn.jpg

CSS

.bgmove {
  position: relative;
  width: 1100px;
  height: 70px;
}

.left {
  clip-path: url(#clipLeft);
  background-color: red;
  width: 403px
}

.middle {
clip-path: url(#clipMiddle);
  background-color: black;
  width: 284px;
  left: 373px;
}

.right {
clip-path: url(#clipRight);
  background-color: green;
  width: 473px;
  left: 627px;
}

.left,
.middle,
.right {
  height: 70px;
  position: absolute;
}

HTML Code

<html>
  <head>
  </head>
  <body>
    <div class="bgmove">
      <div class="left"></div>
      <div class="middle"></div>
      <div class="right"></div>
    </div>

    <svg height="70" width="1100">
      <defs>
        <clipPath id="clipLeft">
          <path d="M40.4575,70,0,0H362.543L403,70Z" />
        </clipPath>
        <clipPath id="clipMiddle">
          <path d="M1100,70,1059.55,0H627l40.4506,70Z" />
        </clipPath>
        <clipPath id="clipRight">
          <path d="M657,70,616.38,0H373l40.62,70Z" />
        </clipPath>
      </defs>
    </svg>
  </body>
</html>

You can view the final result by clicking on the following link: https://jsfiddle.net/Zivo/y4srujqe/

Upon inspection, I realized that only the left part is being clipped while the middle and right parts remain hidden despite using identical settings. What could be causing this issue?

Please advise on what may be incorrect in my implementation.

Answer №1

The svg elements do not contain the div tags. When using shapes for a clip-path, their positioning is based on the origin of the div itself. This results in the clipMiddle and clipRight being positioned further to the right than intended. To demonstrate this, if you replace each clip with #clipLeft, you can observe the paths:

.left {
  clip-path: url(#clipLeft);
  background-color: red;
  width: 403px
}

.middle {
  clip-path: url(#clipLeft);
  background-color: black;
  width: 284px;
  left: 373px;
}

.right {
  clip-path: url(#clipLeft);
  background-color: green;
  width: 473px;
  left: 687px;
}

You can view the outcome at https://jsfiddle.net/vnkgd3r5/. The middle path is not correctly clipped because its length differs from the other two paths.

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

What are some ways to display unprocessed image data on a website using JavaScript?

I have an API endpoint that provides image files in raw data format. How can I display this image data on a website using the img tag or CSS background-image property, without utilizing canvas? One possible approach is shown below: $.get({ url: '/ ...

Unexpected behavior encountered when making an AJAX request that involves CSS classes

One of the functionalities on a page involves selecting values for CSS class attributes. Within the rails application show view, there is a style block and a div that utilizes these styles: <style> #bg_<%= @promolayout.id %> { backgroun ...

The specified height for input[type=button] in Firefox/Safari is adjusted by subtracting the padding and border

When implementing the following CSS: input[type=button] { background-color: white; border: 1px solid black; font-size: 15px; height: 20px; padding: 7px; } along with this HTML: <input type="button" value="Foo" /> I anticipate that the t ...

"Is it possible to keep an eye on two different events and take action once they both

I have a menu with different submenus for each list item, all utilizing the same background tag. Currently, when one submenu is open and I hover over another list item, the previous submenus hide and the new one opens. What I want is for the content to cha ...

Creating a Rectangular Trapezoid Shape with CSS - Eliminating Unnecessary Spacing

I'm trying to create a trapezoid button using CSS. Here is the intended look: https://i.sstatic.net/0vqlk.png However, my current implementation looks like this: https://i.sstatic.net/QrR4t.png The button appears fine but there seems to be some e ...

Hide an absolutely positioned div when another element is clicked outside of it

Here is the code for the function that executes when a button on my website is clicked: function displayOverlay() { document.getElementById("overlay").style.visibility = "visible"; document.getElementById("dim").style.visibility = "visible"; d ...

What is the reason that in Bootstrap, the buttons become full width when using "fixed-bottom," even though they are not full width without it?

My goal is to have 1 button positioned near the top and 2 buttons fixed at the bottom. However, when I add the fixed-bottom` class to the div containing the bottom-fixed buttons, it causes them to span the full width of the container. This results in the b ...

Desktop display issue: Fontawesome icon not appearing

Having trouble getting the fontawesome icon to display properly on my website. It appears in inspect mode, but not on the actual site itself. Any suggestions on how to fix this issue? import React, { Fragment, useState} from "react"; import { Na ...

Attempting to position two buttons and a logo in the footer with the help of Bootstrap!

Currently working on a new website project utilizing Bootstrap-4 My goal is to position a logo to the left, a link button in the center, and another link button to the right within a footer div. So far, I've managed to achieve the layout, but the iss ...

What is the best way to create a large-scale matrix using SVG technology?

I want to create a 10000X10000 matrix in canvas/svg, with each cell containing a square. I attempted to accomplish this using canvas and two loops: for(i=0; i<10000; i++){ for(j=0;j<10000; j++){ /*some drawing code*/ console.log(i,' ...

Identifying a span element and appending to its classList

I am currently working on code that generates spans, and my objective is to adjust the color of specific spans based on their text content. I have identified a section where I need assistance with the syntax of the code I should input. My aim is to locate ...

CSS3 :target and display:none inconsistency problem in Internet Explorer and Firefox

Creating a one-page site with navigation tabs that toggle between hidden divs using :target CSS3 selector is my current project. To ensure the first div is visible upon page load, I implemented this line of code: document.location.href = "#div1"; The HTM ...

There is an ample amount of blank space located at the bottom of the page

There seems to be an excess of white space at the bottom of my webpage, despite my efforts to adjust margins and padding. I've inspected the elements using browser developer tools but have been unable to pinpoint the issue. var chatResponseBox = do ...

Ensure that the Left and Right menu are fixed in position, while allowing the middle content to be scrollable

I'm in the process of creating a web page with a fixed left and right menu, while the middle content should be scrollable and positioned behind the menus. I've attempted to implement this using the following HTML and CSS, but encountered an error ...

jQuery document.ready not triggering on second screen on Android device

Why is jQuery docment.ready not firing on the second screen, but working fine on the first/initial screen? I also have jQuery Mobile included in the html. Could jQuery Mobile be causing document.ready to not work? I've heard that we should use jQuery ...

Navigate to specific element from bootstrap navigation bar

I am in the process of creating a website for a small organization. The website is being constructed using bootstrap 4, and there is a navbar that connects to various flex-containers. I want these connections to smoothly scroll to their respective elements ...

Enhancing readability in a vertical CSS menu with proper spacing

I'm looking to increase the spacing between each menu item as they appear too close together. Can someone help me with managing this? The menu names are currently right under one another, almost touching. What is the best way to create more space betw ...

Updating the background color and adjusting the text input color in the upcoming user interface

import {Input} from "@nextui-org/react"; <Input label="Email" radius='sm' /> https://i.sstatic.net/gprRpEIz.png I am looking for a way to customize the input text color and the label color separatel ...

The functionality of Javascript stops working once an ajax call is made

My attempt to make an Ajax call to fetch additional data upon clicking a button was successful on the first click. However, subsequent clicks on the button do not trigger the action, and the data retrieved does not apply any JavaScript functionalities like ...

Steps for making a hyperlink functional from a database

Currently on my website, I have implemented a 'save to favorites' button which allows users to save recipes to their favorites and view them on their dashboard. While I have successfully displayed the favorites on the dashboard with hyperlinks, I ...