CSS3 Media Queries实现响应式布局

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

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+f205UetqIYaKnMejpe/t43r89n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AYKIFgGCiBYBgogWAYKIFgGCiBYBgogWAYP8HB+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>
上一篇:tinkpad e450c 进入 BIOS


下一篇:nginx: worker process is shutting down