You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flex垂直对齐异常:WooCommerce商品悬停图片拉伸错位

Fix WooCommerce Hover Image Vertical Alignment & Stretching Issue

Got it, let's tackle this—your flexbox centering works perfectly for main product images, but the hover plugin you installed is overriding those styles and messing up the alignment and stretching. Here's how to fix it:

Why This Happens

The image hover plugin is likely applying its own default styles to the hover image container (like forcing a block layout instead of inheriting your flex setup) or setting fixed width/height values on the hover image itself. This breaks your carefully set vertical centering and causes the unwanted stretching you're seeing.

Step-by-Step Solution

Add this custom CSS to your site to enforce your flexbox centering rules for the hover images and keep their aspect ratio intact:

/* Force hover image container to match your main image flexbox setup */
.product .woo-image-swap__image-wrap {
    display: flex !important;
    height: 320px;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* Prevent images from spilling outside the container */
}

/* Stop hover images from stretching, preserve natural aspect ratio */
.product .woo-image-swap__image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

How to Apply This CSS

  • Head to your WordPress dashboard
  • Navigate to Appearance > Customize > Additional CSS
  • Paste the code into the provided text area
  • Click Publish to save your changes

This will override the plugin's conflicting styles, making the hover images align vertically centered exactly like your main product images—no more stretching or top-aligned weirdness.

内容的提问来源于stack exchange,提问作者Lukas Kollin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:59:42