設置佈局Viewport的各類信息
一、width=device-width; 設置Viewport視口寬度等於設備寬度
二、initial-scale=1; 網頁默認縮放比爲1(網頁在手持設備上,不會進行默認縮放
三、minimum-scale=1 網頁最小縮放比爲1
四、maximum-scale=1 網頁最小大縮放比爲1
五、user-scalable=no 禁止用戶手動縮放網頁(ios10+ 的設備失效)css
在手機站及響應式網站的製做中,網頁必須添加下述Viewport的設置語句html
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
禁止設備將手機號、郵箱進行識別,取消點擊撥打電話等事件html5
<meta name="format-detection" content="telephone=no,email=no"/>
ios 添加到主屏幕時,WebAPP的標題ios
<meta name="apple-mobile-web-app-title" content="標題"/>
ios添加到主屏幕時,啓用WebAPP的全屏模式,刪除頂端地址欄和底部工具欄web
<meta name="apple-mobile-web-app-capable" content="yes"/>
ios 添加到主屏幕時,WebAPP的頂部狀態欄顏色:
black:黑色
white:白色
balck-translucent:黑色半透明。但設置爲半透明時網頁將充滿整個屏幕,頂部透明的狀態欄將蓋住網頁最上方一小條chrome
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
ios添加到主屏幕時WebAPP的圖標,href屬性爲圖標路徑瀏覽器
<link rel="apple-touch-icon-precomposed" href=""/>
設置瀏覽器使用最新的IE或chrome去編譯:
>>>這句設置語句不是手機端專用,通常pc網頁均需設置app
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
一、通常手機端不支持微軟雅黑字體
二、中文字體通常不設置,使用系統默認便可
三、英文字體通常設置爲font-family: helvetica;工具
font-family: helvetica;
一、手機端不能長按選擇
二、pc端不能用鼠標選擇佈局
-webkit-user-select: none; -moz-user-select: none;
設置表單的默認外觀,手機、 pc都可使用
appearance: none; -webkit-appearance: none; -moz-appearance: none;
設置placeholder的屬性
input::-webkit-input-placeholder { color: red; } input:-ms-input-placeholder { // IE10+ color: red; } input:-moz-placeholder { // Firefox4-18 color: red; } input::-moz-placeholder { // Firefox19+ color: red; }
禁止圖片和超連接長按彈出菜單
-webkit-appearance: none;
@media 類型(長選all/screen) and (條件1) and (條件2) {
CSS選擇器{
CSS屬性:屬性值;
}
}
<link rel="stylesheet" href="css/02響應式佈局.css" media="all and (max-width: 800px)"/>
@import url("css/02響應式佈局.css") all and (max-width: 800px);
容器:須要添加彈性佈局的父元素
項目:彈性佈局容器中的每個子元素,稱爲項目
①給父容器添加display:flex/inline-flex;屬性,便可使容器內容採用彈性佈局顯示,而不遵循常規文檔流的顯示方式
②容器添加彈性佈局後,僅僅是容器內容採用彈性佈局,而容器自身在文檔流中的定位方式依然遵循常規文檔流
③display:flex;容器添加彈性佈局後,顯示爲塊級元素
display:inline-flex;容器添加彈性佈局後,顯示爲行級元素
④注意,設爲 Flex 佈局之後,子元素的float、clear和vertical-align屬性將失效。可是position屬性依然生效。
②flex-wrap屬性定義,若是一條軸線排不下,如何換行
nowrap(默認):不換行。當容器寬度不夠時,每一個項目會被擠壓寬度
wrap:換行,而且第一行在容器最上方
wrap-reverse:換行,而且第一行在容器最下方
③ flex-flow 是flex-direction和flex-wrap的縮寫形式,默認值是row nowrap
④ justify-content屬性定義了項目在主軸上的對齊方式。
>>>此屬性與主軸方向息息相關:主軸方向爲:row-起點在左邊,row-reverse-起點在右邊,column-起點在上邊,column-reverse-起點在下邊
flex-start(默認值):項目位於主軸起點
flex-end:項目位於主軸終點
center: 居中
space-between:兩端對齊,項目之間的間隔都相等。(開頭和最後的項目,與父容器的邊緣沒有間隔)
space-around:每一個項目兩側的間隔相等。因此,項目之間的間隔比項目與邊框的間隔大一倍。(開頭和最後的項目,與父容器的邊緣有必定的間隔)
⑤ align-items屬性定義項目在交叉軸上如何對齊。
flex-start:交叉軸的起點對齊。
flex-end:交叉軸的終點對齊。
center:交叉軸的中點對齊。
baseline: 項目的第一行文字的基線對齊。(文字的行高、字體大小會影響每行的基線)
stretch(默認值):若是項目未設置高度或設爲auto,將佔滿整個容器的高度。
⑥align-content屬性定義了多根軸線的對齊方式。若是項目只有一根軸線,該屬性不起做用。
>>>當項目換爲多行時,可使用align-content取代align-items(單行時使用align-items,多行時使用align-content)
flex-start:與交叉軸的起點對齊。
flex-end:與交叉軸的終點對齊。
center:與交叉軸的中點對齊。
space-between:與交叉軸兩端對齊,軸線之間的間隔平均分佈。
space-around:每根軸線兩側的間隔都相等。因此,軸線之間的間隔比軸線與邊框的間隔大一倍。
stretch(默認值):軸線佔滿整個交叉軸。
① order屬性定義項目的排列順序。數值越小,排列越靠前,默認爲0。
② flex-grow屬性定義項目的放大比例,默認爲0,即若是存在剩餘空間,也不放大。
③ flex-shrink屬性定義了項目的縮小比例,默認爲1,即若是空間不足,該項目將縮小。
④ flex-basis定義項目佔據的主軸空間。(若是主軸爲水平,則設置這個屬性,至關於設置項目的寬度。原width會失效)
⑤ flex屬性是flex-grow, flex-shrink 和 flex-basis的簡寫,默認值爲0 1 auto。後兩個屬性可選。
這個屬性有兩個快捷設置: auto=(1 1 auto)/none(0 0 auto)
⑥ align-self:定義單個項目自身在交叉軸上的排列方式,能夠覆蓋掉容器上的align-item屬性
屬性值:與align-items相同,默認值爲auto,表示繼承父容器的align-items屬性值
HTML代碼:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="css/響應式佈局demo.css"/> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> </head> <body> <header id="header"> <ul> <li>header1</li> <li>header2</li> <li>header3</li> <li>header4</li> <li>header5</li> </ul> <div>icon</div> </header> <section id="main"> <div class="left">left</div> <div class="center">center</div> <div class="right">right</div> </section> <footer id="foot"> footer </footer> </body> </html>
CSS代碼
*{ margin: 0px; padding: 0px; font-size: 48px; text-align: center; box-sizing: border-box; } #header, #main, #foot{ height: 100px; width: 1200px; background-color: chocolate; line-height: 100px; margin: 0 auto; min-width: 300px; } #header ul{ width: 80%; } #header ul li{ float: left; width: 20%; list-style: none; font-size: 20px; } #header div{ width: 50px; height: 50px; background-color: yellow; float: right; line-height: 50px; font-size: 20px; margin-top: 25px; margin-right: 25px; display: none; } #main{ height: 500px; line-height: 500px; border-bottom: 10px solid white; border-top: 10px solid white; } #main .left{ width: 25%; height: 500px; background-color: darkcyan; float: left; } #main .center{ width: 50%; height: 500px; background-color: navajowhite; float: left; border-left: 10px solid white; border-right: 10px solid white; } #main .right{ width: 25%; height: 500px; background-color: salmon; float: left; } @media screen and (max-width: 1200px) { #header, #main, #foot{ width: 100%; } } @media only screen and (max-width: 900px) { #main .right{ display: none; } #main .left{ width: 35%; } #main .center{ width: 65%; border-right: hidden; } } @media only screen and (max-width: 600px) { #header ul{ display: none; } #header div{ display: block; } #main{ height: 920px; } #main .left{ float: none; width: 100%; height: 250px; line-height: 250px; } #main .center{ float: none; width: 100%; height: 400px; line-height: 400px; border-left: hidden; border-top: 10px solid white; border-bottom: 10px solid white; } #main .right{ display: block; float: none; width: 100%; height: 250px; line-height: 250px; } }
顯示效果: