[英]Ant design carousel shows “weird” blue spaces
I started yesterday with Ant Design in a Gatsby project.我昨天从 Gatsby 项目中的 Ant Design 开始。 I want to make a carousel and tried using the Ant Design component for this.
我想制作一个旋转木马并尝试为此使用 Ant 设计组件。 Ant Design Carousel .
Ant 设计旋转木马。 This shows this result:
这显示了这个结果:
The blue things are the carousel, but instead the 4 I have in my code, I have 9 blue spaces on screen.蓝色的东西是旋转木马,但我的代码中有 4 个,屏幕上有 9 个蓝色空间。 I don't understand where these come from.
我不明白这些是从哪里来的。
When I click the buttons 2/3/4 below, all blue spaces disappear.当我单击下面的按钮 2/3/4 时,所有蓝色空间都消失了。 When I click on button 1 they all reappear.
当我单击按钮 1 时,它们都会重新出现。
My imports and code:我的进口和代码:
import * as React from "react";
import { Row, Col, Image, Table, Carousel } from 'antd';
<Carousel afterChange={onChange}>
<div>
<h3 style={contentStyle}>1</h3>
</div>
<div>
<h3 style={contentStyle}>2</h3>
</div>
<div>
<h3 style={contentStyle}>3</h3>
</div>
<div>
<h3 style={contentStyle}>4</h3>
</div>
</Carousel>
function onChange(a, b, c) {
console.log(a, b, c);
}
const contentStyle = {
height: '160px',
color: '#fff',
lineHeight: '160px',
textAlign: 'center',
background: '#364d79',
};
All help is appreciated.感谢所有帮助。
It's because you haven't included the CSS stylesheet.这是因为您没有包含 CSS 样式表。 Make sure you add the styles using following import:
确保使用以下导入添加 styles:
import 'antd/dist/antd.css'
If you're using Gatsby.js, you can add it in your gatsby-browser.js
file.如果您使用的是 Gatsby.js,则可以将其添加到
gatsby-browser.js
文件中。 If the file doesn't exist, you can create one in your root directory (the same where your package.json
is).如果该文件不存在,您可以在根目录中创建一个(与您的
package.json
所在的位置相同)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.