html - CSS Hover 定位其他元素

标签 html css hover zurb-foundation target

当悬停在 .calltoaction 上时,背景图像应该缩放到 105%。如何通过 CSS 定位?我正在为我的 html 使用 foundation.css。还创建了代码笔:http://codepen.io/rezasan/pen/dpyoYO

HTML:

<div id="tiles">
<div class="row">
<div class="medium-6 columns nopadleftright tile-img" style="background-image:url('http://placehold.it/300x300');"></div>
<div class="medium-6 columns nopadleftright text-center">
  <div class="v-align">
    <h1 class="preheader text-center">EXPERIENCES</h1>
    <h1>A Magical Location</h1>
    <p>Text</p>
    <div class="calltoaction"><a href="#">ABOUT</a></div>
  </div>
</div>
 <div class="row">
   <div class="medium-6 columns nopadleftright text-center">
  <div class="v-align">
    <h1 class="preheader text-center">EXPERIENCES</h1>
    <h1>A Magical Location</h1>
    <p>Text</p>
    <div class="calltoaction"><a href="#">ABOUT</a></div>
  </div>
</div>
<div class="medium-6 columns nopadleftright tile-img" style="background-image:url('http://placehold.it/300x300');"></div>

CSS:

#tiles .row .medium-6 {
    width:45%;
    float:left;
    height: 185px;
    background-color: #fff;
    padding:0 10px;
}

#tiles .row .tile-img{
    background-repeat: no-repeat;
    background-position: center center; 
    -webkit-background-size: 100%;
    -moz-background-size: 100%;
    -o-background-size: 100%;
    background-size: 100%;
    transition: background-size .3s ease-in-out;
    -moz-transition: background-size .3s ease-in-out;
    -ms-transition: background-size .3s ease-in-out;
    -o-transition: background-size .3s ease-in-out;
    -webkit-transition: background-size .3s ease-in-out;
}

#tiles .calltoaction a:hover + .tile-img {
    background-size: 105%;
}

最佳答案

你不能通过纯 CSS 做到这一点,因为它不能那样工作(在你的情况下你不能定位一个 parent )。但是,您可以通过一些 jQuery 函数来实现:

$('.calltoaction a').hover(function(){
  $('.tile-img').css('background-size', '105%');
});

https://jsfiddle.net/wx38rz5L/2777/

关于html - CSS Hover 定位其他元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39266713/

相关文章:

html - CSS 位置 :fixed not working

html - 模态内的表单大小

html - Bootstrap 导航栏折叠切换显示单条黑线而不是菜单

ios - iPhone 6 中的水平滚动

css - 如何设置 React Native <CheckBox> 组件的样式?

html - CSS - 悬停可见另一个子菜单

html - css - 动态 div 高度

PHP、MySQL : Problem retrieving image url strings from database

html - 为什么文字装饰: underline not work?

html - 将鼠标悬停在 <li> 上使其他 <ul> 消失