Firefox Experiences a Bizarre CSS Clip Path Glitch

Testing out CSS Clip Path from the provided website led to an unexpected bug. Surprisingly, the code works flawlessly on both CodePen and JSFiddle but fails to execute properly within my local development environment or app.

Here is the snippet of CSS used in attempting to create a polygon:

nav {
    position: fixed;
    bottom: 0;
    background: #BE0F16;
    color: #fff;
    width: 100%;
    padding: 2rem 1rem;
    text-align: right;
    -webkit-clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 50%);
    clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 50%);
    -webkit-clip-path: url("#clip-shape");
    clip-path: url("#clip-shape");
}
nav .next-chapter {
    color: #fff;
    padding-left: 1rem;
}

And here's the corresponding HTML:

<!DOCTYPE html>
<html>

<head>
    <title>Something</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <link href="css.css" rel="stylesheet" />
</head>

<body>
    <nav>
        <a class="menu"><i title="Menu" class="fa fa-bars"></i><h1 class="visuallyhidden">Menu</h1></a>
        <a class="next-chapter" href="/<%=next%>"><i title="Next Chapter" class="fa fa-hand-o-right"></i><span class="visuallyhidden">Next Chapter</span></a>
        <a id="comment" href="http://twitter.com/?status=@uebyn"></a>
    </nav>
    <svg width="0" height="0">
        <defs>
            <clipPath id="clip-shape" clipPathUnits="objectBoundingBox">
                <polygon points="0 0, 0 1, 1 1, 1 .5" />
            </clipPath>
        </defs>
    </svg>
    <script src="script.js"></script>
</body>

</html>

Despite following the instructions outlined in the article meticulously, upon opening index.html, I was greeted with a rectangle instead of the anticipated polygon shape. Interestingly, copying the same code to both CodePen and JSFiddle shows the correct polygon rendering.

This anomaly has left me perplexed. Why does Firefox correctly render the CSS clip path on CodePen and JSFiddle but not within my own HTML file? Even after transferring my entire HTML code to CodePen, the issue persists. Any suggestions will be greatly appreciated.

Answer №1

When you include the CSS in a separate file named css.css, and write

clip-path: url("#clip-shape");

This code is actually shorthand for

clip-path: url("css.css#clip-shape");

However, if the file css.css does not contain an element with an ID of clip-shape (as all elements are in the HTML file), you should instead write

clip-path: url("<the name of the HTML file goes here>#clip-shape");

If you are using jsfiddle where everything is in the same document, this issue would not arise.

Just to clarify, there is no bug in Firefox related to this issue.

Answer №2

Appreciate it, this solution did the trick when implementing the rule in the CSS file:

.myclass{
clip-path: url("/~powersparks/bz.html#clip");
}

It also functions as intended when added solely to the d3 pattern:

     svg.append("path")
      .datum(data)
      .attr("class", "area")
      .attr("clip-path", "url('/~powersparks/bz.html#clip')")
      .attr("d", area);

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

Do LI elements need to be floated left for right alignment within a container?

I have a code where the LI elements are floated left and aligned to the left of the container. I want to change their alignment to the right using CSS. How can I achieve this? For example: [Item1..................................Item2] Below is the HTML ...

How to use a loop to alternate CSS classes in HTML?

Here is a sample code using a while loop: while($fetch = $stm->fetchAll()) { echo '<tr class=""'>; echo '<td>' . $fetch['name'] . '</td>'; echo '</tr>'; } I want to ...

What is the best way to calculate precise pixel dimensions for mobile devices?

Upon inspecting the browser's developer tool, it indicates that the resolution of an iPhone X is 375*812, although this may not be the actual resolution. While CSS pixels do not always align perfectly with display resolution, the question remains - If ...

Hiding collapsible navbar in Angular 7 when in responsive mode

Hey there, I'm currently using a navbar in Angular 7 and I'm looking for a way to collapse it when clicking on another area of the page. When resizing my browser or when accessing the app on mobile, the navbar displays a menu icon with three bars ...

Angular not executing Jquery script in included HTML files

Underneath is a simple jquery code snippet: $(document).ready(function() { $("h2").click(function(){ alert("Hello world"); }) }); After clicking on any h2 tag in the website, an alert message will display. The code functions properl ...

Locate the closest pals near my present whereabouts

Is it possible to find my friends by obtaining their location from their mobile phones when they are near me? I have a code snippet below with the variable cities where I can input the numbers of my friends. Can I achieve this or do I need to make some m ...

Creating an image in jpg format from an html file using a button

I have a unique HTML code for an email signature from my company and I am looking to add a button that can generate a JPG or PNG image of the signature without having to resort to PrintScreen and manual cropping in editing tools like Paint or Photoshop. Ho ...

Overlaying Div Concealed by Background Video Filter

Whenever we add a filter to our background video, the div overlay ends up moving behind the video and becoming hidden. To see an example of this issue, check out this fiddle showcasing the background video with the text overlay: https://jsfiddle.net/dyrepk ...

What is the best way to generate a compilation of quotes on my HTML page using JavaScript objects?

It would be great if someone could provide a Jsfiddle, thank you! In my js document, I have received the following sample: var comments = [ {"name":"John","comment":"Text","timestamp":69379200}, {"name":"Ronny","comment":"Text","times ...

Challenges encountered with input outcomes

I am facing an issue with input results. I have a button that triggers a function to check for empty input fields. However, when I click the button, it always falls into the last if statement and displays as if the fields are not empty. I have already att ...

Stretching of images in Safari and Chrome

Having trouble with image display on different browsers? Look at my code snippet below: <style> #globalpsa { width:100%; height:100%; border:3px double #fff; margin:2% auto; } #globalpsa input[type="image"] { wid ...

Ensuring that nested objects in an absolutely positioned element do not wrap, clear, or stack

Looking for some assistance with my tooltip menu. The problem I'm facing is that my links keep wrapping to a new line, and I can't figure out how to prevent this. I've already attempted using display:inline and float:left on the links within ...

Adjusting column styles on mobile or desktop devices

My row has two columns <div class="row"> <div class="col-9"> hello </div> <div class="col-3"> world </div> </div> But I want to change the column classes for small screens, so they would be ...

Decode my location and input the address before validating it

While I have come across numerous plugins that enable geolocation and display it on a map, I am searching for something unique. I am interested in implementing geocoding when a user visits the page with an option to "allow geolocation." If the user agrees ...

Switching the image on click of an option tag

I'm looking to create a dynamic image changing feature using two select tags in my HTML. One select tag is for the model and the other is for the color. When a user selects a model from the first dropdown, I want the image to change to reflect that mo ...

Set up event listener for clicks on dynamically created HTML table

I am creating an html table during an ajax callback like ... success: function (data) { if (data != undefined) { var table = $("<table id='carTable' />").addClass("table table-striped table-bordered table-condensed"); v ...

Is it possible to blur all elements of a form except for the submit button?

Can someone help me with a form issue I am facing? <form> <input type="text>' <input type="submit">' </form>'' After submitting the form, I would like to blur the entire form: $(this).closest('form') ...

Mall magnitude miscalculation

I am currently experiencing an issue with Galleria and the Flickr plugin. Some images are displaying correctly, while others appear scaled and parts of them are cut off. How can I fix this problem? Below is the HTML code for the Galleria gallery on my web ...

Mixing up bootstrap grid columns with mobile-responsive view patterns

I have this specific design that I need help with: This design is intended for desktop or larger screens only. Note: The red and green boxes in the design are not of equal height. https://i.sstatic.net/snAKt.png For mobile devices or smaller screens, t ...

The issue of excessive body overflow arises upon opening multiple modals successively

I'm facing an issue with bootstrap modals. When I open the first modal, the body gets the class modal-open which is correct. However, when I click the button to close the first modal and open another one, the class is removed from the body even though ...