CSS selector based on width?

前端 未结 4 739
灰色年华
灰色年华 2020-12-04 02:00

Is there a CSS rule that would match elements based on their width? If not, would it be interesting to propose that in the standard?

One could do something like

4条回答
  •  既然无缘
    2020-12-04 02:34

    That might become inconsistent because new elements could be unexpectedly affected. I would just add a class that defines {wrap: nowrap;} to any elements in your html. Or if the element width changes on resize, just use some js.

    window.onscroll = function(){
        var elementWidth = document.getElementById('elementID').style.width;
        if(elementWidth < 200){ .. do something .. }
        else{ .. reverse changes .. }
    }
    

提交回复
热议问题