【问题标题】:Brighten image with text using CSS使用 CSS 使图像变亮
【发布时间】:2017-07-18 16:44:22
【问题描述】:

我们使用这个 css

.event_box > a img{
  width: 100%;
  filter: brightness(70%);
  display: block;
  -webkit-transition: all 0.7s linear;
  -moz-transition: all 0.7s linear;
  -ms-transition: all 0.7s linear;
  -o-transition: all 0.7s linear;
  transition: all 0.7s linear;
}
 .event_box >a:hover img:hover{ 
  filter:brightness(100%)
}

.event_box .text-picture
{
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  color: #fff;
  height: 0;
  text-align: center;
  font-family: Open Sans Semibold;
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  text-transform: uppercase;
  z-index: 999;
}

结合这个html:

<div class="row">
                    <div class="event_box">
                    <a href="'.$templink.$langlink.$paginalink.'portfolio'.$caselink.'1000-wishes">
                    <img src="'.$url.'images/home/1000-wishes.jpg" alt="1000 Wishes"/>
                        <div class="text-picture">
                        1000 Wishes
                        </div>
                    </a>
                    </div>
                </div>

您将看到一张带有文字的图片。 鼠标悬停效果一直有效,直到您的鼠标指针碰到文本,然后鼠标悬停效果停止。 这个问题有解决办法吗?

.event_box > a img{
  width: 100%;
  filter: brightness(70%);
  display: block;
  -webkit-transition: all 0.7s linear;
  -moz-transition: all 0.7s linear;
  -ms-transition: all 0.7s linear;
  -o-transition: all 0.7s linear;
  transition: all 0.7s linear;
}
 .event_box >a:hover img:hover{ 
  filter:brightness(100%)
}

.event_box .text-picture
{
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  color: #fff;
  height: 0;
  text-align: center;
  font-family: Open Sans Semibold;
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  text-transform: uppercase;
  z-index: 999;
}
<div class="row">
                    <div class="event_box">
                    <a href="http://www.jcsl.nl/clean/images/home/1000-wishes.jpg">
                    <img src="http://www.jcsl.nl/clean/images/home/1000-wishes.jpg" alt="1000 Wishes">
                        <div class="text-picture">
                        1000 Wishes
                        </div>
                    </a>
                    </div>
                </div>

【问题讨论】:

  • 有没有机会用代码 sn-p 更新问题?
  • 我从来没有这样做过,我希望它能像这样正常工作。

标签: html css image mouseover


【解决方案1】:

当然。将pointer-events: none; 添加到.text-picture CSS。

这样做是让鼠标事件(如悬停、点击等)通过元素。这样做,图像的“悬停”状态不会被打断,因此它会保持明亮。

.event_box > a img{
  width: 100%;
  filter: brightness(70%);
  display: block;
  -webkit-transition: all 0.7s linear;
  -moz-transition: all 0.7s linear;
  -ms-transition: all 0.7s linear;
  -o-transition: all 0.7s linear;
  transition: all 0.7s linear;
}
 .event_box >a:hover img:hover{ 
  filter:brightness(100%)
}

.event_box .text-picture
{
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  color: #fff;
  height: 0;
  text-align: center;
  font-family: Open Sans Semibold;
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  text-transform: uppercase;
  z-index: 999;
  pointer-events: none;
}
<div class="row">
                    <div class="event_box">
                    <a href="http://www.jcsl.nl/clean/images/home/1000-wishes.jpg">
                    <img src="http://www.jcsl.nl/clean/images/home/1000-wishes.jpg" alt="1000 Wishes">
                        <div class="text-picture">
                        1000 Wishes
                        </div>
                    </a>
                    </div>
                </div>

【讨论】:

  • 非常感谢,我从未见过这个选项。甚至 Notepad++ 也无法解决这个问题。
  • 没问题。 pointer-events 最常与 SVG 图像一起使用,但将其设置为 none 将适用于所有元素类型。它有点新,但在所有现代浏览器以及 IE11+ 中都可以识别。如果您正在寻找适用于 IE11 之前的解决方案,我可以查看可用的解决方案。
【解决方案2】:

将指针事件 none 添加到 text-picture 类

.event_box .text-picture
{
  //this line
  pointer-events:none;
  ----

  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  color: #fff;
  height: 0;
  text-align: center;
  font-family: Open Sans Semibold;
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  text-transform: uppercase;
  z-index: 0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-25
    • 2010-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多