Inhaltsverzeichnis
演示:12列布局
演示:表单ui
演示:表格
Heim Web-Frontend HTML-Tutorial Css3媒体查询使用_html/css_WEB-ITnose

Css3媒体查询使用_html/css_WEB-ITnose

Jun 21, 2016 am 08:56 AM

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;} }
Nach dem Login kopieren

在设备窗口宽度小于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>
Nach dem Login kopieren

流式布局,百分比赋值,多预设设置结合媒体查询。

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
1 Monate vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat -Befehle und wie man sie benutzt
1 Monate vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Was ist der Zweck des & lt; Fortschritts & gt; Element? Was ist der Zweck des & lt; Fortschritts & gt; Element? Mar 21, 2025 pm 12:34 PM

Der Artikel erörtert den HTML & lt; Progress & gt; Element, Absicht, Styling und Unterschiede vom & lt; Meter & gt; Element. Das Hauptaugenmerk liegt auf der Verwendung & lt; Fortschritt & gt; Für Aufgabenabschluss und & lt; Meter & gt; für stati

Was ist der Zweck des & lt; datalist & gt; Element? Was ist der Zweck des & lt; datalist & gt; Element? Mar 21, 2025 pm 12:33 PM

Der Artikel erörtert den HTML & lt; Datalist & gt; Element, das die Formulare verbessert, indem automatische Vorschläge bereitgestellt, die Benutzererfahrung verbessert und Fehler reduziert werden.Character Count: 159

Was sind die besten Praktiken für die Kompatibilität des Cross-Browsers in HTML5? Was sind die besten Praktiken für die Kompatibilität des Cross-Browsers in HTML5? Mar 17, 2025 pm 12:20 PM

In Artikel werden Best Practices zur Gewährleistung der HTML5-Cross-Browser-Kompatibilität erörtert und sich auf die Erkennung von Merkmalen, die progressive Verbesserung und die Testmethoden konzentriert.

Was ist der Zweck des & lt; Meter & gt; Element? Was ist der Zweck des & lt; Meter & gt; Element? Mar 21, 2025 pm 12:35 PM

Der Artikel erörtert das HTML & lt; Meter & gt; Element, verwendet zur Anzeige von Skalar- oder Bruchwerten innerhalb eines Bereichs und seine gemeinsamen Anwendungen in der Webentwicklung. Es differenziert & lt; Meter & gt; von & lt; Fortschritt & gt; und Ex

Wie verwende ich HTML5 -Formularvalidierungsattribute, um die Benutzereingabe zu validieren? Wie verwende ich HTML5 -Formularvalidierungsattribute, um die Benutzereingabe zu validieren? Mar 17, 2025 pm 12:27 PM

In dem Artikel werden unter Verwendung von HTML5 -Formularvalidierungsattributen wie Erforderlich, Muster, Min, MAX und Längengrenzen erörtert, um die Benutzereingabe direkt im Browser zu validieren.

Was ist das Ansichtsfenster -Meta -Tag? Warum ist es wichtig für reaktionsschnelles Design? Was ist das Ansichtsfenster -Meta -Tag? Warum ist es wichtig für reaktionsschnelles Design? Mar 20, 2025 pm 05:56 PM

In dem Artikel wird das Ansichtsfenster -Meta -Tag erörtert, das für das reaktionsschnelle Webdesign auf mobilen Geräten unerlässlich ist. Es wird erläutert, wie die ordnungsgemäße Verwendung eine optimale Skalierung von Inhalten und Benutzerinteraktion gewährleistet, während Missbrauch zu Design- und Zugänglichkeitsproblemen führen kann.

Was ist der Zweck des & lt; iframe & gt; Etikett? Was sind die Sicherheitsüberlegungen bei der Verwendung? Was ist der Zweck des & lt; iframe & gt; Etikett? Was sind die Sicherheitsüberlegungen bei der Verwendung? Mar 20, 2025 pm 06:05 PM

Der Artikel erörtert das & lt; iframe & gt; Der Zweck von Tag, externe Inhalte in Webseiten, seine gemeinsamen Verwendungen, Sicherheitsrisiken und Alternativen wie Objekt -Tags und APIs einzubetten.

Ist HTML für Anfänger leicht zu lernen? Ist HTML für Anfänger leicht zu lernen? Apr 07, 2025 am 12:11 AM

HTML ist für Anfänger geeignet, da es einfach und leicht zu lernen ist und schnell Ergebnisse sehen kann. 1) Die Lernkurve von HTML ist glatt und leicht zu beginnen. 2) Beherrschen Sie einfach die grundlegenden Tags, um Webseiten zu erstellen. 3) hohe Flexibilität und kann in Kombination mit CSS und JavaScript verwendet werden. 4) Reiche Lernressourcen und moderne Tools unterstützen den Lernprozess.

See all articles