[英]CSS - Rotate radial-gradient
I have got a <div>
with radial-gradient
, but it is at a wrong angle. 我有一个带有
radial-gradient
的<div>
,但它的角度是错误的。 Changing the angle of simple linear-gradient
is easy, but it has multiple gradients. 改变简单
linear-gradient
的角度很容易,但它有多个渐变。 I can't add 90deg
at the start, because it doesn't work. 我不能在开始时添加
90deg
,因为它不起作用。
Below is my gradient. 下面是我的渐变。 The waves are from bottom to top, how can I turn them to make them from left to right ( I want to use only
background
property )? 波浪从下到上,如何将它们从左到右转动( 我只想使用
background
属性 )? Thanks for help. 感谢帮助。
div { width: 400px; height: 400px; background: radial-gradient(circle at 100% 50%, transparent 20%, #ff0000 21%, #ff0000 34%, transparent 35%, transparent), radial-gradient(circle at 0% 50%, transparent 20%, #ff0000 21%, #ff0000 34%, transparent 35%, transparent) 0 -50px; background-size: 75px 100px; }
<div> </div>
This should work. 这应该工作。 Swapped the values for the circles and background size.
交换了圆圈和背景大小的值。
div { width: 400px; height: 400px; background: radial-gradient(circle at 50% 100%, transparent 20%, #ff0000 21%, #ff0000 34%, transparent 35%, transparent) 50px 0, radial-gradient(circle at 50% 0%, transparent 20%, #ff0000 21%, #ff0000 34%, transparent 35%, transparent) 0 0; background-size:100px 75px; }
<div> </div>
You can use CSS transform: rotate
property to rotate the div, instead of gradient. 您可以使用CSS
transform: rotate
属性来旋转div,而不是渐变。 :) :)
div { width: 400px; height: 400px; background: radial-gradient(circle at 100% 50%, transparent 20%, #ff0000 21%, #ff0000 34%, transparent 35%, transparent), radial-gradient(circle at 0% 50%, transparent 20%, #ff0000 21%, #ff0000 34%, transparent 35%, transparent) 0 -50px; background-size:75px 100px; transform: rotate(90deg); }
<div></div>
You can use :before
pseudo class for the gradient background and then apply transform
to the :before
(will not affect div
). 您可以在渐变背景的伪类
:before
使用:before
然后将transform
应用于:before
(不会影响div
)。
Stack Snippet 堆栈代码段
div { width: 400px; height: 400px; position: relative; z-index: 0; } div:before { content: ""; background: radial-gradient(circle at 100% 50%, transparent 20%, #ff0000 21%, #ff0000 34%, transparent 35%, transparent), radial-gradient(circle at 0% 50%, transparent 20%, #ff0000 21%, #ff0000 34%, transparent 35%, transparent) 0 -50px; background-size: 75px 100px; position: absolute; top: 0; left: 0; right: 0; bottom: 0; transform: rotate(90deg); z-index: -1; }
<div>Content</div>
Simply change some values. 只需更改一些值即可。 You may also specify a
background-position
to avoid the first cut part of the wave: 您还可以指定
background-position
以避免波形的第一个切割部分:
div { width: 400px; height: 400px; background: radial-gradient(circle at 50% 100%, transparent 20%, #ff0000 21%, #ff0000 34%, transparent 35%, transparent), radial-gradient(circle at 50% 0%, transparent 20%, #ff0000 21%, #ff0000 34%, transparent 35%, transparent)-116px 0; background-size: 77px 57px; background-position: -5px 25px, 33px 20px; }
<div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.