jQuery selector for first row of inline-block divs

后端 未结 4 1087
生来不讨喜
生来不讨喜 2021-02-11 06:24

I have some divs with display: inline-block; and I have to select first row of divs and set them for example different border color and I need to do it in javaScript (jQuery).

4条回答
  •  遇见更好的自我
    2021-02-11 07:24

    you can get the width of your container which has a css-style named "container" by $(".container").width,

    and then you can calculate how many divs can be put in the first row,and put it in a variable like firstrow_divNums.

    now use $(".calculate").children() to get the child-divs,

    finally use "for" loop from $(".calculate").children().eq(0) to $(".calculate").children().eq(firstrow_divNums) ,

    and now you can do what you want like adding css-style to any elements.

提交回复
热议问题