Programing

@ 미디어 최소 너비 및 최대 너비

lottogame 2020. 5. 9. 09:04
반응형

@ 미디어 최소 너비 및 최대 너비


@media설정이 있습니다.

HTML :

<head>
  <meta name="viewport" content="width=device-width, user-scalable=no" />
</head>

CSS :

@media screen and (min-width: 769px) {
    /* STYLES HERE */
}

@media screen and (min-device-width: 481px) and (max-device-width: 768px) { 
    /* STYLES HERE */
}

@media only screen and (max-device-width: 480px) {
    /* STYLES HERE */
}

이 설정을 사용하면 iPhone에서 작동하지만 브라우저에서는 작동하지 않습니다.

내가 이미 device메타에 있었기 때문에 그럴 수 max-width:480px있습니까?


가장 좋은 방법은 5.5, 6, 7 및 8을 포함한 이전 브라우저와 같이 이전 브라우저에 기본 CSS를 작성하는 것입니다. @media를 읽을 수 없습니다. @media를 사용하면 다음과 같이 사용합니다.

<style type="text/css">
    /* default styles here for older browsers. 
       I tend to go for a 600px - 960px width max but using percentages
    */
    @media only screen and (min-width: 960px) {
        /* styles for browsers larger than 960px; */
    }
    @media only screen and (min-width: 1440px) {
        /* styles for browsers larger than 1440px; */
    }
    @media only screen and (min-width: 2000px) {
        /* for sumo sized (mac) screens */
    }
    @media only screen and (max-device-width: 480px) {
       /* styles for mobile browsers smaller than 480px; (iPhone) */
    }
    @media only screen and (device-width: 768px) {
       /* default iPad screens */
    }
    /* different techniques for iPad screening */
    @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
      /* For portrait layouts only */
    }

    @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
      /* For landscape layouts only */
    }
</style>

그러나 @media로 원하는 모든 것을 할 수 있습니다. 이것은 모든 브라우저에 대한 스타일을 만들 때 내가 찾은 최고의 예입니다.

iPad CSS 사양.

또한! 인쇄 가능성을 찾고 있다면@media print{}


근본적인 문제는 max-device-widthvs old를 사용하고 max-width있습니다.

Using the "device" keyword targets physical dimension of the screen, not the width of the browser window.

For example:

@media only screen and (max-device-width: 480px) {
    /* STYLES HERE for DEVICES with physical max-screen width of 480px */
}

Versus

@media only screen and (max-width: 480px) {
    /* STYLES HERE for BROWSER WINDOWS with a max-width of 480px. 
       This will work on desktops when the window is narrowed.  */
}

The correct value for the content attribute should include initial-scale instead:

<meta name="viewport" content="width=device-width, initial-scale=1">
                                                   ^^^^^^^^^^^^^^^


If website on small devices behavior like desktop screen then you have to put this meta tag into header before

<meta name="viewport" content="width=device-width, initial-scale=1">

For media queries you can set this as

this will cover your all mobile/cellphone widths

    @media only screen and (min-width: 200px) and (max-width: 767px)  {
    //Put your CSS here for 400px to 600px width devices (cover all mobile portrait width //

    }

For iPad and iPad pro you have to use

    @media only screen and (min-width: 768px) and (max-width: 1024px)  {
    //Put your CSS here for 768px to 1024px width devices(covers all iPad portrait width //

    }

If you want to add css for Landscape mode you can add this

and (orientation : landscape)

  @media only screen and (min-width: 200px) and (max-width: 767px) and (orientation : landscape) {
        //Put your CSS here for 400px to 600px width devices (cover all mobile landscape width //

        }

참고URL : https://stackoverflow.com/questions/13550541/media-min-width-max-width

반응형