DevOps

Html Css @media quary for Smart phones

IT오이시이 2011. 4. 16. 15:29
728x90



HTML5와  CSS3를 이용한 멀티 디바이스 지원: @media quary for Smart phones

- 다양한 크기의 스마트폰의 보급으로 화면 사이즈에 대한 UI를 고려 한다면

  CSS의 media query를 이용하여 구현을 할 수 있다.

 가로 일때 세로일때 화면 사이즈가 폰일때, 패드일때 하나의 웹 페이지로 지원을 할수 있게 된다.


    @media all and (orientation:portrait) {

    img {

        max-width:(device-width);

        max-height:(device-height);

        min-width:(device-width*0.5);

        min-height:(device-width * 0.5);

        overflow : auto;

    }

    @media all and (orientation:landscape) {

    img {

        max-width:(device-width);

        max-height:(device-width);

        min-width:(device-width*0.5);

        min-height:(device-width*0.5);

        overflow : auto;

    }


아이폰 아이패드를 위해서 다음과 같이 확장 가능하다.

[참고] http://broadcast.oreilly.com/2010/04/using-css-media-queries-ipad.html


Here are the new links, showing the updated CSS Media Queries:


<link rel="stylesheet" media="all and (max-device-width: 480px)" href="iphone.css">
<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" href="ipad-portrait.css">
<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" href="ipad-landscape.css">
<link rel="stylesheet" media="all and (min-device-width: 1025px)" href="ipad-landscape.css"> 



좀더 종합적으로 아래와 같이 작성 가능하다.

 [참고] http://www.stuffandnonsense.co.uk/blog/about/hardboiled_css3_media_queries/

/* Smartphones (portrait and landscape) ----------- */
@ only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}

/* Smartphones (landscape) ----------- */
@ only screen 
and (min-width : 321px) {
/* Styles */
}

/* Smartphones (portrait) ----------- */
@ only screen 
and (max-width : 320px) {
/* Styles */
}

/* iPads (portrait and landscape) ----------- */
@ only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}

/* iPads (landscape) ----------- */
@ only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}

/* iPads (portrait) ----------- */
@ only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}
ㅠ
@ only screen 
and (min-width : 1224px) {
/* Styles */
}

/* Large screens ----------- */
@ only screen 
and (min-width : 1824px) {
/* Styles */
}

/* iPhone 4 ----------- */
@
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}

Of course, you might not want all your responsive design styles inside one huge stylesheet. If that’s the case, you can serve alternative stylesheets using the same queries as attributes on your link elements.

<head>

<link rel="stylesheet" href="smartphone.css" 
media="only screen and (min-device-width : 320px) 
and (max-device-width : 480px)">

<link rel="stylesheet" href="smartphone-landscape.css" 
media="only screen and (min-width : 321px)">

<link rel="stylesheet" href="smartphone-portrait.css" 
media="only screen and (max-width : 320px)">

<link rel="stylesheet" href="ipad.css" 
media="only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px)">

<link rel="stylesheet" href="ipad-landscape.css" 
media="only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape)">

<link rel="stylesheet" href="ipad-portrait.css" 
media="only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait)">

<link rel="stylesheet" href="widescreen.css" 
media="only screen and (min-width : 1824px)">

<link rel="stylesheet" href="iphone4.css" 
media="only screen 
and (-webkit-min-device-pixel-ratio : 1.5), 
only screen and (min-device-pixel-ratio : 1.5)">

</head>







728x90
반응형