对象拟合不起作用,我不知道为什么。它仅适用于图像标签中的内联样式。任何人都可以解释一下吗?也许 hero_media 容器会影响对象匹配?我还尝试使用伪元素( after 和 before )向图像添加文本。只需要修改 hero_media 容器
this is my code
import React from "react";
import Navbar from "../navbar/Navbar";
import Footer from "../footer/Footer";
import donation from "./donation.css";
const Donation = () => {
return (
<div>
<div className="content_wrap">
<Navbar />
<div className="hero_media">
<img
//style={{ objectFit: "fill", width='100%', height:'100%' }}// this is work
src={process.env.PUBLIC_URL + "/assets/donation.jpg"}
alt="donation image"
className="image"
/>
</div>
</div>
<Footer />
</div>
);
};
export default Donation;
Css file
content_wrap {
padding-bottom: 300px;
height: 100%;
}
.hero_media {
padding-top: 2px;
max-width: 100%;
margin: 0 auto;
position: relative;
height: 500px;
box-shadow: rgb(20, 20, 20) 0 0 10px;
}
/*------------------IMAGE-------------*/
.image {
max-width: 100%;
max-height: 100%;
object-fit: fill;//this is not working???
}