CSS img 插入到 :hover:after breaks if two lines

标签 css wordpress

我的目标是在用户将鼠标悬停在 h3 上时在其右侧显示图像。如果 h3 是一行,我的代码就可以工作,但如果 h3 变成两行或更多行,它就会中断,因为图像显示仍然紧跟在文本之后而不是在整个 block 之后显示。

Working Correctly

Failing

我正在开发 WordPress 模板。

我将绝对定位添加到 a:hover:after 否则图像的插入会移动整个 h3 元素。

<div class="col-sm-10 offset-sm-1">
    <div class="blog-entry">
    <?php   
    the_title( '<h3 class="blog-entry-title">🥑 <a href="' . esc_url( 
        get_permalink() ) . '" rel="bookmark">', '</a></h3>' ); 
    ?>
    </div>
</div>

这是我的 CSS

.blog-entry-title {
    min-height: 75px;
}

.blog-entry-title a {
    color: #232323;
    padding: 15px 90px 15px 15px;   
}

.blog-entry-title a:hover {
    color: #66ccff;
}

.blog-entry-title a:hover:after {
    content:url('https://example/color-burst.png');
    position: absolute;
    top: -10px;
}

最佳答案

尝试使用 background-image 而不是 content:url。您可以调整 background-position 而不是移动生成的 img 元素的顶部。

我也在使用 position:absolute,但只是为了设置 widthheight,所以元素停留在行。

.wrapper {
  width: 250px;
}

.blog-entry-title {
    min-height: 75px;
}

.blog-entry-title a {
    color: #232323;
    padding: 15px 90px 15px 15px;

}

.blog-entry-title a:hover {
    color: #66ccff;
}

.blog-entry-title a:hover:after {
  content: '';
  background: url("https://upload.wikimedia.org/wikipedia/commons/f/fe/Farm-Fresh_bullet_error.png");
  background-repeat: no-repeat;
  background-position: 50% 40%;
  position: absolute;
  width: 16px;
  height: 16px;
}
<div class="wrapper">
<div class="blog-entry">
  <h3 class="blog-entry-title"><a href="#">Hello world</a></h3>
</div>
<div class="blog-entry">
  <h3 class="blog-entry-title"><a href="#">The Best Guacamole Recipe in the World</a></h3>
</div>
<div class="blog-entry">
  <h3 class="blog-entry-title"><a href="#">Goodbye world</a></h3>
</div>
</div>
</div>

关于CSS img 插入到 :hover:after breaks if two lines,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49960326/

相关文章:

wordpress - 在 cakephp 3.0 中重写 cakephp 路径

javascript - JS 图像 slider /旋转木马显示 5 个元素而不是 1 个

html - 如何使 flex 响应

javascript - WordPress的。添加样式/类以禁用管理菜单中的按钮(不活动)

javascript - 通过获取当前 URL 替换 href 值

php - Wordpress 事件 Orderby Meta 生效日期

php - CSS.php 的链接?

html - 如何让我的内容可以滚动,同时保持我的页眉和页脚在同一个地方

wordpress - 注销 Wordpress 并重定向到不同的 URL

javascript - 如何在 WordPress 中使用 javascript/jquery 调整图像大小?