简体   繁体   English

如何调整图像大小并保留在悬停时更改图像的能力

[英]How do I have images resize and retain the ability to have them change on hover

I have this issue.. I want to be able to use我有这个问题..我希望能够使用

.custom-forums {
    height: auto;
    width: 100%;
    border-image-source:transparent url("../images/forums.png") center top no-
    repeat;
}

with

.custom-forums:hover {
   background-image: url('../images/forums-hover.png');
}

The issue is this: When width is set to 100% it simply does not show the image.问题是:当width设置为100%它根本不显示图像。 But when width and height are set to 170px it does work.但是当widthheight设置为170px它确实有效。 I would like to have the button resize based on screen resolution and retain the ability to have the hover image change.我希望根据屏幕分辨率调整按钮大小并保留更改悬停图像的能力。

Much gratitude, Mas21非常感谢, Mas21

Background images require a predefined height or content of a certain height in its container in order to work.背景图像需要在其容器中具有预定义的高度或特定高度的内容才能工作。

I had a thought you could do this another way:我有一个想法,你可以用另一种方式做到这一点:

  • Use a background image使用背景图片
  • Put another image in that div and on hover set it to opacity 0, or your preference and the bg image shows将另一个图像放在该 div 中,然后悬停将其设置为不透明度 0,或者您的偏好和 bg 图像显示

Run this example:运行这个例子:

 .container { background: url('http://placehold.it/199x199') no-repeat center center; width: 200px; } img { transition: opacity ease-in-out .5s; } img:hover { opacity: .25; }
 <div class="container"> <img src="http://placehold.it/200x200"> </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何用图像替换表单按钮,并在悬停时更改图像? 还精灵与单独的图像? - How do I replace a form button with an image, and have the image change on hover? Also sprites vs separate images? 我是否需要DOM中的图像才能使用画布合并它们? - Do I need to have images in DOM to merge them using canvas? 我如何 hover 更改汉堡菜单颜色,单击汉堡菜单将其转换为 x 并显示内容下拉菜单? - How do I hover to change the hamburger menu colour, click the hamburger menu to transform it to x and have the contents dropdown? 我有一个脚本来调整图像大小。 无论如何让它输出5张图像? - I have a script to resize an image. Is there anyway to have it output 5 images? 如何将文本悬停在自定义形状上? - How do I have text hover over a custom shape? 我有一堆不同大小的图像。 如何在保持比例的同时重新调整尺寸? - I have a bunch of images with varying sizes. How do I re-size them while maintaining proportions? 我该如何更改我的代码? - How do I have to change my codes? 如何仅列出数组中包含“3”的数字? - How do I list only the numbers that have '3' in them from an array? 我如何在鼠标悬停时有一条线跟随鼠标,但又有放大图表? - how do I have a line follow the mouse on hover, but also have zoom in chart? 如何在 Phaser 3 中正确调整图像大小以保持质量 - How to correctly resize images to retain quality in Phaser 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM