css - 如何在 React 和 CSS 之间进行通信
问题描述
我正在尝试创建一个代码,您可以在其中执行类似的操作
反应:
class app extends React.Component{
//states and stuff
render(){
<div>
<p className = "ellipse" x = {this.state.x} y={this.state.y} rx={this.state.rx} ry={this.state.ry}/>
<div/>
}
}
css
.ellipse{
x:(the input x)
y:(the input y)
rx:(the input rx)
ry:(the input ry)
}
这将创建一个以 x,y 为中心的椭圆,水平半径为 rx,垂直半径为 ry
解决方案
您可以将样式对象传递给您的 React 组件。
但请注意,CSS 属性应该是驼峰式的。是marginLeft
和paddingLeft
。
然后,您可以将您的样式对象连接到您的反应状态。
例子 :-
const [padding, setPadding] = React.useState(10);
<div style={{ paddingLeft: `${padding}px` }} />
推荐阅读
- flutter - 使用 Firestore 为 StreamBuilder 创建流
- arrays - 显示用户输入值的 C 代码
- pre-commit.com - pre-commit.com:.pre-commit-config.yaml 和 requirements.txt 中的相同版本
- chef-infra - 使用 Chef.event_handler 时是否可以访问 run_status 对象?
- c# - 如何在winform的构造方法中使用用户定义的属性?
- r - 列表中每个矩阵的 for 循环
- aws-cli - aws glue get-databases 在 CLI 上返回空列表
- python - Django 使用多部分/表单数据和字典测试发布请求
- python - Python Sqlite3 从表中获取值,就像字典一样
- firebase - 重定向没有任何错误 - displayName