jquery - 如何在响应式图像上使悬停状态背景为 100% 宽度

标签 jquery css

我已经创建了一些响应式图像,但想要显示用户名的悬停状态。

我已经设法使用 Css 和 Jquery 创建悬停状态,但不幸的是,当我更改屏幕宽度时,悬停背景不会保持 100%。

谁能解释实现 100% 宽度背景的最佳方法?我的背景图像上有填充,所以我无法使黑色背景与图像齐平。

这是一个 fiddle 来解释我的意思。

我希望这是有道理的。

http://jsfiddle.net/isherwood/x59tB/15/

.show-username{
    position: absolute;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    font-weight: bold;
    bottom: 0px;
    padding: 5px;
    font-size: 11px;
    width: inherit;
    display: none;
}

最佳答案

你有两个问题:

此 css 规则的宽度样式导致拉伸(stretch)问题。它总是会覆盖您现有的样式,因为 id 的优先级高于类选择器:

#upload-container ul li span {
    font-size: 16px;
    line-height: 22px;
    display: block;
    width: 82%; // <---- Move this style
    position: absolute;
    bottom: 13px;
 }

第二次为您的 .show-username css 规则添加左右声明:

.show-username{
    position: absolute;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    font-weight: bold;
    bottom: 0px;
    padding: 5px;
    font-size: 11px;
    width: inherit;
    display: none;
    right: 10px;
    left: 10px;
}

关于jquery - 如何在响应式图像上使悬停状态背景为 100% 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19842404/

相关文章:

jquery - 为什么要将 $ 与 $self 和 $body 放在一起?并且 self 与 $self 相同

html - 如何响应地用 div 填充水平空间

html - 图像不居中 Bootstrap center-block

javascript - CSS:无法在 li 中水平对齐元素?

css - Sublime Text Less2Css 禁用自动计算

jquery - 屏幕阅读器可以是 DIV 元素中的 "locked"吗?

javascript - 寻找等同于以下 jQuery 解决方案的 javascript 解决方案

javascript - 如何使用 jquery 将列表元素动态对齐到其邻居的高度

javascript - 第一次在两秒内执行 window.setInterval ,然后每 10 秒调用一次

javascript - 创建可以覆盖图像的倒圆 Angular 箭头