最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to apply linear-gradient 'to left' in tailwind? - Stack Overflow

programmeradmin4浏览0评论

I have achieved the following with [mask-image:linear-gradient(to_right,transparent_0%,#000_1%)]:

But I have no idea how to do the same for the right side. I have tried many different things but no luck. There seems to be no to_left parameter. Any help much appreciated!

I have achieved the following with [mask-image:linear-gradient(to_right,transparent_0%,#000_1%)]:

But I have no idea how to do the same for the right side. I have tried many different things but no luck. There seems to be no to_left parameter. Any help much appreciated!

Share Improve this question asked Mar 18 at 1:05 AshAsh 9283 gold badges15 silver badges30 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 1

Your code places it to the left by default. To position it on the right, either swap the colors or use to left.

To apply it on both sides, it needs to extend across the entire width, meaning it should logically start and end with transparency.

(from 90deg) to_right:
- left side: 0% (from)
- right side: 100% (to)

(from 270deg) to_left:
- left side: 100% (to)
- right side: 0% (from)
transparent 0%, #000 40%, #000 60%, transparent 100%
    /\                  /\                  /\
 left side            center             right side

See my example below:

<script src="https://cdn.jsdelivr/npm/@tailwindcss/browser@4"></script>

<div class="
  w-64 h-16 bg-yellow-100 text-center
  [mask-image:linear-gradient(to_right,transparent_0%,#000_40%)]
">Left side</div>

<div class="
  w-64 h-16 bg-yellow-200  text-center
  [mask-image:linear-gradient(to_left,transparent_0%,#000_40%)]
">Right Side</div>

<div class="
  w-64 h-16 bg-yellow-300  text-center
  [mask-image:linear-gradient(to_right,transparent_0%,#000_40%,#000_60%,transparent_100%)]
">
  Left & Right Side
</div>

To increase the transparent area, you need to increase the percentage on the left side and decrease it on the right side, following the example above. This is because the percentage indicates the point where the color blending starts.

<script src="https://cdn.jsdelivr/npm/@tailwindcss/browser@4"></script>

<div class="
  w-64 h-16 bg-yellow-300  text-center
  [mask-image:linear-gradient(to_right,transparent_10%,#000_40%,#000_60%,transparent_90%)]
  // transparent_10% first color from left side
">
  Left & Right Side (to_right)
</div>
<div class="
  w-64 h-16 bg-yellow-300  text-center
  [mask-image:linear-gradient(to_left,transparent_10%,#000_40%,#000_60%,transparent_90%)]
  // transparent_10% first color from right side
">
  Left & Right Side (to_left)
</div>

you could try using degrees to align the gradient

[mask-image:linear-gradient(270deg,transparent_0%,#000_20%)]
发布评论

评论列表(0)

  1. 暂无评论