html - 图像高度和宽度的CSS问题

标签 html css reactjs

我在 jsx/html 页面上的图像是 div:

 <div className="card-row-image" style={getBackgroundImage(thumbnail)} />

问题出在 css 类 heightwidth68px 但是当我打开应用程序时,页面宽度低于 68px

您可以查看屏幕截图: ss

Css部分代码:

.card-row-image {
  height: 68px;
  width: 68px;
  border-radius: 4px;
  margin-right: 10px;
  background-size: cover;
  background-position: center center;
}

为什么图片的宽度不是 68px?

最佳答案

getBackgroundImage(thumbnail) 中提供的内联样式比链接到该类的 CSS 规则具有更高的优先级。您有几个选择:

  1. 更改 getBackgroundImage 以允许指定其他大小(不是“thumb”)

  2. 应用内联样式,但移除其中的宽度和高度:

const { width, height, ...styleWithoutSize } = getBackgroundImage(thumbnail)
<div className="card-row-image" style={styleWithoutSize} />
  1. 使用 !important 更改优先级顺序>
.card-row-image {
  height: 68px !important;
  width: 68px !important;
  border-radius: 4px;
  margin-right: 10px;
  background-size: cover;
  background-position: center center;
}

关于html - 图像高度和宽度的CSS问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57029589/

相关文章:

html - Divs 中的 Div 滚动不会滚动

javascript - React 用户 session 一小时后自动注销

javascript - 任何对键控对象的使用都应该包装在 React.addons.createFragment(object) 中

javascript - 在每个 dom 更改和操作上运行脚本

javascript - 删除包装 div

html - rails : How to apply background-color to body

javascript - Jquery Sliding Div 只工作一次

javascript - react 原生 + react 原生路由器通量 : How to apply hideNavBar to only one <Scene/>?

php - JQuery 隐藏/可见错误

javascript - 单击输入元素时如何获取表单子(monad)级的文本