我的html中有以下图和标题:

<figure id="pub_img"><img src="images/{{image.link}}" >
    <figcaption>{{image.caption}}</figcaption>
    </figure>

下面的css代码除其他外执行以下操作:

  • 确保人物和IMG符合宽度并向右浮动
  • 在图像和标题周围制作1 px的黑色边框
  • 悬停时,放大整个figure-IMG-caption struct .

我有一个无法解决的问题:

zoom 还增加了1 px黑色边框--这变得相当丑陋.我不知道如何在不增加赋予它们的边框的情况下增加数字、IMG、figtitle.

我该怎么做呢?

#pub_img:hover {
  -webkit-transform: scale(4);
  -moz-transform: scale(4);
  -o-transform: scale(4);
  transform: scale(4);
}

#pub_img {
  border: 1px solid #555;
  float: right;
  width: 80px;
  -webkit-transition: all .4s ease-in-out;
  -moz-transition: all .4s ease-in-out;
  -o-transition: all .4s ease-in-out;
  -ms-transition: all .4s ease-in-out;
}

figure {
  display: table;
  border: 1px solid red;
  width: 80px;
}

figure img {
  width: 100%;
  margin: 0px;
  padding: 0px;
  vertical-align: middle;
}

figure figcaption {
  border-top: 0.1px solid gray;
  background-color: #ffffff;
  font-size: 0.2em;
  text-align: justify;
}
<figure id="pub_img"><img src="https://picsum.photos/600/300">
  <figcaption>Lorem Ipsum</figcaption>
</figure>

推荐答案

您不能使用zoom 来实现这一目标.它类似于透明度上的opacity属性(它需要是rgba,否则它会影响整个元素).这里我们需要增加figure中的widthfigcaption中的font-size,而不是像这样zoom :

#pub_img:hover {
  width: 325.33px;
}

#pub_img:hover figcaption {
  font-size: 1.5em;
  font-weight: 600;
}

#pub_img {
  border: 1px solid #555;
  float: right;
  width: 80px;
  -webkit-transition: all .4s ease-in-out;
  -moz-transition: all .4s ease-in-out;
  -o-transition: all .4s ease-in-out;
  -ms-transition: all .4s ease-in-out;
}

figure {
  display: table;
  border: 1px solid red;
  width: 80px;
}

figure img {
  width: 100%;
  margin: 0px;
  padding: 0px;
  vertical-align: middle;
}

figure figcaption {
  border-top: 0.1px solid gray;
  background-color: #ffffff;
  font-size: 0.2em;
  text-align: justify;
}
<figure id="pub_img"><img src="https://picsum.photos/600/300">
  <figcaption>Lorem Ipsum</figcaption>
</figure>

文本zoom 延迟的替代版本:

#pub_img:hover {
  width: 325.33px;
}

#pub_img:hover figcaption {
  font-size: 1.5em;
  font-weight: 600;
}

#pub_img {
  border: 1px solid #555;
  float: right;
  width: 80px;
  -webkit-transition: all .4s ease-in-out;
  -moz-transition: all .4s ease-in-out;
  -o-transition: all .4s ease-in-out;
  -ms-transition: all .4s ease-in-out;
}

figure {
  display: table;
  border: 1px solid red;
  width: 80px;
}

figure img {
  width: 100%;
  margin: 0px;
  padding: 0px;
  vertical-align: middle;
}

figcaption > div {
  overflow: hidden;
}



figure figcaption {
  border-top: 0.1px solid gray;
  background-color: #ffffff;
  font-size: 0.2em;
  text-align: justify;

  display: grid;
  grid-template-rows: 0fr;
  transition: 250ms grid-template-rows ease;
  transition-delay: 0.1s;
}

figure:hover figcaption {
  grid-template-rows: 1fr;
}
<figure id="pub_img"><img src="https://picsum.photos/600/300">
  <figcaption><div>Lorem Ipsum</div></figcaption>
</figure>

Html相关问答推荐

在 Select 前后更改选项卡的背景

如何设置弹性盒子容器的具体大小?

浮动Div在CSS中未按预期工作

如何使VS代码支持以模仿嵌套的方式对已经包含注释的HTML进行注释?

div 中的垂直中心表格

当浏览器宽度减小时字体大小变得太大

将三个div转换为显示flex

使用 Thymeleaf 将图像水平居中

如何使用javascript在jsx中重复插入特殊字符?

Github上部署需要花费几小时时间:等待github pages部署批准

发送带有图像的Google文档作为HTML格式的邮件正文不再起作用

SVG 填充 colored颜色 不使用轮廓填充空白区域

在 CSS 中的 div 中获取文本以环绕其他文本?

具有 css 高度的输入元素:100% 溢出父 div

带有伪元素的不规则形状的渐变边框

Cargo 在网格中的排列

如何在react 中向按钮添加禁用属性?

我正在使用 react-router-dom 并创建了一个固定的导航栏,它在每个网页上不断改变大小,我不知道为什么

根据百分比用多种 colored颜色 填充SVG路径

当我希望它只横向滚动时,可滚动菜单也会上下移动