CSS @media စည်းမျဉ်း
ဥပမာ
ဘရောက်ဆာဝင်းဒိုးသည် 600px ကျယ်သည် သို့မဟုတ် ထို့ထက်နည်းသည့်အခါ <body> ဒြပ်စင်၏နောက်ခံအရောင်ကို "အပြာရောင်" သို့ပြောင်းပါ-
@media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
အောက်တွင် နောက်ထပ် "စမ်းသုံးကြည့်ပါ" ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
@media
မတူညီသောမီဒီယာအမျိုးအစား/စက်ပစ္စည်းများအတွက် မတူညီသောစတိုင်များကို အသုံးပြုရန် စည်းမျဉ်းကို မီဒီယာမေးမြန်းချက်များတွင် အသုံးပြုသည် ။
မီဒီယာမေးမြန်းချက်များကို အသုံးပြုနိုင်ပြီး၊ ကဲ့သို့သော အရာများစွာကို စစ်ဆေးရန်၊
- viewport ၏ အကျယ်နှင့် အမြင့်
- စက်၏ အကျယ်နှင့် အမြင့်
- လမ်းညွှန်ချက် (တက်ဘလက်/ဖုန်းသည် အလျားလိုက် သို့မဟုတ် ပုံတူမုဒ်တွင် ရှိပါသလား။)
- ပြတ်သားမှု
မီဒီယာမေးမြန်းချက်များကို အသုံးပြုခြင်းသည် ဒက်စတော့များ၊ လက်ပ်တော့များ၊ တက်ဘလက်များနှင့် မိုဘိုင်းဖုန်းများသို့ အံဝင်ခွင်ကျဖြစ်စေသော ပုံစံစာရွက် (တုံ့ပြန်မှုရှိသော ဝဘ်ဒီဇိုင်း) ကို ပေးပို့ရန်အတွက် ရေပန်းစားသောနည်းလမ်းတစ်ခုဖြစ်သည်။
အချို့သောစတိုင်များသည် ပုံနှိပ်စာရွက်စာတမ်းများအတွက်သာ သို့မဟုတ် စခရင်ဖတ်သူများအတွက်သာဖြစ်သည် (မီဒီယာအမျိုးအစား- ပရင့်၊ ဖန်သားပြင် သို့မဟုတ် စကားသံ) ကို သတ်မှတ်ရန် သင်သည် မီဒီယာမေးခွန်းများကို အသုံးပြုနိုင်သည်။
မီဒီယာအမျိုးအစားများအပြင် မီဒီယာအင်္ဂါရပ်များလည်း ရှိသေးသည်။ မီဒီယာ အင်္ဂါရပ်များသည် သုံးစွဲသူ ကိုယ်စားလှယ် သို့မဟုတ် ပြသသည့် ကိရိယာ၏ သီးခြားအင်္ဂါရပ်ကို စမ်းသပ်ခွင့်ပြုခြင်းဖြင့် မီဒီယာမေးမြန်းချက်များအတွက် ပိုမိုတိကျသော အသေးစိတ်အချက်အလက်များကို ပေးဆောင်ပါသည်။ ဥပမာအားဖြင့်၊ သင်သည် သတ်မှတ်ထားသော အကျယ်ထက် ပိုကြီးသော သို့မဟုတ် သေးငယ်သော ဖန်သားပြင်များတွင်သာ ပုံစံများကို အသုံးချနိုင်သည်။
Browser ပံ့ပိုးမှု
ဇယားရှိ နံပါတ်များသည် @media စည်းမျဉ်းကို အပြည့်အဝထောက်ခံသည့် ပထမဆုံးဘရောက်ဆာဗားရှင်းကို သတ်မှတ်ပေးပါသည်။
Property | |||||
---|---|---|---|---|---|
@media | 21 | 9 | 3.5 | 4.0 | 9 |
CSS Syntax
@media not|only mediatype and (mediafeature and|or|not
mediafeature) {
CSS-Code;
}
not ၊ only နှင့် keywords များ၏ အဓိပ္ပါယ်
not- အဓိကစကားလုံး မဟုတ်သော စကားလုံးသည် မီဒီယာမေးမြန်းမှုတစ်ခုလုံး၏ အဓိပ္ပါယ်ကို ပြောင်းပြန်လှန်စေသည်။
တစ်ခုတည်းသော သော့ချက်စကားလုံးသည် မီဒီယာ အင်္ဂါရပ်များပါရှိသော မီဒီယာမေးမြန်းချက်များကို မပံ့ပိုးသော ဘရောက်ဆာအဟောင်းများကို သတ်မှတ်ထားသော ပုံစံများကို အသုံးပြုခြင်းမှ တားဆီးပေးသည်။ ၎င်းသည် ခေတ်မီဘရောက်ဆာများအပေါ် သက်ရောက်မှုမရှိပါ။
နှင့်- သော့ချက်စကားလုံးသည် မီဒီယာအမျိုးအစားတစ်ခု သို့မဟုတ် အခြားမီဒီယာအင်္ဂါရပ်များနှင့် ပေါင်းစပ်ထားသည်။
သူတို့အားလုံးက ရွေးချယ်ခွင့်ရှိတယ်။ သို့သော် အကယ်၍ သင် သာ အသုံးပြု ပါ က ၊ မီဒီယာ အမျိုးအစားကိုလည်း သတ်မှတ်ရပါမည်။
ဤကဲ့သို့ မတူညီသော မီဒီယာအတွက် မတူညီသော ပုံစံစာရွက်များ ကိုလည်း သင့်တွင် ရနိုင်သည် -
<link rel="stylesheet" media="screen and (min-width:
900px)" href="widescreen.css">
<link rel="stylesheet" media="screen and (max-width:
600px)" href="smallscreen.css">
....
မီဒီယာ အမျိုးအစားများ
Value | Description |
---|---|
all | Default. Used for all media type devices |
Used for printers | |
screen | Used for computer screens, tablets, smart-phones etc. |
speech | Used for screenreaders that "reads" the page out loud |
မီဒီယာအင်္ဂါရပ်များ
Value | Description |
---|---|
any-hover | Does any available input mechanism allow the user to hover over elements? (added in Media Queries Level 4) |
any-pointer | Is any available input mechanism a pointing device, and if so, how accurate is it? (added in Media Queries Level 4) |
aspect-ratio | The ratio between the width and the height of the viewport |
color | The number of bits per color component for the output device |
color-gamut | The approximate range of colors that are supported by the user agent and output device (added in Media Queries Level 4) |
color-index | The number of colors the device can display |
grid | Whether the device is a grid or bitmap |
height | The viewport height |
hover | Does the primary input mechanism allow the user to hover over elements? (added in Media Queries Level 4) |
inverted-colors | Is the browser or underlying OS inverting colors? (added in Media Queries Level 4) |
light-level | Current ambient light level (added in Media Queries Level 4) |
max-aspect-ratio | The maximum ratio between the width and the height of the display area |
max-color | The maximum number of bits per color component for the output device |
max-color-index | The maximum number of colors the device can display |
max-height | The maximum height of the display area, such as a browser window |
max-monochrome | The maximum number of bits per "color" on a monochrome (greyscale) device |
max-resolution | The maximum resolution of the device, using dpi or dpcm |
max-width | The maximum width of the display area, such as a browser window |
min-aspect-ratio | The minimum ratio between the width and the height of the display area |
min-color | The minimum number of bits per color component for the output device |
min-color-index | The minimum number of colors the device can display |
min-height | The minimum height of the display area, such as a browser window |
min-monochrome | The minimum number of bits per "color" on a monochrome (greyscale) device |
min-resolution | The minimum resolution of the device, using dpi or dpcm |
min-width | The minimum width of the display area, such as a browser window |
monochrome | The number of bits per "color" on a monochrome (greyscale) device |
orientation | The orientation of the viewport (landscape or portrait mode) |
overflow-block | How does the output device handle content that overflows the viewport along the block axis (added in Media Queries Level 4) |
overflow-inline | Can content that overflows the viewport along the inline axis be scrolled (added in Media Queries Level 4) |
pointer | Is the primary input mechanism a pointing device, and if so, how accurate is it? (added in Media Queries Level 4) |
resolution | The resolution of the output device, using dpi or dpcm |
scan | The scanning process of the output device |
scripting | Is scripting (e.g. JavaScript) available? (added in Media Queries Level 4) |
update | How quickly can the output device modify the appearance of the content (added in Media Queries Level 4) |
width | The viewport width |
နောက်ထပ် ဥပမာများ
ဥပမာ
ဘရောင်ဇာ၏ အကျယ်သည် 600px ကျယ်သည် သို့မဟုတ် ထို့ထက်နည်းသည့်အခါ အစိတ်အပိုင်းတစ်ခုကို ဝှက်ထားပါ-
@media screen and (max-width: 600px) {
div.example {
display:
none;
}
}
ဥပမာ
မြင်ကွင်းပို့တ်သည် 800 ပစ်ဇယ်ကျယ်လျှင် သို့မဟုတ် ပိုကျယ်ပါက နောက်ခံ-အရောင်အား လာဗင်ဒါသို့သတ်မှတ်ရန် mediaqueries ကိုသုံးပါ မြင်ကွင်းပို့တ်သည် 400 နှင့် 799 ပစ်ဇယ်ကြားတွင်ကျယ်ပါက အစိမ်းဖျော့ဖျော့သို့ဖျော့သွားပါ။ မြင်ကွင်းပို့တ်သည် 400 pixels ထက်သေးငယ်ပါက၊ နောက်ခံအရောင်သည် အပြာနုရောင်ဖြစ်သည်-
body {
background-color: lightblue;
}
@media screen and (min-width:
400px) {
body {
background-color: lightgreen;
}
}
@media
screen and (min-width: 800px) {
body {
background-color: lavender;
}
}
ဥပမာ
တုံ့ပြန်နိုင်သော လမ်းကြောင်းပြမီနူးကို ဖန်တီးပါ (ကြီးမားသောစခရင်များပေါ်တွင် အလျားလိုက်နှင့် ဖန်သားပြင်ငယ်များတွင် ဒေါင်လိုက်ပြသသည်-
@media screen and (max-width: 600px) {
.topnav a {
float: none;
width: 100%;
}
}
ဥပမာ
တုံ့ပြန်မှုရှိသော ကော်လံအပြင်အဆင်ကို ဖန်တီးရန် မီဒီယာမေးခွန်းများကို အသုံးပြုပါ-
/* On screens that are 992px wide or less, go from four columns to two
columns */
@media screen and (max-width: 992px) {
.column {
width: 50%;
}
}
/* On screens that are 600px wide or less, make the columns stack
on top of each other instead of next to each other */
@media screen and (max-width:
600px) {
.column {
width: 100%;
}
}
ဥပမာ
တုံ့ပြန်မှုရှိသော ဝဘ်ဆိုက်တစ်ခုကို ဖန်တီးရန် မီဒီယာမေးခွန်းများကို အသုံးပြုပါ-
ဥပမာ
ဘရောက်ဆာ၏ ဦးတည်ချက်ပေါ်မူတည်၍ စာမျက်နှာတစ်ခု၏ အပြင်အဆင်ကို ပြောင်းလဲရန် မီဒီယာမေးမြန်းချက်များကိုလည်း အသုံးပြုနိုင်သည်။ "Landscape" orientation ဟုခေါ်သော ဘရောက်ဆာဝင်းဒိုးသည် ၎င်း၏အမြင့်ထက် ပိုကျယ်သည့်အခါတွင်သာ အသုံးချမည့် CSS ဂုဏ်သတ္တိအစုတစ်ခု ရှိနိုင်ပါသည်။
ဦးတည်ချက်သည် ရှုခင်းမုဒ်တွင် ရှိနေပါက အပြာနုရောင် နောက်ခံအရောင်ကို အသုံးပြုပါ-
@media only screen and (orientation:
landscape) {
body {
background-color: lightblue;
}
}
ဥပမာ
စာရွက်စာတမ်းကို စခရင်ပေါ်တွင်ပြသသောအခါ၊ ပုံနှိပ်သည့်အခါတွင် အနက်ရောင်အဖြစ် စာသားအရောင်ကို အစိမ်းရောင်အဖြစ် သတ်မှတ်ရန် မီဒီယာမေးခွန်းများကို အသုံးပြုပါ-
@media screen {
body {
color: green;
}
}
@media print {
body {
color: black;
}
}
ဥပမာ
ကော်မာ ခြားထားသော စာရင်း - ကော်မာကို အသုံးပြု၍ ရှိနှင့်ပြီးသား တစ်ခုသို့ ကော်မာကို အသုံးပြု၍ အပိုမီဒီယာ စုံစမ်းမှုတစ်ခုကို ပေါင်းထည့်ပါ (၎င်းသည် OR အော်ပရေတာတစ်ခုကဲ့သို့ ပြုမူလိမ့်မည်)။
/* When the width is between 600px and 900px OR above 1100px - change the
appearance of <div> */
@media screen and (max-width: 900px) and
(min-width: 600px), (min-width: 1100px) {
div.example {
font-size: 50px;
padding: 50px;
border: 8px solid black;
background: yellow;
}
}
ဆက်စပ်စာမျက်နှာများ
CSS ကျူတိုရီရယ်- CSS မီဒီယာမေးခွန်းများ
CSS ကျူတိုရီရယ်- CSS Media Queries နမူနာများ
RWD ကျူတိုရီရယ်- မီဒီယာမေးခွန်းများဖြင့် တုံ့ပြန်နိုင်သော ဝဘ်ဒီဇိုင်း
JavaScript ကျူတိုရီရယ်- window.matchMedia() နည်းလမ်း