简体   繁体   English

更改另一个DIV之前的DIV宽度

[英]Change DIV width that is before another DIV

I have this structure with dynamic DIVs and all have the same class, since all are created automatically. 我具有这种具有动态DIV的结构,并且都具有相同的类,因为它们都是自动创建的。

The problem here is that, the last of them prior to other DIV with other class, I would like to have his style as width:100% instead of width:50% as all others set by CSS. 这里的问题是,在其他类之前,它们中的最后一个要比其他DIV更好,我希望他的样式为width:100%,而不是CSS设置的所有其他样式,为width:50%。

Here's a sample: 这是一个示例:

<div class="awp_box awp_box_inner"></div>
<div class="awp_box awp_box_inner"></div>
<div class="awp_box awp_box_inner"></div>
<div class="awp_stock_container awp_sct" style="max-width: 400px !important;"></div>

So I only want to change that third DIV, which sometimes is the first and only one, other times is the second, other times is the fourth, etc... 所以我只想更改第三个DIV,有时是第一个,只有一个,其他时间是第二个,其他时间是第四个,依此类推...

I am usually good with CSS but this time I'm having a hard time finding a solution for this one. 我通常对CSS很好,但是这次我很难为这个问题找到解决方案。

Can someone please give me a hand here guiding me in the right track so I could put this working? 有人可以帮我在正确的道路上指引我,以便我可以进行这项工作吗?

If I was correct in my question above then add this CSS 如果我在上述问题中正确无误,请添加此CSS

div.awp_box.awp_box_inner:nth-last-child(1) {
     width: 100%;
}

Source: TutsPlus 资料来源: TutsPlus

Based on the comments, the following script could give you what you need. 根据评论,以下脚本可以为您提供所需的内容。

$(document).ready(function(){    
    $('.awp_sct').prev().addClass('full');
});

It will add a class to the previous element of the .awp_sct. 它将向.awp_sct的上一个元素添加一个类。

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM