// React CSS 示例代码
// 1. 使用内联样式
const styles = {
color: 'blue',
fontSize: '24px'
};
function InlineStyleExample() {
return (
<div>
<h1 style={styles}>这是使用内联样式的标题</h1>
</div>
);
}
// 2. 使用类名 (CSS Modules)
import styles from './App.module.css';
function CssModuleExample() {
return (
<div className={styles.container}>
<h1 className={styles.title}>这是使用 CSS Modules 的标题</h1>
</div>
);
}
// 3. 使用 styled-components
import styled from 'styled-components';
const Title = styled.h1`
color: green;
font-size: 28px;
`;
function StyledComponentExample() {
return (
<div>
<Title>这是使用 styled-components 的标题</Title>
</div>
);
}
style
属性上。这种方式适合简单的样式,但不适合复杂的样式管理。如果你需要更多关于 React 和 CSS 的内容,请告诉我!
上一篇:css禁止选中
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站