html - 如何在 Shopify 的 theme.liquid 文件中添加悬停图像

标签 html css shopify mouseover

我想知道当我将鼠标悬停在 Shopify 中的特定图像上时如何添加不同的图像。我的 theme.liquid 文件中目前有以下代码,但我不确定如何添加一些鼠标悬停代码来显示不同的图像。

<div class="site-header__phone">
                <a href="tel:123456789">{{ 'phone-icon.png' | asset_url | img_tag }} </a>
              </div>

穆斯塔法,

以下是我写的内容,因为它悬停在我添加的图标上而不是产品上,但页面显示“/> ”/> 这是不正确的..

<div class="site-header__phone">
                <a href="tel:123456789">
                  <img class="phone" src="{{ 'phone-icon.png' | asset_url | img_tag }}" /> 
                  <img class="phone_hover" src="{{ 'phone-icon-h.png' | asset_url | img_tag }}" />
                </a>
              </div>

CSS 是:

.site-header__phone {
  margin-top:6px;
  margin-left:15px;
}

.site-header__phone a img.phone_hover { display: none; }
.site-header__phone a:hover img.phone { display: none; }
.site-header__phone a:hover img.phone_hover { display: block; }

有什么地方我做错了吗?

最佳答案

试试这个,希望它对你有用。像这样给出Html部分

    <div class="image">
  <a href="{{ url }}">
     <img class="first" src="{{ product.images[0] | product_img_url: 'large' }}" alt="{{ product.title | escape  }}" />
     <img class="second" src="{{ product.images[1] | product_img_url: 'large' }}" alt="{{ product.title | escape  }}" />
   </a>
</div> 

还有像这样的 styles.css 样式表

.product .image a img.second { display: none; }
.product .image a:hover img.first { display: none; }
.product .image a:hover img.second { display: block; }

关于html - 如何在 Shopify 的 theme.liquid 文件中添加悬停图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39755508/

相关文章:

html - 使表格单元格成为 block 元素

ruby-on-rails - 在不同的 Controller 中使用 Shopify API

html - chrome 的@media print 不工作

html - 从视频库中的视频图像中删除外边框

css - flex 包装 :wrap doesn't wrap when I am changing browser's width

ruby-on-rails - Shopify如何确保其液体模板安全(避免使用XSS)?

javascript - Shopify:在 JavaScript 中获取当前登录的用户 ID

javascript - 为什么选择更改方法不起作用?

javascript - 如何在不更改同一 div 中其他元素的不透明度的情况下更改 div 的不透明度?

html - 如何仅在 CSS 中制作此箭头?