如何在 React Native 實作中轉換 CSS 以執行以下操作?
.parent.parent-1 .sub-class-1 {
background: yellow;
}
.parent.parent-2 .sub-class-1, .parent.parent-2 .sub-class-2 {
background: red;
}
<div class="parent parent-1">
<div class="sub-class-1">Test1</div>
<div class="sub-class-2">Test2</div>
</div>
uj5u.com熱心網友回復:
您可以將div視為 aView然后為樣式創建樣式表,因此 -
import { StyleSheet, View, Text } from 'react-native';
const styles = StyleSheet.create({
parent: {
backgroundColor: 'yellow',
},
subClass: {
backgroundColor: 'red'
},
});
<View style={styles.parent}>
<View style={styles.subClass}><Text>Text1</Text</View>
<View style={styles.subClass}><Text>Text2</Text</View>
</View>
免責宣告 - 我不太確定你的 CSS 是否正確,我沒有看到你在哪里使用“parent-2”,所以我只是假設了一個簡單的例子
uj5u.com熱心網友回復:
您可以使用樣式組件:
例子:
export const Container = styled.View`
height:10px;
width:20px;
flex-direction:row;
background-color:null;
`
用:
將您的視圖或子視圖包裹在如下所示的 Container 中:
<Container>
//...rest of your code
</Container>
參考鏈接:
帶有 React Native 的樣式組件
樣式組件
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/358479.html
上一篇:自己行中影像的CSS選擇器
