Warning: Undefined array key 0 in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 406

Warning: Attempt to read property "parent" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 407

Warning: Attempt to read property "term_id" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 413

Warning: Attempt to read property "cat_name" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 413

デバイスのビューエリアや解像度でスタイルを切り替える方法


Warning: Undefined variable $pre in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 517

Warning: Undefined variable $pre in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 517

Warning: Undefined variable $pre in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 517
web

デバイスやビューのエリアサイズでスタイルを切り替える

サイズの指定には以下の4種類が用意されています。

属性説明
max-widthビューエリアの最大値
min-widthビューエリアの最小値
max-device-widthデバイスエリアの最大値
min-device-widthデバイスエリアの最小値

指定時はこれらを組み合わせてエリアサイズごとのスタイルの指定をします。

media screen and (min-width : 768px){
  /*ビューエリアの横幅768pxまでのスタイル*/
}
@media screen and (min-width : 1024px) {
  /*ビューエリアの横幅1024pxまでのスタイル*/
}

ビューエリアとデバイスエリアの補足

ビューエリアはその時点のサイズなのに対し、デバイスエリアはデバイスのサイズです。 スマートフォンを横向きにしてサイズが横長になった場合、ビューエリアのスタイルは切り替わりますがデバイスエリアのスタイルは切り替わらない違いがあります。

デバイスの解像度でスタイルを切り替える

webkitでdevice-pixel-ratioを、将来的な記述としてresolutionを指定します。
デバイスピクセル値は{1,1.5,2,3}などが想定されます。

media (-webkit-min-device-pixel-ratio: 1.5), /* Webkit */
       (min-resolution: 1.5dppx)              /* The Future */
  /*高解像時のスタイル*/
}

横向きと縦向きでスタイルを切り替える

リキッドレイアウトであれば縦横を切り替えても基本的に問題ありません。
そうでない場合や、あえて縦・横で違うコンテンツにする場合、orientationプロパティを使います。

*横向きの場合*/
@media screen and (orientation: portrait) {
  /*横向きのスタイル*/
}
 
/*縦向きの場合*/
@media screen and (orientation: landscape) {
  /*縦向きのスタイル*/
}

Warning: Undefined variable $category in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 79

Warning: Attempt to read property "name" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 79

の記事

eyecatch

演算と演算子

eyecatch

XAMPPをインストールする方法

eyecatch

PHPとは

eyecatch

ウェブとウェブサイト

eyecatch

コンテンツモデルとコンテキスト

eyecatch

ウェブサイトに使われる一般的な文字フォント一覧


Warning: Undefined variable $category in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 84

Warning: Attempt to read property "count" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 84
HOME