我正在使用ReactJS create-react-app来构建网站。我想在我的主页上使用css将图片水平居中,但它仍然保持左对齐。
我已经通过类声明将.jpg文件导入到.js文件中,并显示在页面上,但它没有遵循我在index.css文件中进行的类修改。
//在Cur.js文件中
import React from 'react';
import Image from 'react-image-resizer';
import cur from './cur.jpg';
function Cur() {
return (
<div>
<Image
img src={cur} alt="cur" class="center"
height={350}
width={700}
/>
</div>
);
}
export default Cur;
//在 index.css 文件中
.center{
text-align: center;
display: block;
justify-content: center;
align-items: center;
margin: auto;
width: 100%;
}
flex
。 - nrion