javascript - 带有三元运算符的 CSS - 仅在一种情况下设置属性
问题描述
我在我的 CSS 中使用 react native Platform API 作为三元运算符。
例如,我正在设置高度:
height: Platform.OS === 'ios' ? 40 : 50,
但是,有时我想在一种情况下设置属性,但在另一种情况下却不想:
height: Platform.OS === 'ios' ? 40 : <Don't set height>
实现这一目标的正确逻辑是什么?
解决方案
The approach i use is by making 2 style components :
const styles = StyleSheet.create({
withHeight: {
color: 'red',
height:40
},
withoutHeight:{
color:'red'
}
});
So in your component you can do like :
<View style={Platform.OS =='ios'?styles.withHeight:styles.withoutheight}>
Hope it helps. feel free for doubts
推荐阅读
- python - 将 Python ML 模型部署到 NodeJS Web 应用程序
- python - 当我在for中增加变量时,为什么迭代值没有发生任何事情?
- mysql - 是否有一个 mySQL 过程可以将重复的数据行合并为一个,然后允许我像处理一行一样操作该数据?
- jquery - 更改一个文本框值时使用哪个事件它应该更改 jquery 中另一个文本框中的相关值
- vb.net - 数据表中不需要的字符
- python - 从二进制矩阵构建图
- java - 使用 Java 获取终端多参数命令的输出
- java - 如何为 Base64.decodeBase64 编写 JUnit 测试
- c++ - 如何在函数声明中为 std::unordered_map 的引用分配默认(空)值?
- python - 在外部 .py 文件中使用 django 模型