设定网页最小最大宽度和高度(兼容IE6)
http://www.cnblogs.com/double-bin/archive/2011/12/19/2293093.html
/* 最小寬度 */
.min_width{min-width:300px;
/* sets max-width for IE */
_width:expression(document.body.clientWidth < 300 ? "300px" : "auto");
}
/* 最大寬度 */
.max_width{
max-width:600px;
/* sets max-width for IE */
_width:expression(document.body.clientWidth > 600 ? "600px" : "auto");
}
/* 最小高度 */
.min_height{
min-height:200px;
/* sets min-height for IE */
_height:expression(this.scrollHeight < 200 ? "200px" : "auto");
}
/* 最大高度 */
.max_height{
max-height:400px;
/* sets max-height for IE */
_height:expression(this.scrollHeight > 400 ? "400px" : "auto");
}
/* 最大最小寬度 */
.min_and_max_width{
min-width:300px;
max-width:600px;
/* sets min-width & max-width for IE */
_width: expression(
document.body.clientWidth < 300 ? "300px" :
( document.body.clientWidth > 600 ? "600px" : "auto")
);
}
/* 最大最小高度 */
.min_and_max_height{
min-height:200px;
max-height:400px;
/* sets min-height & max-height for IE */
_height: expression(
this.scrollHeight < 200 ? "200px" :
( this.scrollHeight > 400 ? "400px" : "auto")
);
}
另插一条限定图片最大宽度和高度的代码,仅供参考,其实与上述同源同理。
Html代码
这里是结合css和其支持的expression实现的,示例代码如下:
<title>控制图片的最大高宽</title>
<style type="text/css">
.clear{clear:both;}
.widthimg{width: expression(this.width > 200 ? '200px': true); max-width: 200px; }
</style>
<body>
<div class="clear">
<img class="widthimg" src="../image/mm.jpg" />
</div>
<div class="clear">
<img src="../image/xx7.jpg" />
</div>
</body>
</html>
<head>
<style type="text/css">
<!--
img.pic{
max-width:300;
max-height:100px;
/*由于IE6.0以及以前版本的IE不支持上边两个属性,所以加上以下两条语句.这里要说明的是expression只有IE支持*/
width: expression(this.width > 300 && this.width / 300 >= this.height / 100 ? 300 : true);
height: expression(this.height > 100 && this.width / 300 < this.height / 100 ? 100 : true);
}
//-->
</style>
</head>
<body>
<div id="pic">
</div>
<img class="pic" src="Blue hills.jpg" />
</body>
</html>
由于上边的代码中,设置最大的长宽是直接用数字的,这样再修改的时候十分不方便,所以做了以下修改:
<html>
<head>
<script type="text/javascript">
<!--
Object.MAX_WIDTH = 400;
Object.MAX_HEIGHT = 300;
-->
</script>
<style type="text/css">
<!--
img.pic{
max-width:300px;
max-height:100px;
width: expression(this.width > Object.MAX_WIDTH && this.width / Object.MAX_WIDTH >= this.height / Object.MAX_HEIGHT ? Object.MAX_WIDTH : true);
height: expression(this.height > Object.MAX_HEIGHT && this.width / Object.MAX_WIDTH < this.height / Object.MAX_HEIGHT ? Object.MAX_HEIGHT : true);
}
//-->
</style>
</head>
<body>
<div id="pic">
</div>
<img class="pic" src="Blue hills.jpg" />
</body>
</html>
这样的话,只需要修改Object.MAX_WIDTH和Object.MAX_HEIGHT这两个类变量就可以很方便的修改最大的长宽.
设定网页最小最大宽度和高度(兼容IE6)的更多相关文章
- IE 6最小最大宽度与高度的写法
最小最大宽度,最小最大高度,这是CSS很常见的一个要求.在现代浏览器中,一个 min-height,min-width 就可以解决问题,但是在IE系列,比如IE6则比较繁琐一点.下面总结一些IE 6下 ...
- 有两种分别用<bgsound>和<embed></embed>标签,当用<embed>插入背景音乐时可以设置宽度和高度为0,隐藏播放器。
<bgsound>: <bgsound> 是用来插入背景音乐,但只适用于 ie,其参数设定不多.如下 <bgsound src="your.mid" ...
- 关于Div的宽度与高度的100%设定
http://www.cnblogs.com/clare-zhang/archive/2011/08/26/2154220.html 正像你所知道的那样,设置DIV大小的有两个属性width和heig ...
- 关于div宽度和高度的100%设定
设置DIV大小的有两个属性width和height,以前在学习DIV每次给DIV设置100%宽度或高度时都很迷惑,不明白这个100%的宽度(高度)到底有多宽有多高?这个100%是从哪里得到的从哪里继承 ...
- Div的宽度与高度的100%设定
div的100%是从其上一级div的宽高继承来的,所以必须设置其上一级div的宽度或高度,否则无效. 举例说明:父div(deman)宽300高200,子div(cc)如果在这个条件下设置divcc的 ...
- min-height最小高度的实现(兼容IE6、IE7、FF)(解决IE6不兼容min-height)
<!doctype html><html> <head> <meta charset="UTF-8"> <meta name= ...
- js和jquery如何获取图片真实的宽度和高度
按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式,下面为大家介绍下js和jquery如何获取图片真实的宽度和高度 1.什么时候需要获取图片真实的宽度和高度 在做pc网页 ...
- js和jquery获取图片真实的宽度和高度
1.什么时候需要获取图片真实的宽度和高度 在做pc网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式! 另外一种就是在手机页面上,在新闻页插入的图片往 ...
- 如何通过js和jquery获取图片真实的宽度和高度
什么时候需要获取图片真实的宽度和高度 在做pc网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式! 另外一种就是在手机页面上,在新闻页插入的图片往往都 ...
随机推荐
- restframework CBV试图的4种方式
day100 上节回顾 1 APIView流程 2 序列化组件(restframework) 1 # 自定义序列化组件 class BookSerializers(serializers.Serial ...
- 云数据库 Redis 缓存 PHP session 变量
1.安装 phpredis 扩展. wget https://github.com/nicolasff/phpredis/archive/master.zip unzip master.zip cd ...
- mybatis-Plus 增强版用法收藏
转载:http://www.cnblogs.com/okong/p/mybatis-plus-guide-one.html#xml%E5%BD%A2%E5%BC%8F https://blog.csd ...
- C++ opencv 滑动条 Trackbary以及处理三通道和单通道图像
#include <opencv2\core.hpp> #include <opencv2\highgui.hpp> #include <opencv2\imgproc. ...
- java——快排、冒泡、希尔、归并
直接贴代码 快排: public class Test { private static void sort(int[] nums){ if(nums == null || nums.length = ...
- RequireJS -Javascript模块化(一、简介)
1.认识RequireJS RequireJs官网(http://requirejs.org/)的描述: RequireJS is a JavaScript file and module loade ...
- ES6结构赋值
解构赋值 从ES6开始,JavaScript引入了解构赋值,可以同时对一组变量进行赋值. 什么是解构赋值?我们先看看传统的做法,如何把一个数组的元素分别赋值给几个变量: var array = ['h ...
- plSql添加快捷键设置
汉化版:工具-首选项-用户界面-编辑器-自动替换-定义文件 英文版:Tools->Perferences->Editor中Autoreplaces选择配置的shortcuts 常用快捷键设 ...
- SQL命令行操作
命令行操作(mysql.exe) 0.登录 : mysql -u root -p 1.显示数据库列表: show databases; 2.选择数据库: ...
- Mac 安装GTK
Mac上配置GTK环境 安装command line工具, 如果安装了Xcode, 就直接跳过该步骤 安装Homebrew 使用brew install pkg-config 使用brew insta ...