css3媒体查询技术的出现,在多设备支持上为我们提供了解决方案。
媒体查询的使用方法:
@media screen and (max-width: 480px) { .col-xs-1{width: 8.333333333333332%; float:left;} .col-xs-2{ width: 16.666666666666664%; float:left;} .col-xs-3{ width: 25%; float:left;} }
在设备窗口宽度小于480时,下面的样式会被采用,不满足这个查询设置,下面定义的css是无效的,html根本就不会识别到。
简单理解就是,如果当前宽度是1000,那么就是div上有类名.col-xs-1,div还是只是简单块元素(不会浮动和宽为百分比),查询的设置是不起作用的。
充分利用媒体查询,实现多设备支持的框架当前最热门就是bootstrap了,我们可以学习和使用它进行开发。
下面是我自己利用媒体查询写的实例页面,都是常用css布局方式配合了媒体查询,多的就不做解释了,一句话就是写法都是css里面,看看就能懂:
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>media/媒体查询/简易UI</title> <!--设备设置--> <meta name="viewport" content="width=device-width;initial-scale=1.0"> <!--渲染ie内核--> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <style> /*========================全局样式============================*/ *{ margin:0; padding:0;} html{height:100%;} body{height:100%; font-size:16px; font-family:"微软雅黑";} a{ text-decoration:none;} img{ border:none;} ul{ list-style:none;} /*========================预定义样式==========================*/ /*通用*/ .left{float:left;} .right{float:right;} .clear{clear:both;} .clearfix:after{ content:"."; display:block; height:0; clear:both; overflow:hidden;} .clearfix{ zoom:1;} /*12列布局*/ .row:after{ content:"."; display:block; height:0; clear:both; overflow:hidden;} @media screen and (max-width: 480px) { .col-xs-1{width: 8.333333333333332%; float:left;} .col-xs-2{ width: 16.666666666666664%; float:left;} .col-xs-3{ width: 25%; float:left;} .col-xs-4{ width: 33.33333333333333%; float:left;} .col-xs-5{width: 41.66666666666667%; float:left;} .col-xs-6{width: 50%; float:left;} .col-xs-7{ width: 58.333333333333336%; float:left;} .col-xs-8{width: 66.66666666666666%; float:left;} .col-xs-9{width: 75%; float:left;} .col-xs-10{width: 83.33333333333334%; float:left;} .col-xs-11{ width: 91.66666666666666%; float:left;} .col-xs-12{ width:100%; float:left;} .col-xs-mar-1{ margin-left: 8.333333333333332%; margin-right: 8.333333333333332%;} .col-xs-mar-2{ margin-left:16.666666666666664%; margin-right:16.666666666666664%;} .col-xs-mar-3{margin-left:25%; margin-right:25%;} .col-xs-mar-4{margin-left:33.33333333333333%; margin-right:33.33333333333333%;} .col-xs-mar-5{margin-left:41.66666666666667%; margin-right:41.66666666666667%;} .col-xs-mar-6{margin-left:50%; margin-right:50%;} .col-xs-mar-7{ margin-left:58.333333333333336%; margin-right:58.333333333333336%;} .col-xs-mar-8{ margin-left:66.66666666666666%; margin-right:66.66666666666666%;} .col-xs-mar-9{margin-left:75%; margin-right:75%;} .col-xs-mar-10{margin-left:83.33333333333334%; margin-right:83.33333333333334%;} .col-xs-mar-11{margin-left:91.66666666666666%; margin-right:91.66666666666666%;} } @media screen and (min-width: 481px) and (max-width: 768px) { .col-sm-1{ width: 8.333333333333332%; float:left;} .col-sm-2{ width:16.666666666666664%; float:left;} .col-sm-3{ width:25%; float:left;} .col-sm-4{ width:33.33333333333333%; float:left;} .col-sm-5{ width:41.66666666666667%; float:left;} .col-sm-6{ width:50%; float:left;} .col-sm-7{ width:58.333333333333336%; float:left;} .col-sm-8{ width:66.66666666666666%; float:left;} .col-sm-9{ width:75%; float:left;} .col-sm-10{ width:83.33333333333334%; float:left;} .col-sm-11{ width:91.66666666666666%; float:left;} .col-sm-12{ width:100%; float:left;} .col-sm-mar-1{ margin-left: 8.333333333333332%; margin-right: 8.333333333333332%;} .col-sm-mar-2{ margin-left:16.666666666666664%; margin-right:16.666666666666664%;} .col-sm-mar-3{margin-left:25%; margin-right:25%;} .col-sm-mar-4{margin-left:33.33333333333333%; margin-right:33.33333333333333%;} .col-sm-mar-5{margin-left:41.66666666666667%; margin-right:41.66666666666667%;} .col-sm-mar-6{margin-left:50%; margin-right:50%;} .col-sm-mar-7{margin-left:58.333333333333336%; margin-right:58.333333333333336%;} .col-sm-mar-8{margin-left:66.66666666666666%; margin-right:66.66666666666666%;} .col-sm-mar-9{margin-left:75%; margin-right:75%;} .col-sm-mar-10{margin-left:83.33333333333334%; margin-right:83.33333333333334%;} .col-sm-mar-11{margin-left:91.66666666666666%; margin-right:91.66666666666666%;} } @media screen and (min-width: 769px) and (max-width: 992px) { .col-md-1{ width: 8.333333333333332%; float:left;} .col-md-2{ width:16.666666666666664%; float:left;} .col-md-3{ width:25%; float:left;} .col-md-4{ width:33.33333333333333%; float:left;} .col-md-5{ width:41.66666666666667%; float:left;} .col-md-6{ width:50%; float:left;} .col-md-7{ width:58.333333333333336%; float:left;} .col-md-8{ width:66.66666666666666%; float:left;} .col-md-9{ width:75%; float:left;} .col-md-10{ width:83.33333333333334%; float:left;} .col-md-11{ width:91.66666666666666%; float:left;} .col-md-12{ width:100%; float:left;} .col-md-mar-1{ margin-left: 8.333333333333332%; margin-right: 8.333333333333332%;} .col-md-mar-2{ margin-left:16.666666666666664%; margin-right:16.666666666666664%;} .col-md-mar-3{margin-left:25%; margin-right:25%;} .col-md-mar-4{margin-left:33.33333333333333%; margin-right:33.33333333333333%;} .col-md-mar-5{margin-left:41.66666666666667%; margin-right:41.66666666666667%;} .col-md-mar-6{margin-left:50%; margin-right:50%;} .col-md-mar-7{margin-left:58.333333333333336%; margin-right:58.333333333333336%;} .col-md-mar-8{margin-left:66.66666666666666%; margin-right:66.66666666666666%;} .col-md-mar-9{margin-left:75%; margin-right:75%;} .col-md-mar-10{margin-left:83.33333333333334%; margin-right:83.33333333333334%;} .col-md-mar-11{margin-left:91.66666666666666%; margin-right:91.66666666666666%;} } @media screen and (min-width: 993px) and (max-width: 1200px) { .container{ width:900px; margin:0 auto;} .col-lg-1{ width: 8.333333333333332%; float:left;} .col-lg-2{ width:16.666666666666664%; float:left;} .col-lg-3{ width:25%; float:left;} .col-lg-4{ width:33.33333333333333%; float:left;} .col-lg-5{ width:41.66666666666667%; float:left;} .col-lg-6{ width:50%; float:left;} .col-lg-7{ width:58.333333333333336%; float:left;} .col-lg-8{ width:66.66666666666666%; float:left;} .col-lg-9{ width:75%; float:left;} .col-lg-10{ width:83.33333333333334%; float:left;} .col-lg-11{ width:91.66666666666666%; float:left;} .col-lg-12{ width:100%; float:left;} .col-lg-mar-1{ margin-left: 8.333333333333332%; margin-right: 8.333333333333332%;} .col-lg-mar-2{ margin-left:16.666666666666664%; margin-right:16.666666666666664%;} .col-lg-mar-3{margin-left:25%; margin-right:25%;} .col-lg-mar-4{margin-left:33.33333333333333%; margin-right:33.33333333333333%;} .col-lg-mar-5{margin-left:41.66666666666667%; margin-right:41.66666666666667%;} .col-lg-mar-6{margin-left:50%; margin-right:50%;} .col-lg-mar-7{margin-left:58.333333333333336%; margin-right:58.333333333333336%;} .col-lg-mar-8{margin-left:66.66666666666666%; margin-right:66.66666666666666%;} .col-lg-mar-9{margin-left:75%; margin-right:75%;} .col-lg-mar-10{margin-left:83.33333333333334%; margin-right:83.33333333333334%;} .col-lg-mar-11{margin-left:91.66666666666666%; margin-right:91.66666666666666%;} } @media screen and (min-width: 1201px) { .container{ width:1100px; margin:0 auto;} .col-xs-max-1{ width: 8.333333333333332%; float:left;} .col-xs-max-2{ width:16.666666666666664%; float:left;} .col-xs-max-3{ width:25%; float:left;} .col-xs-max-4{ width:33.33333333333333%; float:left;} .col-xs-max-5{ width:41.66666666666667%; float:left;} .col-xs-max-6{ width:50%; float:left;} .col-xs-max-7{ width:58.333333333333336%; float:left;} .col-xs-max-8{ width:66.66666666666666%; float:left;} .col-xs-max-9{ width:75%; float:left;} .col-xs-max-10{ width:83.33333333333334%; float:left;} .col-xs-max-11{ width:91.66666666666666%; float:left;} .col-xs-max-12{ width:100%; float:left;} .col-xs-max-mar-1{ margin-left: 8.333333333333332%; margin-right: 8.333333333333332%;} .col-xs-max-mar-2{ margin-left:16.666666666666664%; margin-right:16.666666666666664%;} .col-xs-max-mar-3{margin-left:25%; margin-right:25%;} .col-xs-max-mar-4{margin-left:33.33333333333333%; margin-right:33.33333333333333%;} .col-xs-max-mar-5{margin-left:41.66666666666667%; margin-right:41.66666666666667%;} .col-xs-max-mar-6{margin-left:50%; margin-right:50%;} .col-xs-max-mar-7{margin-left:58.333333333333336%; margin-right:58.333333333333336%;} .col-xs-max-mar-8{margin-left:66.66666666666666%; margin-right:66.66666666666666%;} .col-xs-max-mar-9{margin-left:75%; margin-right:75%;} .col-xs-max-mar-10{margin-left:83.33333333333334%; margin-right:83.33333333333334%;} .col-xs-max-mar-11{margin-left:91.66666666666666%; margin-right:91.66666666666666%;} } /*ui细化*/ .width-10{ width:10px;} .width-50{ width:50px;} .width-100{ width:100px;} .width-150{ width:150px;} .width-200{ width:200px;} .border-normal{ background:#999; border:none; margin:10px 10%; display:block; border-radius:10px; height:50px; line-height:40px; color:#fff; text-align:center; width:80%; font-size:18px; cursor:pointer;} .border-success{background:#0C6;border:none;margin:10px 10%;display:block; border-radius:10px;height:50px; line-height:40px; color:#fff; text-align:center;width:80%; font-size:18px; cursor:pointer;} .border-err{background:#F33;border:none;margin:10px 10%;display:block; border-radius:10px;height:50px; line-height:40px; color:#fff; text-align:center;width:80%; font-size:18px; cursor:pointer;} .table-normal{ width:100%; margin:10px 0px; border-collapse:collapse;} .table-normal td{ border:1px solid #999; padding:5px;} .table-radius{ width:100%; margin:10px 0px; border-spacing:0px;border-right:1px solid #999;border-bottom:1px solid #999;border-radius:10px;} .table-radius td{ border-top:1px solid #999;border-left:1px solid #999; padding:5px;} .table-radius tr td:last-child{} .table-radius tr:last-child td{} .table-radius tr:first-child td:first-child{border-radius:10px 0 0 0;} .table-radius tr:first-child td:last-child{border-radius:0 10px 0 0;} .table-radius tr:last-child td:first-child{border-radius:0 0 0 10px;} /*=========================自定义样式===========================*/ #size{ height:50px; line-height:50px; text-align:center; font-weight:bold; font-size:20px; margin:50px; border-bottom:5px solid #09F;} .col{ margin:20px 0; background:#0CF; box-sizing:border-box; border:2px solid #993;} .col2{background:#C30; box-sizing:border-box; border:2px solid #0CF;height:50px;} </style></head><body> <div id="size">测试窗口大小当前为<span id="sizeval">0</span>px</div> <h3 id="演示-列布局">演示:12列布局</h3> <div class="container"> <div class="row"> <div class="col col-md-5 col-lg-3 col-lg-mar-2 col-xs-max-2 col-xs-max-mar-1">1</div> <div class="col col-md-5 col-lg-3 col-xs-max-2">2</div> <div class="col col-md-5 col-lg-3 col-lg-mar-2 col-xs-max-2">3</div> <div class="col col-md-5 col-lg-3 col-xs-max-2"> <div class="row"> <div class="col2 col-md-5 col-lg-3 col-lg-mar-2 col-xs-max-2">3-1</div> <div class="col2 col-md-5 col-lg-3 col-lg-mar-2 col-xs-max-2">3-2</div> </div> </div> <div class="col col-md-12 col-lg-6 col-xs-max-12">4</div> <div class="col col-md-8 col-lg-6 col-xs-max-3">5</div> <div class="col col-md-4 col-lg-6 col-xs-max-3">6</div> <div class="col col-md-4 col-lg-6 col-xs-max-6">7</div> </div> </div> <h3 id="演示-表单ui">演示:表单ui</h3> <div class="container"> <input type="button" class="border-normal" value="提交"> <input type="button" class="border-success" value="提交"> <input type="button" class="border-err" value="提交"> </div> <h3 id="演示-表格">演示:表格</h3> <div class="container"> <table class="table-normal"> <tr><td>1</td><td>1</td><td>1</td></tr> <tr><td>2</td><td>2</td><td>2</td></tr> <tr><td>3</td><td>3</td><td>3</td></tr> </table> <table class="table-radius"> <tr><td>1</td><td>1</td><td>1</td></tr> <tr><td>2</td><td>2</td><td>2</td></tr> <tr><td>3</td><td>3</td><td>3</td></tr> </table> </div> </body><script>var size=document.getElementById("size");var sizeval=document.getElementById("sizeval");sizeval.innerHTML=document.documentElement.offsetWidth;window.onresize=function(){ sizeval.innerHTML=document.documentElement.offsetWidth;};</script></html>
流式布局,百分比赋值,多预设设置结合媒体查询。

HTML、CSS和JavaScript在網頁開發中的角色分別是:HTML負責內容結構,CSS負責樣式,JavaScript負責動態行為。 1.HTML通過標籤定義網頁結構和內容,確保語義化。 2.CSS通過選擇器和屬性控製網頁樣式,使其美觀易讀。 3.JavaScript通過腳本控製網頁行為,實現動態和交互功能。

HTMLISNOTAPROGRAMMENGUAGE; ITISAMARKUMARKUPLAGUAGE.1)htmlStructures andFormatSwebContentusingtags.2)itworkswithcsssforstylingandjavascript for Interactivity,增強WebevebDevelopment。

HTML是構建網頁結構的基石。 1.HTML定義內容結構和語義,使用、、等標籤。 2.提供語義化標記,如、、等,提升SEO效果。 3.通過標籤實現用戶交互,需注意表單驗證。 4.使用、等高級元素結合JavaScript實現動態效果。 5.常見錯誤包括標籤未閉合和屬性值未加引號,需使用驗證工具。 6.優化策略包括減少HTTP請求、壓縮HTML、使用語義化標籤等。

HTML是一種用於構建網頁的語言,通過標籤和屬性定義網頁結構和內容。 1)HTML通過標籤組織文檔結構,如、。 2)瀏覽器解析HTML構建DOM並渲染網頁。 3)HTML5的新特性如、、增強了多媒體功能。 4)常見錯誤包括標籤未閉合和屬性值未加引號。 5)優化建議包括使用語義化標籤和減少文件大小。

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

HTML的作用是通過標籤和屬性定義網頁的結構和內容。 1.HTML通過到、等標籤組織內容,使其易於閱讀和理解。 2.使用語義化標籤如、等增強可訪問性和SEO。 3.優化HTML代碼可以提高網頁加載速度和用戶體驗。

htmlisaspecifictypefodyfocusedonstructuringwebcontent,而“代碼” badlyLyCludEslanguagesLikeLikejavascriptandPytyPythonForFunctionality.1)htmldefineswebpagertuctureduseTags.2)“代碼”代碼“ code” code code code codeSpassSesseseseseseseseAwiderRangeLangeLangeforLageforLogageforLogicIctInterract

HTML、CSS和JavaScript是Web開發的三大支柱。 1.HTML定義網頁結構,使用標籤如、等。 2.CSS控製網頁樣式,使用選擇器和屬性如color、font-size等。 3.JavaScript實現動態效果和交互,通過事件監聽和DOM操作。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

Dreamweaver CS6
視覺化網頁開發工具

禪工作室 13.0.1
強大的PHP整合開發環境

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。