0

我希望当我悬停 [.area] 类时,[.button] 类会发生变化,但它不起作用。我能做些什么?

这是我的代码

#content { float:left; margin:0 20px 20px 0; }
.area { z-index:0; position:relative; border-radius:5px; border:3px #09B2D2 solid; height:430px; width:245px; transition: all .5s; }
.area:hover { background:#09b2d2; }
.area:hover .words { color:#fff; }
.head { background:#09b2d2; width:245px; margin-top:25px; text-align:center; font-family:Segoe UI; font-size:30px; text-transform:uppercase; padding:3px 0; font-weight:bold; color:#fff; }
.words { margin-top:25px; line-height:40px; text-align:center; color:#09b2d2; font-family:Segoe UI; font-weight:bold; transition: all .5s; }
.button { z-index:1; transition: all .5s; left:57px; background:#fff; top:-20px; border-radius:3px; border:2px solid #09B2D2; width: 125px; height: 40px; position:relative; text-align:center; }
.button:hover { background:#09b2d2; }
.button:hover .h1 { opacity:0; }
.button:hover .h2 { opacity:100; }
.h1 { transition: all .5s; z-index:2; margin:4px 0 0 -32px; font-weight:bold; color:#09B2D2; font-family:Segoe UI; font-size:20px; position:absolute; }
.h2 { margin:5px 0 0 -36px; transition: all .5s; z-index:2; opacity:0; font-weight:bold; color:#fff; font-family:Segoe UI; font-size:20px; position:absolute; }
.h2 > a { color:#fff; text-decoration:none;}

<div id="content">
    <div class="area">
        <div class="head">Başlangıç</div>
        <div class="words">Wordpress Teknolojisi</br>1 Yıl Alan Adı Tescili</br>500 MB Hosting</br></br>Seo Desteği</br>Ücretsiz Destek</br>Kontrol Paneli</div>
    </div>
    <div class="button">
    <span class="h1">100 TL</span>
    <span class="h2"><a href="#">Satın Al</a></span>
    </div>
</div>
4

1 回答 1

0

我建议:

.area:hover + .button {
    /* CSS here */
}

.button这会在前一个兄弟元素.area悬停时设置元素的样式。

您的原始代码“不起作用”的原因是因为显然没有 CSS 选择器针对.area:hover或指定与该.button元素相关的元素。

为了减少限制:

.area:hover ~ .button {
    /* CSS here */
}

.button这将为出现在 DOM 中的任何同级元素设置样式,而不是.area悬停的元素。

是相邻的+兄弟组合器(它将仅选择紧跟在 之后的元素.button),是通用的兄弟组合器,它将选择元素后面的所有元素。.area~ .button.area

参考:

于 2013-10-31T21:57:13.883 回答