简体   繁体   English

对于CSS Pseudo类,为什么React开发人员必须进行状态更改?

[英]For CSS Pseudo classes ,why React developers have to go for state changes?

In React, Can somebody explain me, for CSS Pseudo classes (eg. hover,focus,active etc), why I have to go for state changes in react ? 在React中,有人可以为我解释一下CSS伪类(例如,悬停,焦点,活动等),为什么我必须在react中进行状态更改吗? why not react developers kept that style like we do in CSS? 为什么不像开发人员那样在CSS中保持开发人员的反应呢?

The example which you are referring on https://jsfiddle.net/rz2t224t/2 shows handling specific events on the HTML element. 您在https://jsfiddle.net/rz2t224t/2上引用的示例显示了处理HTML元素上的特定事件。

return React.createElement(
 "button",
 {onMouseOver: this.mouseOver, onMouseOut: this.mouseOut},
 label
);

With above code when onMouseOver and onMouseOut event occur on the button then mouseOver and mouseOut function will be executed respectively. 使用上述代码,当按钮上发生onMouseOveronMouseOut事件时,将分别执行mouseOver和mouseOut函数。

We can use CSS with reactjs normally as we do. 我们可以正常使用CSS与reactjs。

For example of hover : https://jsfiddle.net/balaji_mitkari/69z2wepo/68520/ 例如悬停: https : //jsfiddle.net/balaji_mitkari/69z2wepo/68520/

You have to use .css to achieve what you are after, you can't do it with inline styles: 您必须使用.css来实现所追求的目标,而内联样式则无法实现:

from https://medium.com/@jviereck/modularise-css-the-react-way-1e817b317b04#.gwcfeppld 来自https://medium.com/@jviereck/modularise-css-the-react-way-1e817b317b04#.gwcfeppld

CSS pseudo classes and media queries are not supported: Using inline styles doesn't give you the full expressiveness compared to writing normal CSS: In particular, there is no way to express CSS selectors for pseudo classes like .notification:hover or .notification:before. 不支持CSS伪类和媒体查询:与编写普通CSS相比,使用内联样式不能给您完整的表达力:特别是,无法为.notification:hover或.notification等伪类表达CSS选择器:之前。 Also, it is not possible to use media queries to adapt the styling based on view medium (eg adjust the content to look different when viewed on mobile vs. on desktop). 同样,不可能使用媒体查询来基于查看媒体来调整样式(例如,调整内容以使其在移动设备上查看时与在桌面上查看时有所不同)。 Libraries like Radium offer a way to work around these limitations but have to do a nasty tricks to get there. 像Radium这样的库提供了一种方法来解决这些限制,但必须采取一些讨厌的技巧才能达到目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM