JS 响应式布局
1、media
效果为屏幕宽度变化时,背景颜色也变化
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
@media screen and (max-width: 1024px){
.bg{
background-color: aqua;
}
}
@media screen and (max-width: 980px) {
.bg {
background-color: red;
} }
@media screen and (max-width: 720px) {
.bg {
background-color: yellow;
} } @media screen and (max-width: 640px) {
.bg {
background-color: green;
} } @media screen and (max-width: 320px) {
.bg {
background-color: darkgray;
} }
</style>
</head>
<body class="bg"> </body>
</html>
2. 弹性图片
样式如下面的code
.img 和 img
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
@media screen and (max-width: 1024px){
.bg{
background-color: aqua;
}
}
@media screen and (max-width: 980px) {
.bg {
background-color: red;
} /*使用流体图片*/
img {
max-width: 100%;
height: auto;
width: auto\9; /* ie8 */
position: absolute;
width:600px;
top:-25%;
} .img{
height: 200px;
border:1px solid sandybrown;
overflow:hidden;
margin-bottom:10px;
display: block;
position: relative;
} }
@media screen and (max-width: 720px) {
.bg {
background-color: yellow;
} } @media screen and (max-width: 640px) {
.bg {
background-color: green;
} } @media screen and (max-width: 320px) {
.bg {
background-color: darkgray;
} }
</style>
</head>
<body class="bg">
<div style="margin-top: 300px" class="img">
<img src="data:image/img1.jpg" />
</div>
</body>
</html>
JS 响应式布局的更多相关文章
- rem+js响应式布局的设置
直接调用代码即可,不过不同屏幕宽度要求会不同,相应修改一下就ok了 // rem响应式布局 (function(){ var html=document.querySelector('html') h ...
- js响应式布局
<!DOCTYPE html> <html class="mobile"> <head> <meta charset="UTF- ...
- HTML5 respond.js 解决IE6~8的响应式布局问题
HTML5 respond.js 解决IE6~8的响应式布局问题 响 应式布局,理想状态是,对PC/移动各种终端进行响应.媒体查询的支持程度是IE9+以及其他现代的浏览器,但是IE8在市场当中仍然 ...
- 理解rem实现响应式布局原理及js动态计算rem
前言 移动端布局中,童鞋们会使用到rem作为css单位进行不同手机屏幕大小上的适配.那么来讲讲rem在其中起的作用和如何动态设置rem的值. 1.什么是rem rem是相对于根元素(html标签)的字 ...
- 利用JS去做响应式布局
利用JS去做响应式布局 js动态改变布局方式 // 取浏览器可视区高宽 var lw = $(window).width(); var lh = $(window).height();// 页面加载完 ...
- 另外一款超棒的响应式布局jQuery插件 – Freetile.js
在线演示 我们曾经介绍过俩款知名的响应式布局插:isotope和masonary,今天我们这里再介绍一款相当不错的响应式布局插件 – Freetile.js,使用它同样可以生成超酷的动态布局效果.相信 ...
- 用JS更好的实现响应式布局
响应式布局更加高效的方法: 代码实现 <script> $(function() { (function(){ var $html = $('html'); var $window = $ ...
- CSS3移动端vw+rem不依赖JS实现响应式布局
1.前言 (1)vw/vh介绍 在使用之前,我们先简单了解一下什么是vw和rem以及它们的作用,vw是css3出现的一个新单位,它是"view width"缩写,定义为把当前屏幕分 ...
- 一步步开发自己的博客 .NET版 剧终篇(6、响应式布局 和 自定义样式)
前言 这次开发的博客主要功能或特点: 第一:可以兼容各终端,特别是手机端. 第二:到时会用到大量html5,炫啊. 第三:导入博客园的精华文章,并做分类.(不要封我) 第四:做 ...
随机推荐
- OC 内存管理之手动内存管理MRC
一.基本原理 1.什么是内存管理 内存管理的重要性: 移动设备的内存极其有限,每个app所能占用的内存是有限制的 当app所占用的内存较多时,系统会发出内存警告,这时得回收一些不需要再使用的内存空间. ...
- web前端切图处理
技巧: 一. 如何在 Retina 屏幕的设备使用更高分辨率的图片 以 MacBook Pro 为例,它的标准分辨率高达 2560 x 1600,但是如果真的以这个分辨率显示网页,网页的有效区域就小的 ...
- jQuery 插件运行机制和 $冲突解决
1.jQuery.fn.extend(object) 基本插件假设我们要创建一个插件,使一组元素中的文本变为绿色.我们要做的就是添加一个名为greenify的函数, $.fn 将像其他任何jquery ...
- learning uboot bootargs panic parameter
By passing the kernel panic parameter, the system automatically resets after 3 seconds when kernel p ...
- bzoj3946
题解: 树套树 treap+线段树 treap就把线段树上的节点弄一下 然后修改的时候 把中间的一段一起加 把两头重新计算(二分+hash) 代码: #include<bits/stdc++.h ...
- Arithmometer: A Node.js implementation
Foreword: This project is a part of pair programming task. We implement an command-line based arithm ...
- 集成学习之Boosting —— XGBoost
集成学习之Boosting -- AdaBoost 集成学习之Boosting -- Gradient Boosting 集成学习之Boosting -- XGBoost Gradient Boost ...
- Final阶段第1周/共1周 Scrum立会报告+燃尽图 04
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2483] 版本控制:https://git.coding.net/liuyy08 ...
- Ubuntu下安装、卸载notepad++
Ubuntu下的安装方法: sudo add-apt-repository ppa:notepadqq-team/notepadqq sudo apt-get update sudo apt-get ...
- Pycharm下tensorflow导入错误
问题: ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory 解决方案: L ...