how do i include css based on screen size of the device

后端 未结 4 1967
有刺的猬
有刺的猬 2020-12-18 11:29

How do i include css based on the screen size of the devices for viewing web pages?

What i have in mind is that i will only include one css inside a page and inside

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 12:10

    If you want to have only one css per page, but in that css file you want to import other css files that have differences based on screen size, you can do it like for example for screens less than 960px

    @media screen and (max-width: 960px) 
    {
    
    /* your imports */
    @import url('/css/styles1.css');
    @import url('/css/styles2.css');
    
    }
    

    Also if you want to use only two css files in general, you might want to search for media queries and work on that a little :)

    There are different methods for using different styles for different devices and screens, you might find this article useful about that http://css-tricks.com/resolution-specific-stylesheets/

    Which says, e.g, you can specify in which screen size you want to show a css file like this;

    
    
    
    

提交回复
热议问题