Can I use CSS for styling my ReactNative component. Currently I can only use StyleSheet like this:
var styles = React.StyleSheet.create({
autocomplete: {
backgroundColor: '#FFF',
zIndex: 5,
},
...
I want to use CSS instead of this as in ReactJs
Can I use CSS for styling my ReactNative component. Currently I can only use StyleSheet like this:
var styles = React.StyleSheet.create({
autocomplete: {
backgroundColor: '#FFF',
zIndex: 5,
},
...
I want to use CSS instead of this as in ReactJs
Share Improve this question edited Dec 13, 2021 at 10:21 Martin 6,1562 gold badges26 silver badges47 bronze badges asked Mar 22, 2017 at 10:59 PranavPinarayiPranavPinarayi 3,2075 gold badges24 silver badges33 bronze badges 2- 1 Go through the documentation for more info facebook.github.io/react-native/releases/0.23/docs/… – Hariks Commented Mar 22, 2017 at 12:39
- 2 Fix link above: reactnative.dev/docs/style – wvdz Commented Apr 8, 2020 at 7:43
5 Answers
Reset to default 7First create a file named App.module.css
then write your pure css here
.container {
background-color: rgb(44, 0, 95);
width: 100%;
height: 100%;
}
then,
import the file in your js file
import style from './App.module.css';
Now you can this style like normal react native styling
<View style={style.container}>
What do you mean pure css ?
Have a look at styled-components, the project is in active development.
This allow you to style your react components using css.
I had the same issue once and I solved it using this component. I see is no longer under development however for me it was perfectly working.
What it does basically is taking your CSS files and it will generate from them some StyleSheet components that you can easily integrate in your react application.
Try this library: https://atom.io/packages/atom-react-native-css
You can style components with CSS and built in support for SASS.
<Text style={{backgroundColor:'#FFF',zIndex: 5}}></Text>