;
가 아닌 ,
로 한다''
를 붙여야한다.
을 붙이지 않는다마진이나 패딩의 경우 축약형 대신 상하,좌우 값을 한번에 적용할 수 있는 속성이 존재한다(marginVertical, paddingHorizontal 등)
CSS
.item { flex: 1 1 auto; margin: 0 4px 0 6px; }
RN
item: { flexGrow: 1, flexShrink: 1, flexBasis: 'auto', marginVertical: 0, marginBottom: 4, marginLeft: 6, }
CSS/HTML
.bigBlue { color: blue; font-weight: bold; font-size: 30px; } .red { color: red; } <div class="red bigBlue">red, not blue</div>
결과: color: red
RN
bigBlue: { color: 'blue', fontWeight: 'bold', fontSize: 30, }, red: { color: 'red', } render() { return ( // 여러개의 스타일을 전달할 때 배열을 이용한다. <Text style={[styles.red, styles.bigBlue]}>red, then bigBlue</Text> ); }
결과: color: blue(스타일 선언 순서와 상관 없이 blue값이 적용된다. red값이 먼저 전달된 후 blue값이 갱신 됨)
RN에서 선택 스타일링을 주고자할 때
<View> { data.map((item, index) => ( <View style={[ styles.item, (index === 0) && { borderTopWidth: 0 }, // CSS: first-child (index % 2 === 1) && { backgroundColor: '#eee' } // CSS: nth-child(even) ]}> <Text>{item.name}</Text> <Text>{item.price}</Text> </View> )) } </View>
map함수와 index를 이용해 첫 번째와 짝수번째 item에 스타일을 적용하였다. 위 방법은 map을 사용하기 때문에 데이터 배열이 필요하기 때문에 데이터를 사용하지 않는 디자인적인 요소라면 의미없는 배열을 사용해야한다.
또한 item들이 서로 관련되어 있지 않아 map함수와 index의 활용이 어렵다면 사용하기 힘든 단점이 있다
<Text>{`첫번째 줄
두번째 줄`}
</Text>
<Text>첫번째 줄{'\n'}두번째 줄</Text>
<Text>첫번째 줄</Text>
<Text>두번째 줄</Text>
RN
import {Platform, StyleSheet} from 'react-native'; const styles = StyleSheet.create({ container: { flex: 1, ...Platform.select({ ios: { backgroundColor: 'red', }, android: { backgroundColor: 'blue', }, }), }, });