使用 CSS 使带文字的图片变亮

Brighten image with text using CSS

我们使用这个 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>

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

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

.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>

将指针事件none添加到文本图片class

.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;
}