最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I use CSS in ReactNative - Stack Overflow

programmeradmin2浏览0评论

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
Add a comment  | 

5 Answers 5

Reset to default 7

First 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>
发布评论

评论列表(0)

  1. 暂无评论