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>
流式布局,百分比赋值,多预设设置结合媒体查询。

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools
