CSS data attribute conditional value selector?

前端 未结 1 389
不思量自难忘°
不思量自难忘° 2021-01-04 11:42

Given html such as :

Jonh
Jack
Julian&l
相关标签:
1条回答
  • 2021-01-04 12:35

    With CSS you can select elements with their attributes:

    div[data-points] {  }
    

    or the value of their attributes:

    div[data-points="800"] {  }
    

    but you can't use conditions in CSS.
    I would recommend you to use a javaScript solutions for this problem which can be so easy, for example, using jQuery you can do something like:

    $("div[data-points]").each(function() {
        if ($(this).attr('data-points') > 1000) {
            $(this).addClass('larger-than-1000'); // Or whatever
        }
    });
    
    0 讨论(0)
提交回复
热议问题