markdown 07 - 样式组件简介
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 07 - 样式组件简介相关的知识,希望对你有一定的参考价值。
# Introduction to Styling Components
- general notes
## Code Example - Adding Styling with Stylesheets
- by default no file is automatically included into the code that is created by the build workflow
- styling files need to be imported
### Component
```
import React from 'react';
// IMPORTING STYLES
import './Person.css';
const person = (props) => {
return (
// ADD CLASSNAME
<div className="Person">
<p>Hi! Im {props.name} and Im {props.age} years old</p>
</div>
);
}
export default App;
```
### CSS File
```
.Person {
width: 60%;
margin: 16px auto;
border: 1px solid #eee;
box-shadow: 0 2px 3px #ccc;
padding: 16px;
text-align: center;
}
```
## Code Example - Working with Inline Styles
- styling elements without an external stylesheet
```
import React, {Component} from 'react';
class App extends Component {
state = { ... }
render() {
// ADDING NEW STYLE OBJECT TO RENDER METHOD
const btnStyles = {
backgroundColor: 'white',
font: 'inherit',
border: '1px solid blue',
padding: '8px',
cursor: 'pointer'
}
return(
<div>
// ADDING STYLE PROPERTY
<button style={btnStyles}>Switch Names</button>
...
</div>
)
}
}
export default App;
```
以上是关于markdown 07 - 样式组件简介的主要内容,如果未能解决你的问题,请参考以下文章
markdown 样式组件更好的调试
markdown 组件 - 简介
markdown解析与着色
JavaScript课程——Day24(bootstrap简介全局的css样式组件)
ReactNative简介开发环境调试常用组件useState状态FlatList组件SectionList组件Platform 模块定义样式图片组件触摸事件打包apk发布版
MaHua简介