此时,图像在黑色文本容器上zoom .我该如何防止这种情况?我只希望图像在自己的容器中放大,而不是覆盖黑色div容器.

这是一个JSFiddle和我的代码:

.cms-section-default.boxed [class*="cms-element"] {
  border-radius: 3px;
}

.body-selection-item {
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0.8em 0.5em 0.2em 0.5em;
  text-align: center;
  -ms-flex-positive: 1;
  flex-grow: 1;
  background-color: white;
  border: 1px solid #b2b2b2;
}

.body-selection-item-image:hover {
  -ms-transform: scale(1.05);
  -webkit-transform: scale(1.05);
  transform: scale(1.05);
}

.body-selection-item-image {
  overflow: hidden;
  transition: -ms-transform .5s ease;
  transition: -webkit-transform .5s ease;
  transition: transform .5s ease;
  -webkit-transition: -webkit-transform .5s ease;
}

.body-selection-item-image {
  height: 15rem;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
  width: 100%;
}

.body-selection-item-text {
  font-size: 1rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  padding: 0.5em;
  background: #1f1f1f;
  color: #fff;
}
<div class="cms-element-text">
  <div class="body-selection-item">
    <a title="Ttile" href="#">
      <div style="background-image:url(https://images.unsplash.com/photo-1657053543559-5845ec792c0e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3351&q=80);" class="body-selection-item-image"></div>
      <div class="body-selection-item-text">MY TEXT-BOX</div>
    </a>
  </div>
</div>

推荐答案

这种众所周知的动画通常是通过在元素内用overflow: hiddenzoom img来完成的.因为overflow:hidden代表元素的含量,并不阻止他变大.试试这个:

.cms-section-default.boxed [class*="cms-element"] {
  border-radius: 3px;
}
.body-selection-item {
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0.8em 0.5em 0.2em 0.5em;
  text-align: center;
  flex-grow: 1;
  background-color: white;
  border: 1px solid #b2b2b2;
}

.body-selection-item-image {
  overflow: hidden;
  height: 15rem;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
  width: 100%;
}

.body-selection-item-image:hover img {
  transform: scale(1.05);
}

.body-selection-item-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}
.body-selection-item-text {
  font-size: 1rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  padding: 0.5em;
  background: #1f1f1f;
  color: #fff;
}
<div class="cms-element-text">
  <div class="body-selection-item">
    <a title="Deckenleuchten" href="/Leuchten/Deckenleuchten/">
      <div class="body-selection-item-image">
        <img src="https://images.unsplash.com/photo-1657053543559-5845ec792c0e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3351&q=80" />
      </div>
      <div class="body-selection-item-text">MY TEXT-BOX</div>
    </a>
  </div>
</div>

Html相关问答推荐

如何防止下拉菜单内的Bootstrap列表行包装?

如何在angular 17.2中使用routerLink解决此错误

如何使用html和css将两个项目垂直对齐

损坏的可点击html邮箱签名

R-markdown中的非顺序列表

带有MathJax SVG的HTML代码在XHTML中不起作用

现代网络浏览器可以并行下载哪些类型的网络资源?还有,什么东西不能并行下载?

将精选选项的价格合并为一个价格HTML、PHP和JQuery

十进制数字不适用于格网项目的格网布局线放置中使用的SPAN关键字

HTML中的ARIA标签:在元素内部还是外部?(&Q;

`table>;的消失;tbody:nth子级(1)`HTML

即使必填字段为空,HTML 表单也已成功提交

这两个CSS中的网格居中对齐内部盒子有什么区别?

如何正确地嵌套Flexbox

pull-right 不适用于 bootstrap alert 内的按钮

标签背景 colored颜色 的 html 和 css 技巧说明

单击时 HTML 锚元素不重定向到相对路径

防止 HTML 表格在 Quarto 中使用全页宽度

文本输入在 Chrome 中保持水平滚动,带有文本溢出:省略号

将固定/绝对伪元素放置在相对 div(具有滚动条)内,始终位于底部