【发布时间】:2020-02-07 10:03:49
【问题描述】:
所以我在制作商店,我想为图像设置样式。 现在我在 div 中看不到面孔:
我知道这是小事,但我做不到:
菜单项组件:
从“反应”导入反应; 导入“./menu-item.styles.scss”;
const MenuItem = ({ title, imageUrl, size }) => (
<div className={`${size} menu-item`}>
<div
className="img"
style={{
backgroundImage: `url(${imageUrl})`
}}
/>
<div className="content">
<h1 className="title">{title}</h1>
</div>
</div>
);
export default MenuItem;
菜单项样式:
.menu-item {
min-width: 30%;
height: 240px;
flex: 1 1 auto;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid black;
margin: 0 7.5px 10px;
border-radius: 10px;
.img {
width: 100%;
height: 100%;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
position: relative;
right: 0px;
border-radius: 10px;
}
&:hover {
.title {
transition: ease-in 0.6s;
opacity: 1;
cursor: pointer;
}
}
&.small-sneakers {
background-position: center;
}
&.large {
height: 420px;
}
&:first-child {
margin-right: 7.5px;
}
&:last-child {
margin-left: 7.5px;
}
.content {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
}
.title {
font-weight: bold;
margin-bottom: 6px;
font-size: 22px;
color: white;
text-transform: uppercase;
align-items: center;
opacity: 0;
z-index: 3;
position: absolute;
}
}
当我尝试做背景位置:顶部 -50px 中心时,图像没有响应:/
感谢您的帮助!
【问题讨论】:
-
你想在哪里做背景位置:顶部 -50px 中心; ?
-
我想看看照片中的面孔,因为我觉得现在看起来不太好。