媒體查詢
最近在研究響應式web頁面設計,入門級media queries ,即媒體查詢,媒體查詢在css3中引入,作用是允許設定表達式檢查媒體環境,用來確定應用不同的樣式。
媒體查詢應用的兩種方式
一.在引入樣式表的時候判斷媒體尺寸,根據尺寸引入不同的樣式表,如下
<link rel="stylesheet" type="text/css" href="A.css" media="screen and (max-width: 620px)">
表示當媒體分表率小於620像素時,應用A樣式表(像素只是媒體查詢的其中一種類型)
and 爲關鍵字
<link rel="stylesheet" type="text/css" href="B.css" media="screen and (min-width: 621px) and (max-width: 980px)">
上面這個link表示 當媒體像素在621像素到980像素之間時,應用B樣式表
二.就是直接在樣式表中寫媒體查詢的樣式
@media screen and (max-width: 620px) { /*當屏幕尺寸小於620px時,應用下面的CSS樣式*/
.class {
background: red;
}
}
媒體查詢就是用來查詢媒體環境,在web中就是對像素條件的查詢,用以控制在不同分辨率的設備上顯示不同的樣式。
字體
body {
margin: 0;
padding: 0;
font-size: 14px;
}
.head {
padding: 10px;
max-width: 1000px;
margin: 0 auto;
background-color: blue;
color: white;
font-size: 1.14em;
}
.left {
background-color: red;
float: left;
width: 40%;
}
.right {
margin-bottom: 10px;
background-color: yellow;
float: right;
width: 50%;
}
.bot {
margin: 0 auto;
background-color: gray;
clear: both;
width: 50%;
}
@media screen and (max-width :600px) {
.bot {
display: none;
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="style/style.css" rel="stylesheet" />
</head>
<body>
<div class="head">
<div class="left">
5月18日,國家主席習近平在上海會見柬埔寨首相洪森。 新華社記者 蘭紅光 攝
習近平表示,中
</div>
<div class="right">
5月18日,國家主席習近平在上海會見柬埔寨首相洪森。 新華社記者 蘭紅光 攝
習近平表示,中柬友誼源遠流長,歷經風雨考驗而不動搖,彌足珍貴。無論國際形勢如何變化,我們一定要堅定不移推動中柬全面戰略合作伙伴關係發展,把中柬友好事業堅定不移推進下去,讓兩國和兩國人民世世代
代友好下去。
</div>
<div class="bot">
5月18日,國家主席習近平在上海會見柬埔寨首相洪森。 新華社記者 蘭紅光 攝
習近平表示,中柬友誼源遠流長,歷經風雨考驗而不動搖,彌足珍貴。無論國際形勢如何變化,我們一定要堅定不移推動中柬全面戰略合作伙伴關係發展,把中柬友好事業堅定不移推進下去,讓兩國和兩國人民世世代
代友好下去。
</div>
</div>
</body>
</html>