html - 悬停时阻止表格元素移动位置?

标签 html css html-table css-transitions

所以我有一个有两行的表。再多一张图片,一张用于下面的段落。这些图像链接到不同的网页,并且我有一个动画,其中边框增长并改变颜色,但我不希望图像在悬停时移动位置。有什么办法可以阻止图像这样做吗?

.project-table img {
  border: 6px solid white;
  width: 300px;
  transition: all 0.5s ease;
}

.project-table img:hover {
  border: 12px solid #FF1D58;
}

td {
  padding: 0px 180px 0 0;
  width: 110px;
  text-align: center;
}
<table class="project-table">
  <tr>
    <td>
      <a href="https://thebenlusted.github.io/jsauthentication/" target="_blank" title="JavaScript Authenticator"><img src="images/js-auth-screenshot.png"></a>
    </td>
    <td>
      <a href="https://google.ca" target="_blank" title="FrickIt Studios Website"><img src="images/sigma-site-screenshot.png"></a>
    </td>
  </tr>
  <tr>
    <td>
      <p>Hello? This is a paragraph. I am trying to see what the width and height is on this element. If we keep the paragraphs at the same length then we won't have this lame height difference.
      </p>
    </td>
    <td>
      <p>Hello? This is a paragraph. I am trying to see what the width and height is on this element. If we keep the paragraphs at the same length then we won't have this lame height difference.
      </p>
    </td>
  </tr>
</table>

最佳答案

发生这种情况是因为您增加了边框宽度,但是您也可以通过使用css属性box-shadow来实现相同的效果。

.project-table img {
  border: 6px solid white;
  width: 300px;
  transition: all 0.5s ease;
}

.project-table img:hover {
  border-color: #FF1D58;
  box-shadow: 0 0 0 6px rgba(255, 29, 88, 1);
}

td {
  padding: 0px 180px 0 0;
  width: 110px;
  text-align: center;
}
<table class="project-table">
            <tr>
              <td><a href="https://thebenlusted.github.io/jsauthentication/" target="_blank" title="JavaScript Authenticator"><img src="images/js-auth-screenshot.png"></a></td>
              <td><a href="https://google.ca" target="_blank" title="FrickIt Studios Website"><img src="images/sigma-site-screenshot.png"></a></td>
            </tr>
            <tr>
              <td><p>Hello? This is a paragraph. I am trying to see what the width and height is
                on this element. If we keep the paragraphs at the same length then we won't have this
                lame height difference.
              </p></td>
              <td>
                <p>Hello? This is a paragraph. I am trying to see what the width and height is
                  on this element. If we keep the paragraphs at the same length then we won't have this
                  lame height difference.
                </p>
              </td>
            </tr>
          </table>

关于html - 悬停时阻止表格元素移动位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59834832/

相关文章:

html - 我怎样才能使表格单元格表现得像 UL LI?

html - 如何选择 DOM 元素的动态跟随 DOM 元素? (CSS 选择器)

html - 相对于图像定位元素

javascript - 扩展 div 的高度以从初始位置到达容器底部

css - 使用带有类名的媒体查询来更改网站宽度

html - 将原点移动到元素的中心?

javascript - jQuery 在使用 rowspan 时选择列中的最后一个单元格

javascript - 水平滚动表格列

javascript - Protractor - 如何通过自定义(非 HTML)属性定位元素?

javascript - 使用 Handsontable 时重复标题