Nuxt compiles CSS Opacity at 1% instead of 100% when deployed to Netlify

Viewed 1207

I have a Nuxt app that works great locally. When I deployed it to Netlify (where yarn generate was run automatically), I noticed that there were some odd CSS things going on.

I have a card with a hover effect:

<style lang="scss" scoped>
  .gallery-card {
    align-items: center;
    background: url('/backgrounds/image-1.jpg') no-repeat center center;
    background-size: cover;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    height: 400px;
    justify-content: center;
    position: relative;
    max-width: 100%;

    .overlay {
      background-color: rgba(255, 255, 255, 0.3);
      bottom: 0;
      left: 0;
      opacity: 0%;
      position: absolute;
      right: 0;
      top: 0;
      transition: 0.2s all ease-in-out;
      visibility: hidden;
    }

    .gallery-title {
      color: white;
      text-shadow: 3px 3px rgba(0, 0, 0, 0.25);
      transition: 0.2s all ease-in-out;
    }

    .visit-btn {
      opacity: 0;
      transition: 0.2s all ease-in-out;
      visibility: hidden;
    }

    &:hover {
      .overlay, .visit-btn {
        opacity: 100%;
        visibility: visible;
      }
    }
  }
</style>

The hover effect works locally but not in production. Upon inspecting it in production, the elements underneath :hover are being given opacity: 1%; instead of opacity: 100%;.

Has this happened to anyone else, or does anyone have suggestions? Thanks!

2 Answers

Thanks to @Phil for the answer. It's funny how your mind can immediately think it's got to be some complicated thing (I immediately thought it was some sort of Nuxt compile config), when in fact the simplest thing was the cause (using the Opacity property properly).

Solution

Change to opacity: 1; instead of opacity: 100%;

Doh!

This isn't just a Nuxt issue, this happens with create-react-app as well. Changing from opacity: 100%; to opacity 1; fixed my build issue.

This post saved me from having an aneurysm. So it most likely is a SCSS issue or a Netlify one.

Related