React Semantic UI 组件无法正确呈现
React Semantic UI component not rendering properly
我使用 create-react-app
来初始化我的应用程序。然后我做了 npm install semantic-ui-react --save
安装包。
我想从 https://react.semantic-ui.com/collections/grid#grid-example-divided-number 创建这个 Grid
示例:
我创建了一个名为 Grid.js
的文件:
import React from 'react'
import { Grid } from 'semantic-ui-react'
const GridExample = () => (
<Grid columns={3} divided>
<Grid.Row>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
</Grid.Row>
<Grid.Row>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
</Grid.Row>
</Grid>
)
export default GridExample
然后在 App.js
我导入了 GridExample
:
import React, { Component } from 'react';
import GridExample from './Grid'
import logo from './logo.svg';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<GridExample />
</div>
);
}
}
export default App;
但是,当网页加载时,<p>
元素相互堆叠 - 就好像 6X1
而不是预期的 2X3
为什么 Grid
没有正确呈现?
您忘记添加 CSS 文件。
根据文档:
This is the quickest way to get started with Semantic UI React. You won't be able to use custom themes with this method.
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css"></link>
有关如何引用它的更多选项,请参阅 https://react.semantic-ui.com/usage#css
我使用 create-react-app
来初始化我的应用程序。然后我做了 npm install semantic-ui-react --save
安装包。
我想从 https://react.semantic-ui.com/collections/grid#grid-example-divided-number 创建这个 Grid
示例:
我创建了一个名为 Grid.js
的文件:
import React from 'react'
import { Grid } from 'semantic-ui-react'
const GridExample = () => (
<Grid columns={3} divided>
<Grid.Row>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
</Grid.Row>
<Grid.Row>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
<Grid.Column>
<p>Lorem Ipsum</p>
</Grid.Column>
</Grid.Row>
</Grid>
)
export default GridExample
然后在 App.js
我导入了 GridExample
:
import React, { Component } from 'react';
import GridExample from './Grid'
import logo from './logo.svg';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<GridExample />
</div>
);
}
}
export default App;
但是,当网页加载时,<p>
元素相互堆叠 - 就好像 6X1
而不是预期的 2X3
为什么 Grid
没有正确呈现?
您忘记添加 CSS 文件。
根据文档:
This is the quickest way to get started with Semantic UI React. You won't be able to use custom themes with this method.
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css"></link>
有关如何引用它的更多选项,请参阅 https://react.semantic-ui.com/usage#css