我在div的jsx / html页面上有图片:
<div className="card-row-image" style={getBackgroundImage(thumbnail)} />
问题是CSS类height
中的问题,而width
是68px
,但是当我打开应用程序时,页面宽度小于68px
Css部分代码:
.card-row-image {
height: 68px;
width: 68px;
border-radius: 4px;
margin-right: 10px;
background-size: cover;
background-position: center center;
}
为什么with的图片不是68px?
答案 0 :(得分:2)
getBackgroundImage(thumbnail)
中提供的内联样式的优先级高于链接到该类的CSS规则。您有两种选择:
更改getBackgroundImage
以允许指定其他大小(不是'thumb')
应用内联样式,但从其中删除宽度和高度:
const { width, height, ...styleWithoutSize } = getBackgroundImage(thumbnail)
<div className="card-row-image" style={styleWithoutSize} />
!important
.card-row-image {
height: 68px !important;
width: 68px !important;
border-radius: 4px;
margin-right: 10px;
background-size: cover;
background-position: center center;
}