CSS Media Queries(メディアクエリ)を使用した指定方法
2011.01.06
この記事は最終更新日から1年以上が経過しています。
CSS Media Queries(メディアクエリ)を使用したデバイスごとの指定方法です。
CSS3のMedia Queries(メディア クエリ)を使用して、デスクトップのブラウザ用をはじめ
iPhone, iPadなどのモバイル用にスタイルシートの分ける方法です。
スタイルシートの分け方は
※プロパティ単位
※ファイル単位
の2種類になります。
プロパティ単位でデバイスごとにスタイルシートを設定
例:
@media only screen
and (条件){
適応させたいセレクタとcssプロパティ....
h4{
border:#000 1px solid;
etc...
}
}
スマートフォン(縦長・横長)
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
}
スマートフォン(横長)
@media only screen
and (min-width : 321px) {
}
スマートフォン(縦長)
@media only screen
and (max-width : 320px) {
}
iPad(縦長・横長)
@media only screen and
(min-device-width : 768px) and
(max-device-width : 1024px) {
}
iPad(横長)
@media only screen and
(min-device-width : 768px) and
(max-device-width : 1024px) and
(orientation : landscape) {
}
iPad(縦長)
@media only screen and
(min-device-width : 768px) and
(max-device-width : 1024px) and
(orientation : portrait) {
}
デスクトップのブラウザ用(横長)
@media only screen and
(min-width : 1224px) {
}
大きいモニター用
@media only screen and
(min-width : 1824px) {
}
iPhone4などの高解像度用
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
}
ファイル単位でデバイスごとにスタイルシートを設定
スマートフォン(縦長・横長)
<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)">
iPad(縦長・横長)
<link rel="stylesheet" href="ipad.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px)">
iPad(横長)
<link rel="stylesheet" href="ipad-landscape.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape)">
iPad(縦長)
<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 : 1224px)">
大きいモニター用
<link rel="stylesheet" href="widescreen.css" media="only screen and (min-width : 1824px)">
iPhone4などの高解像度用
<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)">















