悬停事件发生在我想要的区域之外

时间:2016-01-29 16:36:19

标签: html css css3 hover

我有一个我似乎找不到的小虫子。在我的代码片段中,您可以看到无论何时将鼠标悬停在图像上,不透明和图像比例,以及图像上方都会出现一个框。这是完美的,但我的问题是,只要您将鼠标悬停在其下方的文本上,悬停效果就会发生在图像上。

我似乎无法弄清楚只有当鼠标悬停在图像上时悬停效果才会发生。

任何建议都将不胜感激。

$('.home-img-block img').addClass(function() {
  return (this.width / this.height > 1) ? 'wide' : 'tall';
});
#home-img-block-section {
  width: 100%;
  height: 900px;
}
#home-img-blocks {
  width: 100%;
  height: 750px;
}
.home-img-block {
  width: 33.33%;
  float: left;
  display: block;
  overflow: hidden;

  position: relative;
}
.home-img-container {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}
.home-img-block:hover .overlay {
  background: rgba(0, 0, 0, 0.6);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.home-img-container:after {
  content: attr(data-content);
  color: #fff;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: all 0.5s;
  border: 1px solid #fff;
  padding: 20px 25px;
  text-align: center;
}
.home-img-container:hover:after {
  opacity: 1;
}
.home-img-block img {
  display: block;
  transition: all 1s ease;
}
.home-img-block:hover img {
  transform: scale(1.25);
  background: rgba(0, 0, 0, 0.3);
  width: 33.33%;
  max-height: 100%;
  overflow: hidden;
}
.home-img-block img.wide {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  width: 100%;
}
.home-img-block img.tall {
  max-width: 100%;
  max-height: 100%;
  width: auto;
}
#home-img-block-wording-container {
  width: 100%;
  height: 300px;
}
.home-img-wording-blocks {
  width: 100%;
  height: 100%;
  text-align: center;
  display: inline-block;
  vertical-align: top;
}
.home-img-wording-block-title {
  padding-top: 30px;
  font-size: 1.7em;
}
.home-img-wording-block-description {
  padding: 25px 50px 0 50px;
  font-size: 1.1em;
  color: #5d5d5d;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="home-img-block-section">
	  <div id="home-img-blocks">
		<div class="home-img-block fadeBlock1">
		  <div data-content="FIND OUT MORE" class='home-img-container'>
			<img src="http://optimumwebdesigns.com/images/test1.jpg">
			<div class="overlay"></div>
		  </div>
		  <div class="home-img-wording-blocks">
			<div class="home-img-wording-block-title">WEB DESIGN</div>
			<div class="home-img-wording-block-description">The OD team can see your web design visions brought
			to life, creating a site that promotes your uniqueness through specific functionalities and features.</div>
		  </div>
		</div>
		<div class="home-img-block fadeBlock2">
		  <div data-content="FIND OUT MORE" class='home-img-container'>
			<img src="http://optimumwebdesigns.com/images/test2new.jpg">
			<div class="overlay"></div>
		  </div>
		  <div class="home-img-wording-blocks">
			<div class="home-img-wording-block-title">ECOMMERCE</div>
			<div class="home-img-wording-block-description">Custom built solutions catered towards you end goal. 
			gfdgfdsg greg reg regrfesg fdsg gretswtgy tgreswt treswt trgegfd gsvbd fbgre greasgv drfdg greaag gredr</div>
		  </div>
		</div>
		<div class="home-img-block fadeBlock3">
		  <div data-content="FIND OUT MORE" class='home-img-container'>
			<img src="http://optimumwebdesigns.com/images/test3new.jpg">
			<div class="overlay"></div>
		  </div>
		  <div class="home-img-wording-blocks">
			<div class="home-img-wording-block-title">MARKETING STRATEGIES</div>
			<div class="home-img-wording-block-description">MARKETING STRATEGIES gfdgf fdggs gfsg gfsg gf sgf g  
			gfdsg sdfggfs gfdsgssdfg fdggfds gfdsg gfds gfdgs gf dsgfdsgfgs gfdgfs gtrg resg reg rgesgresrgrg</div>
		  </div>
		</div>
	  </div>
	</div>

1 个答案:

答案 0 :(得分:1)

#include <algorithm>        // std::swap
#include <iostream>         // ...
#include <utility>          // std::move
#include <vector>           // std::vector    
using namespace std;

class Item
{
private:
    int id_;

    Item( Item const& ) = delete;
    auto operator=( Item const& ) -> Item& = delete;

public:
    auto operator=( Item&& other ) -> Item&
    { id_ = other.id_; other.id_ = 0; return *this; }

    ~Item()
    { if( id_ != 0 ) { wcout << "Destroyed #" << id_ << ".\n"; } }

    Item( int id )
        : id_( id )
    { wcout << "Created #" << id_ << ".\n"; }

    Item( Item&& other )
        : id_( other.id_ )
    { other.id_ = 0; }
};

auto main() -> int
{
    vector<Item> v;
    for( int i = 1; i <= 7; ++i ) { v.push_back( Item( i ) ); }

    wcout << "capacity with 7 items: " << v.capacity() << "\n";
    v.erase( v.begin() + 2, v.end() );
    wcout << "capacity with " << v.size() << " items: " << v.capacity() << "\n";
    // Forcibly reduce the capacity. Can't just copy since Item isn't copyable:
    {
        vector<Item> copy;
        for( Item& o : v ) { copy.push_back( move( o ) ); }     // Move items over.
        swap( v, copy );
    }
    wcout << "Capacity after forced reduce: " << v.capacity() << endl;
}

.home-img-block:hover .overlay

替换它们
.home-img-block:hover img

否则当你将鼠标悬停在整个容器上而不是只悬停img时,你就会触发。