CSS網(wǎng)頁(yè)響應(yīng)式布局實(shí)現(xiàn)自動(dòng)適配Pc/Pad/Phone設(shè)備

前言
現(xiàn)在的設(shè)備很多,有PC、iPad、手機(jī)、智能手表、智能電視。如果沒(méi)有響應(yīng)式布局,那么電腦網(wǎng)頁(yè)在手機(jī)或者ipad上顯示,是體驗(yàn)非常差,操作不方便,視覺(jué)疲勞的,所以我們開(kāi)發(fā)網(wǎng)頁(yè)要做好響應(yīng)式布局。
index
<!DOCTYPE html> <html> <head> <title>響應(yīng)式布局</title> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div id="content"> <div id="header">頭部</div> <div id="left">左側(cè)</div> <div id="center">中間</div> <div id="right">右側(cè)</div> <div id="footer">底部</div> </div> </body> </html>
CSS
*{ margin: 0; padding: 0; } /*適應(yīng)PC端 寬度大于1000px*/ @media screen and (min-width: 1000px) { #content{ width: 960px; margin:0 auto; } #header{ width: 100%; line-height: 100px; float: left; background: #333; color: #fff; text-align: center; font-size: 30px; margin-bottom: 10px; } #left{ width: 200px; line-height: 400px; text-align: center; background: #333; float: left; font-size: 30px; color: #fff; margin-right: 10px; } #center{ width: 540px; line-height: 400px; text-align: center; background: #333; float: left; font-size: 30px; color: #fff; } #right{ width: 200px; line-height: 400px; text-align: center; background: #333; float: right; font-size: 30px; color: #fff; } #footer{ width: 960px; height: 200px; background: #333; color: #fff; line-height: 200px; font-size: 30px; text-align: center; float: left; margin-top: 10px; } } /*適應(yīng)pad端 寬度在640-1000之間*/ @media screen and (min-width: 640px) and (max-width: 1000px) { #content{ width: 600px; margin:0 auto; } #header{ width: 100%; line-height: 100px; float: left; background: #333; color: #fff; text-align: center; font-size: 30px; margin-bottom: 10px; } #left{ width: 200px; line-height: 400px; text-align: center; background: #333; float: left; font-size: 30px; color: #fff; margin-right: 10px; } #center{ width: 390px; line-height: 400px; text-align: center; background: #333; float: left; font-size: 30px; color: #fff; } #right{ width: 600px; line-height: 300px; text-align: center; background: #333; float: left; font-size: 30px; color: #fff; margin-top: 10px; } #footer{ width: 600px; height: 200px; background: #333; color: #fff; line-height: 200px; font-size: 30px; text-align: center; float: left; margin-top: 10px; } } /*適應(yīng)移動(dòng)端 寬度小于640*/ @media screen and (max-width: 639px){ #content{ width: 400px; margin:0 auto; } #header{ width: 100%; line-height: 100px; float: left; background: #333; color: #fff; text-align: center; font-size: 30px; margin-bottom: 10px; } #left{ width: 100%; line-height: 150px; text-align: center; background: #333; float: left; font-size: 30px; color: #fff; margin-bottom: 10px; } #center{ width: 100%; line-height: 300px; text-align: center; background: #333; float: left; font-size: 30px; color: #fff; } #right{ width: 100%; line-height: 150px; text-align: center; background: #333; float: left; font-size: 30px; color: #fff; margin-top: 10px; } #footer{ width: 100%; height: 200px; background: #333; color: #fff; line-height: 200px; font-size: 30px; text-align: center; float: left; margin-top: 10px; } }
通過(guò)@media screen and (限制范圍) 來(lái)控制網(wǎng)頁(yè)的布局,例如
min-width代表最小的限制,max-width代表最大的限制。
PC端
Pad端
Phone端
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
CSS像素以及移動(dòng)端不同屏幕適配問(wèn)題解決
這篇文章主要介紹了CSS像素以及移動(dòng)端不同屏幕適配問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)2020-01-13postcss-pxtorem移動(dòng)端適配的實(shí)現(xiàn)
這篇文章主要介紹了postcss-pxtorem移動(dòng)端適配的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)2019-12-03css列表滑動(dòng)防止被底部遮住和適配屏幕長(zhǎng)一點(diǎn)的機(jī)型處理
這篇文章主要介紹了css列表滑動(dòng)防止被底部遮住和適配屏幕長(zhǎng)一點(diǎn)的機(jī)型處理 ,需要的朋友可以參考下2019-07-09CSS3中媒體查詢(xún)結(jié)合rem布局適配手機(jī)屏幕
這篇文章主要介紹了css3中媒體查詢(xún)結(jié)合rem布局適配手機(jī)屏幕,需要的朋友可以參考下2019-06-10- 這篇文章主要介紹了手機(jī)端用rem+scss做適配的詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-15
通過(guò)CSS3的object-fit來(lái)調(diào)整圖片適配尺寸的技巧簡(jiǎn)介
這篇文章主要介紹了通過(guò)CSS3的object-fit來(lái)調(diào)整圖片適配尺寸的技巧,包括用object-fit來(lái)居中并裁剪圖片的方法,需要的朋友可以參考下2016-02-27- 在需要調(diào)整設(shè)備瀏覽器的viewport時(shí),我們通常在HTML中使用來(lái)解決。但是令人意想不到的是,viewport meta標(biāo)簽并不具有“規(guī)范性”,即它不是W3C的正式標(biāo)準(zhǔn),也非Web標(biāo)準(zhǔn)2013-11-10