首页 > 解决方案 > 如何在不使用 styleSheet 原生元素的情况下将 CSS 文件添加到 react-native 应用程序中

问题描述

我需要将纯CSS文件添加到 react-native android 和 ios 应用程序中。如何在不使用 styleSheet 原生元素的情况下克服这个问题?

body {
   margin: 25px;
   background-color: rgb(240,240,240);
   font-family: arial, sans-serif;
   font-size: 14px;
}

h1 {
  font-size: 35px;
  font-weight: normal;
  margin-top: 5px;
} 

标签: cssreact-native

解决方案


使用styled-components.

然后,您可以使用 css 对组件样式进行编码。

const Body = styled.body`
   margin: 25px;
   background-color: rgb(240,240,240);
   font-family: arial, sans-serif;
   font-size: 14px;
`;

const Header = styled.h1`
  font-size: 35px;
  font-weight: normal;
  margin-top: 5px;
`;

推荐阅读