CSS3 Media Queries实现响应式布局

时间:2022-12-29 16:07:07

概念我就不在这里写啦。大家可以看看以下网页:

http://www.runoob.com/cssref/css3-pr-mediaquery.html

http://www.w3cplus.com/content/css3-media-queries

以下是我做的一个小例子:

页面效果:

当页面宽度在320px到550px之间时:                                                          当页面宽度大于551px时

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcUAAADFCAIAAACq1H5nAAAL4klEQVR4nO2cPU8jyRZA+1f5DzhA4i8gCGc0IUgvcQIBEk4cIFbehAmGBJJZ7TbSDJJDJw5WskU00kqQPJEQTLwveoG/+qOq3eZefG9Pn6OjFRi7sbaoM9XltpP/AQCABon1EwAA+EWgpwAAOtBTAAAd6CkAgA70FABAB3oKAKADPQUA0MF7T7/+eEHElmjdGyn0FBG9aN0bKfQUEb1o3Rsp9BQRvWjdGyn0FBG9aN0bKfQUEb1o3Rsp9BQRvWjdGyn0FBG9aN0bKfQUEb1o3Rsp9BQRvWjdGyn0FBG9aN0bKfQUEb1o3Rsp9BR1vDhJkiRJusPrerdXeD3YS5IkSfaOxyrP7f4gSZIkObiz/7+E1Vr3Rgo9RR0vTooFvB7sJd3hce722XF3c9fmPe0MZusb73rFIN71kvqc3JefHjrUujdS6CnqmAnW7Li7WJNeDIYHJ+W8Zbo2Hna26OKmIM4ju81aGF1p3Rsp9BR1nPf04GSvM5jNz/Hny8ncwnDeu5P76kMF1qc/XuqsbVmENl3r3kihpyhxuRRd0e0ddPc63do9veslSe8if9hIT+8PAje+ZNo9O+4WYr3YOS0/Cn1q3Rsp9BR1LK1JF6f8x+Xz/UzyLgK7AYt1buycvxDH5YtXSZIknW7kUZtWxOhE695IoaeoY7mnm9eni83T7Bn6YkVZ2gO9Pwjc+PK1uJidr5dXC9750YrrX3SrdW+k0FPUcdHQwbCT9A6qe7rM4mJxWsxroYZJcnJ/PdiLZTHU09WvoKcN07o3Uugp6rg8c987Hpc2VQuUl5mrV/lXP1otXQe96tfrgz1dvmxFTxumdW+k0FOUmt3BXL8utFyTZs/9v971wq+/L9ate7lrp+YXjW53MUDh0n162jCteyOFnqLA1bpyccF84Hqm1e0V5+ylAy6bu746NfrAUE9XyaanDdO6N1LoKeq47mnhnUvL1EZP9ueWT/kXLndRI28YzfU0vANLTxujdW+k0FPUsbQ+zV0NutgTCMd0XcwgncH9fFc0eBnp/PfOf7T4LestgvAlq+hW695IoaeoY+B8f3V1VOC6qJzzDq4f+8a3jS5O9rPXrvIZKM3SujdS6CnqGNw/zbxUteltoJmt2FVPV+8FqLHGXF5UEHyzAO/ob4jWvZFCT1HHYE+zO6cVS8VldnsXd72kO7zOr0/XUY5mcX2lavFH681cdlEboHVvpNBTFJrb/VxFcxXBzBVUWYqv4HcGs+JGaraeubtlf/vqyPFcLh/Lub9/rXsjhZ6ihuNhJ0k6g2E2iIGT9MVqcd6+wnuZcocK7Q/cH2RuzKx8+UCpX0fr3kihp4joReveSKGniOhF695IoaeI6EXr3kihp4joReveSKGniOhF695IoaeI6EXr3kihp4joReveSKGniOhF695IoaeI6EXr3kihp4joReveSKGniOhF695IoaeI6EXr3kihp4joReveSPHe08e//0bElmjdGynee2r+DyYi7kzr3kihp4joReveSKGniOhF695IoaeI6EXr3kihp4joReveSKGniOhF695IoaeI6EXr3kihp4joReveSKGniOhF695IoaeI6EXr3khpUU9vps9n6eRwmO73b3E3Hv2enqWTm+kzw+TZNwwTPQ3Slp7eTJ8/fn64HE3HT6///PwXd+P46fVyNP1w/b3mXGWYGjFM9DRGW3p6lk4uR1PzP9x2ejWanaYThsm59YeJnsZoS0+PhilLHivHT6+Hw5Rhcm79YaKnMdrS0/3+rfnfa5vd798yTP6tOUz0NAY9RUcTlWFqxDDR0xj0FB1NVIapEcNET2PQU3Q0URmmRgwTPY1BT9HRRGWYGjFM9DQGPUVHE5VhasQw0dMY9BQdTVSGqRHDRE9j0FN0NFEZpkYMEz2NQU/R0URlmBoxTPQ0Bj3dgY/n/dv9/sO3n4/n/dtPf/03f+O/pW8LPwoeqs6vs5+f205Uet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WAYKIFgGCiBYBgogWAYKIFgGCiBYBgogWAYKIFgGCiBYBgogWAYP8HB+pBla5lrBUAAAAASUVORK5CYII=" alt="" width="542" height="196" />

1.html代码:

<template>
<div class="home">
<div class="home-body">
<div class="title"><h1>搜索页</h1></div>
<div class="head-home">
<template v-for='(index,project) in projectData'>
<div class="project " v-if='index>=projectData.length-3' v-on:click='searchProject(index)'>{{project.projectName}}</div>
</template>
</div>
</div>
</div>
</template>

2.style

<style scoped>
@media only screen and (min-width: 320px) and (max-width: 550px){
.home-body{
width:28em;
margin: % auto;
background-color:lightblue;
}
.project{
height: 3em;
line-height: 3em;
width: .75em;
border-radius: 4px;
text-align: center;
font-weight: bold;
cursor: pointer;
background-color: #DBEFF9;
border: 1px solid #4A88A7;
color: #4A88A7;
float: left;
margin: 1em .5em ;
}
.head-home,.type-home,.search-home,.project-all{
overflow: hidden;
margin:.5em 2em;
}
.title{
margin: % ;
padding: % ;
text-align: center;
border-bottom: 1px solid #D2CCCC;
}
}
@media only screen and (min-width: 551px) {
.home-body{
width:39em;
margin: % auto;
}
.project{
height: 3em;
line-height: 3em;
width: .75em;
border-radius: 4px;
text-align: center;
font-weight: bold;
cursor: pointer;
background-color: #DBEFF9;
border: 1px solid #4A88A7;
color: #4A88A7;
float: left;
margin: 1em .5em ;
}
.head-home,.type-home,.search-home,.project-all{
overflow: hidden;
margin:.5em 2em;
}
.title{
margin: % ;
padding: % ;
text-align: center;
border-bottom: 1px solid #D2CCCC;
}
}
</style>

CSS3 Media Queries实现响应式布局的更多相关文章

  1. HTML5实践 -- 使用CSS3 Media Queries实现响应式设计

    CSS3 Media用法介绍:http://www.w3cplus.com/content/css3-media-queries 转载请注明原创地址:http://www.cnblogs.com/so ...

  2. 【CSS3 入门教程系列】CSS3 Media Queries 实现响应式设计

    在 CSS2 中,你可以为不同的媒介设备(如屏幕.打印机)指定专用的样式表,而现在借助 CSS3 的 Media Queries 特性,可以更为有效的实现这个功能.你可以为媒介类型添加某些条件,检测设 ...

  3. CSS3 Media Queries 实现响应式设计

    在 CSS2 中,你可以为不同的媒介设备(如屏幕.打印机)指定专用的样式表,而现在借助 CSS3 的 Media Queries 特性,可以更为有效的实现这个功能.你可以为媒介类型添加某些条件,检测设 ...

  4. 怎样使用CSS3媒体查询&lpar;Media Queries&rpar;制作响应式网站

    自本周开始博主将开始同大家一起研究响应式web设计,CSS3 Media Queries是入门,本周更新,博主将给大家分享media queries的一些常用的用法及注意事项. Media Queri ...

  5. 让IE支持CSS3 Media Query实现响应式Web设计

    如今的屏幕分辨率,小至320px(iPhone),大到2560px甚至更高(大显示器),变化范围极大.除了使用传统的台式机,用户会越来越多的通过手机.上网本.iPad一类的平板设备来浏览页面.这种情况 ...

  6. 利用media query写响应式布局

    最近才接触到响应式布局的概念,之前用到的bootstrap就是一种响应式布局的框架.学习的时候参考了http://blog.csdn.net/shoyer/article/details/829301 ...

  7. CSS3 媒体查询&commat;media 查询(响应式布局)

    例:如果文档宽度小于 300 像素则修改背景颜色(background-color): @media screen and (max-width: 300px) { body { background ...

  8. 关于css3媒体查询和响应式布局

    响应式设计 响应式设计可根据所显示的屏幕大小而改变, 它呈现的每个屏幕看起来并不相同.按照可用的屏幕属性,响应式设计提供了 UI 的最佳效果. 例如,如果网站布局上有一个占据 25% 的屏幕宽度的侧边 ...

  9. css3 flex流动自适应响应式布局样式类

    1.再说css3 flex 一旦一个容器赋予了display:flex属性,将会有以下特点: 项目无法设置浮动. 列表的样式会被清除. 无法使用vertical-align设置垂直对齐方式. 目前互联 ...

随机推荐

  1. oracle杀用户建用户改密码脚本

    # ******************************** # * dba_oracle_awr.sh # ******************************** # Usage: ...

  2. Dojo的Gridx使用jsonrest需要注意的地方

    在使用gridx时,如果要使用jsonrest,主要的工作主要是在服务端,服务端在返回数据时,必须在返回头里添加Content-Range: 0-9/73 属性和值,其中0表示从第0条记录开始,9表示 ...

  3. 1Web语言:开始了解HTML

    HTML是hybertext markup language的缩写,用来告诉浏览器网页的结构和内容.HTML的所有工作都是关于结构的,而不是外观.CSS是级联样式表(Cascading Style S ...

  4. AxWindowsMediaPlayer创建、添加播放列表(C&num;)

    // 创见打开对话框对象实例            OpenFileDialog openFileDialog = new OpenFileDialog(); //设置为可以打开多个文件        ...

  5. &lbrack;转&rsqb;jquery中使用event&period;target的几点

    转自: http://www.cnblogs.com/12go/archive/2011/12/28/2304502.html 1.this和event.target的区别: js中事件是会冒泡的,所 ...

  6. mac安装破解的Navicat

    原文:https://www.jianshu.com/p/f42785e55b6b 原始文档没操作成功,折腾了一下午,后来在如下地址看的简洁版的,突然发现一句重要的话,豁然开朗. 原文链接:https ...

  7. JS中----this的指向和如何修改this的指向

    this this是js中的一个关键字,函数运行时自动生成的一个内部对象,只能在函数内部使用.我们要讨论的是 this 的指向. this就是函数运行时自动生成的一个内部对象 下面介绍一下几种情况下, ...

  8. Cmd控制台修改编码方法

    Cmd控制台修改编码方法 一.前言 在Unbuntu中用sqlite3-command-line操作sqlite3还好好的,到了windows下查询表内容时发现中文全部乱码了!马上想到sqlite3内 ...

  9. Redis之Set 集合

    Redis Set 集合 Set 就是一个集合,集合的概念就是一堆不重复值的组合.利用 Redis 提供的 Set 数据结构,可以存储一些集合性的数据. 比如在 微博应用中,可以将一个用户所有的关注人 ...

  10. mysql的启动,停止与重启

    启动mysql:方式一:sudo /etc/init.d/mysql start 方式二:sudo start mysql方式三:sudo service mysql start 停止mysql:方式 ...