Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

linear-gradient cannot include transparent #498

Closed
pathawks opened this issue Aug 9, 2014 · 6 comments
Closed

linear-gradient cannot include transparent #498

pathawks opened this issue Aug 9, 2014 · 6 comments

Comments

@pathawks
Copy link

pathawks commented Aug 9, 2014

I am trying to fade from white to transparent, but because bourbon sets the background color to white, the whole background is white.

@include linear-gradient(white 0px, transparent 100px);

This produces the following CSS:

background-color:#fff;
background-image:-webkit-linear-gradient(#fff 0px,transparent 100px);
background-image:linear-gradient(#fff 0px,transparent 100px);

The fallback background-color prevents any part of the background from being transparent.

bourbon does check to see if the fallback color is transparent, but it only checks the first color step.

  // Set $G1 as the default fallback color
  $fallback-color: nth($G1, 1);

  // If $fallback is a color use that color as the fallback color
  @if (type-of($fallback) == color) or ($fallback == "transparent") {
    $fallback-color: $fallback;
  }
@Nevraeka
Copy link

@pathawks - is this for layered gradients? If its not - try using

@include linear-gradient(rgb(255,255,255) 0px, rgba(255,255,255,0) 100px);

@Nevraeka
Copy link

Added a PR for forcing better transparency for layered gradients w/ an optional variable

@donokuda
Copy link

@pathawks You can also set the fallback color to transparent using the $fallback variable:

@include linear-gradient(white 0px, transparent 100px, $fallback: transparent);

@lenart
Copy link

lenart commented Dec 11, 2014

Ran into same problem. Had a black transparent gradient (opacity 80% to 60%) and wanted a fallback color with, say, 60% transparency (or flat color). This would work if instead of explicitly setting background-color and background-image we'd only set background property but I guess there's a reason guys didn't do that from the beginning.

@tysongach tysongach modified the milestone: 4.2.0 Dec 29, 2014
@tysongach tysongach modified the milestone: 4.2.0 Jan 23, 2015
@13protons
Copy link

I agree that this is unexpected behavior, but in the meantime you can avoid the $fallback variable by specifying values backwards and using a directional keyword. This lets "transparent" becomes the fallback by virtue of being the first value given:

// No gradient, just white
@include linear-gradient(white 0px, transparent 100px);

// Gradient w/ transparency on right, white on left
@include linear-gradient(to left, transparent , white);

@tysongach
Copy link
Contributor

Don’s comment above should resolve this original issue of fading from white to transparent:

@include linear-gradient(white 0px, transparent 100px, $fallback: transparent);

Here’s a CodePen: http://codepen.io/tysongach/pen/bdEwvV

It’s also worth noting that unless you need IE9 support, vendor prefixing is no longer needed, and you can go with regular ’ol CSS:

background: linear-gradient(180deg, white, transparent);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants