首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用CSS用文本亮亮图像

使用CSS用文本亮亮图像
EN

Stack Overflow用户
提问于 2017-02-27 21:52:09
回答 2查看 2K关注 0票数 1

我们使用这个css

代码语言:javascript
复制
.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:

代码语言:javascript
复制
<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>

你会看到一张图片上有文字的图片。鼠标超过效果工作,直到鼠标指针击中文本,然后鼠标超过效果停止。这个问题有解决办法吗?

代码语言:javascript
复制
.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;
}
代码语言:javascript
复制
<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>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-02-27 22:06:06

好的。将pointer-events: none;添加到.text-picture CSS中。

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

代码语言:javascript
复制
.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;
}
代码语言:javascript
复制
<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>

票数 2
EN

Stack Overflow用户

发布于 2017-02-27 22:10:22

将指针事件无添加到文本图片类中。

代码语言:javascript
复制
.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;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42496442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档