[英]How to set custom style to antd Rate Component
When I mouse over a star in Ant Design's Rate
component it's size increases and on mouse out it goes back to the original size.当我将鼠标悬停在 Ant Design 的
Rate
组件中的一颗星上时,它的大小会增加,鼠标移开时它会恢复到原始大小。 This is probably due to an innate transform: scale(x)
in the component.这可能是由于组件中的先天
transform: scale(x)
。 I want to stop this animation/behaviour of stars if I mouse over them.如果我将鼠标悬停在星星上,我想停止星星的动画/行为。 How can I achieve that?
我怎样才能做到这一点? I have tried different
element state
in devtools but failed.我在 devtools 中尝试了不同的
element state
但失败了。
I'm able to set custom width
and height
but I can't find something which can stop that animation/transform:/.我可以设置自定义
width
和height
,但我找不到可以停止动画/转换的东西:/。 code sandbox代码沙箱
.ant-rate-star.ant-rate-star-full i svg {
width: 15px;
height: 20px;
margin: -3.5px;
}
.ant-rate-star.ant-rate-star-zero i svg {
width: 15px;
height: 20px;
margin: -3.5px;
}
.ant-rate-star.ant-rate-star-half.ant-rate-star-active i svg {
width: 15px;
height: 20px;
margin: -3.5px;
}
.ant-rate-star.ant-rate-star-full i svg:hover {
transform: scale(1); //not working
}
The key classes to isolate here are .ant-rate-star.ant-rate-star-full
, .ant-rate-star.ant-rate-star-zero
, and .ant-rate-star.ant-rate-star-half.ant-rate-star-active
as these correspond to the fully filled, empty, and half filled stars.这里要隔离的关键类是
.ant-rate-star.ant-rate-star-full
、 .ant-rate-star.ant-rate-star-zero
和.ant-rate-star.ant-rate-star-half.ant-rate-star-active
因为这些对应于完全填充的、空的和半填充的星星。 You're right to assume it was transform: scale(x);
你是正确的假设它是
transform: scale(x);
. . With a little testing you can find the right scale value (oddly enough
.91
was the most seamless).通过一些测试,您可以找到正确的比例值(奇怪的是,
.91
是最无缝的)。 I also had to change the transition
since the root element had some sort of transition where the counter scaling would work but there would be a short period of 'bounce' where it was transitioning from the attempted scale up to the forced scale down.我还必须更改
transition
,因为根元素具有某种过渡,在该过渡中计数器缩放可以起作用,但是会出现短暂的“反弹”,从尝试放大到强制缩小过渡。
Here is the update code sandbox .这是更新代码沙箱。 Below is the updated CSS.
以下是更新后的 CSS。
.ant-rate-star.ant-rate-star-full,
.ant-rate-star.ant-rate-star-zero,
.ant-rate-star.ant-rate-star-half.ant-rate-star-active {
transition: transform 0s;
}
.ant-rate-star.ant-rate-star-half.ant-rate-star-active:hover {
transform: scale(0.91);
}
.ant-rate-star.ant-rate-star-full:hover {
transform: scale(0.91);
}
.ant-rate-star.ant-rate-star-zero:hover {
transform: scale(0.91);
}
I actually also wrote a blog post a while back where I wrote a blog post about my own custom star rating system with vanilla JS, CSS and HTML if you're interested in something a bit more easily customizeable:).实际上,我不久前还写了一篇博文,其中我写了一篇关于我自己的自定义星级评分系统的博文,其中包含香草 JS、CSS 和 HTML,如果你对更容易定制的东西感兴趣的话:)。
You can style inline on the component:您可以在组件上设置内联样式:
<Rate style={{ color: '#00c' }}>
You don't need to complicate the things here.你不需要在这里把事情复杂化。 You can simply use fontSize property as follows which will allow you resizing the icon's size -
您可以简单地使用 fontSize 属性,如下所示,这将允许您调整图标的大小 -
<Rate disabled defaultValue={3} style={{ color: "black", fontSize:10 }} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.