cssmedia-queriescontainer-queries

CSS media queries by div width or height


Is it possible, to specific CSS styles by some DIV width or height?

Something like this:

@media screen and (max-width: 1024px) 

Solution

  • You can do this with jQuery.

    function change_size(){
       var window_height = $(window).height();
       var div_height = $("#your_id").height();
       if(window_height < div_height){
              $("#your_id").css({marginTop: "20px", height: "20px"});  //for example
       }
    }
    
    $(document).ready(function(){
       change_size();
    });
    $(window).resize(function(){
       change_size();
    });