【问题标题】:Colour overlay on hover悬停时的颜色叠加
【发布时间】:2015-09-09 02:02:23
【问题描述】:

我在博客上玩自己开发的主题。我有一个图像网格,可以点击进入特定类别。

我在尝试在图像上创建悬停效果时遇到问题。我想可能是因为我使用链接的方式(绝对定位它,并将其设置为 100% 高度)。

如何使用此设置进行以下操作:

  1. 在悬停时添加颜色覆盖(简单的 a.entry-link:hover 不起作用)
  2. 在悬停时为图像添加缩放效果

任何帮助将不胜感激。

提前致谢。

<div class="post-list">

    <div id="articles">
        ::before
        <article>
            <div class="entry-thumbnail">
                <img src="http://localhost:8888/defylife/assets/images/posts/piste_temp.jpg"></img>
            </div>
            <!--

             entry header 

            -->
            <div class="entry-header">
                <h2>

                    Morocco 2015

                </h2>
            </div>
            <a class="entry-link" title="View all posts in " href="http://localhost:8888/defylife/category/adventures/morocco/"></a>
        </article>
        <article>
            <div class="entry-thumbnail">
                <img src="http://localhost:8888/defylife/assets/images/posts/gpz_romania_thumb.jpg"></img>
            </div>
            <!--

             entry header 

            -->
            <div class="entry-header">
                <h2>

                    Norwich - Mamaia

                </h2>
            </div>
            <a class="entry-link" title="View all posts in " href="http://localhost:8888/defylife/category/adventures/norwich-mamaia/"></a>
        </article>
        <article>
            <div class="entry-thumbnail">
                <img src="http://localhost:8888/defylife/assets/images/posts/P6070238.jpg"></img>
            </div>
            <!--

             entry header 

            -->
            <div class="entry-header">
                <h2>

                    Norwich - Split

                </h2>
            </div>
            <a class="entry-link" title="View all posts in " href="http://localhost:8888/defylife/category/adventures/norwich-split/"></a>
        </article>
        <article>
            <div class="entry-thumbnail"></div>
            <!--

             entry header 

            -->
            <div class="entry-header"></div>
            <a class="entry-link" title="View all posts in " href="http://localhost:8888/defylife/category/adventures/spain/"></a>
        </article>    
    </div>

还有 CSS:

body.category .post-list #articles {
    width: 100%;
    padding: 0px;
    display: table;
    margin: 0px;
}

body.category .post-list #articles article .entry-thumbnail {
    display: block;
    width: 100%;
    max-height: 431px;
    overflow: hidden;
    margin: auto;
}

body.category .post-list #articles article .entry-thumbnail img {
    width: 100%;
}

body.category .post-list #articles article {
    display: inline;
    width: 33.3333%;
    margin: -6px 0px 0px; /* this is due to a small gap between rows */
    position: relative;
    float: left;
    text-align: center;
}

body.category .post-list #articles article .entry-header {
    z-index: 100;
    position: absolute;
    color: #FFF;
    font-size: 24px;
    font-weight: bold;
    left: 0px;
    right: 0px;
    bottom: 5px; /* this is because for some reason there are gaps between rows */
    background: rgba(0, 0, 0, 0.25) none repeat scroll 0px 0px;
    padding: 15px;
}

body.category .post-list #articles article .entry-header h2 {
    font-size: 0.85em;
    text-transform: uppercase;
}

body.category .post-list #articles article .entry-link {
    display: block;
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    border-bottom: 0px none;
    height: 100%;
    z-index: 100;
    opacity: 0;
}

【问题讨论】:

  • 你为什么不提供任何代码,即标记。你提到'a.entry-link',但你没有提供任何东西。我们是否必须检查您发布的页面。
  • 一个简单的 a.entry-link:hover 不起作用,因为存在不透明度:0
  • 对不起。认为如果人们可以检查页面上的输出会更有意义。我现在已经添加了代码。谢谢

标签: css hover overlay css-transforms


【解决方案1】:
  1. 您的 &lt;a&gt; 标签不包含您要更改的任何元素,因此悬停不会影响它们(&lt;img&gt;&lt;h2&gt; 中的文本都存在于父 @987654324 @标签——你可能想把:hover放在文章标签上,并改变内部元素(即article:hover div.entry-header { background: rgba(0,0,0,0.5); }

  2. 至于缩放 - 与1相同,您可以通过父元素的悬停来更改宽度/高度。不要忘记,如果您想获得“缩放”效果,您可能还需要更改位置(左侧和顶部)。

下次请在此处提供代码,而不是作为链接。它会更容易提供帮助,并且将来也会提供。

【讨论】:

  • 我已经添加了浏览器看到的代码(否则它是 php 和更少)。添加 article:hover 然后选择一个元素,如 div.entry-header 或 div.entry-thumbnail 似乎没有做任何事情。 a.entry-link 上的绝对定位和 100% 是否导致无法将鼠标悬停在文章上?
  • 我在您的代码中看不到任何 :hover ,因此在此处提供帮助有点困难。请使用 jsfiddle.net 提供代码示例(使用完整的 html/css 工作版本,以便我们提供帮助)。
  • 啊不,我想我明白了。干杯。
猜你喜欢
  • 1970-01-01
  • 2014-02-20
  • 1970-01-01
  • 2011-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-19
  • 1970-01-01
相关资源
最近更新 更多