Can media queries resize based on a div element instead of the screen?

前端 未结 11 1698
[愿得一人]
[愿得一人] 2020-11-22 04:17

I would like to use media queries to resize elements based on the size of a div element they are in. I cannot use the screen size as the div is jus

11条回答
  •  自闭症患者
    2020-11-22 04:49

    The only way I can think that you can accomplish what you want purely with css, is to use a fluid container for your widget. If your container's width is a percentage of the screen then you can use media queries to style depending on your container's width, as you will now know for each screen's dimensions what is your container's dimensions. For example, let's say you decide to make your container's 50% of the screen width. Then for a screen width of 1200px you know that your container is 600px

    .myContainer {
      width: 50%;
    }
    
    /* you know know that your container is 600px 
     * so you style accordingly
    */
    @media (max-width: 1200px) { 
      /* your css for 600px container */
    }
    

提交回复
热议问题