如果prev div有类,则在当前div上添加css

时间:2013-03-19 18:21:27

标签: jquery css

如果prev div有一些类,我只想在当前div上添加css。

我的HTML

<div class="views-field views-field-field-1-image"></div>
<div class="views-field views-field-title"></div>

如果div .views-field-title之前有此div .views-field-field-1-image,则在.views-field-title div上添加宽度。

3 个答案:

答案 0 :(得分:4)

使用adjacent sibling selector

.views-field.views-field-field-1-image + .views-field.views-field-title {
    /* ... */
}

答案 1 :(得分:0)

您可以使用adjacent sibling selector

.views-field-field-1-image + .views-field-title {
    YOUR CSS
}

答案 2 :(得分:0)

.views-field.views-field-field-1-image + .views-field.views-field-title {
    width: #px;
}

文档:http://www.w3.org/TR/CSS21/selector.html#adjacent-selectors