---
title: "IE 6最小最大宽度与高度的写法"
author: "tanwenEyE"
date: "2016-01-06T14:03:48Z"
tags: []
categories: ["Web前端"]
slug: "ie-6"
draft: false
lastmod: "2016-01-06T14:04:39Z"
id: 2268911
url: "https://tanweneye.iteye.com/blog/2268911"
---

最小最大宽度，最小最大高度，这是CSS很常见的一个要求。在现代浏览器中，一个 min-height，min-width 就可以解决问题，但是在IE系列，比如IE6则比较繁琐一点。下面总结一些IE 6下的最小最大宽度与高度的一些写法。

IE6最小最大宽度：


```css

.min-width {
    min-width:600px;
    _width:expression(document.body.clientWidth < 300 ? "300px" : "auto");
}

.max-width {
    max-width: 600px;
    _width:expression(document.body.clientWidth > 600 ? "600px" : "auto");
}
```


IE6最小最大高度：


```css
.min_height{
  min-height:200px;
  _height:expression(this.scrollHeight < 200 ? "200px" : "auto");
}
 
.max_height{
  max-height:400px;
  _height:expression(this.scrollHeight > 400 ? "400px" : "auto");
}
```


IE6最大最小宽度：


```css
.min_and_max_width{
  min-width:300px;
  max-width:600px;
  _width: expression(document.body.clientWidth < 300 ? "300px" :( document.body.clientWidth > 600 ? "600px" : "auto"));
}
 
.min_and_max_width {
    border:solid 1px red;
    height:500px;
    max-width:600px;
    min-width:300px;
 _width: expression(  document.body.clientWidth < 300 ? "300px" :
 ( document.body.clientWidth > 600 ? "600px" : "auto")  );
}
```


IE6最大最小高度：


```css
.min_and_max_height{
  min-height:200px;
  max-height:400px;
  _height: expression(
    this.scrollHeight < 200 ? "200px" :
      ( this.scrollHeight > 400 ? "400px" : "auto")
  );
}
```



转载自：<http://www.nowamagic.net/librarys/veda/detail/2183>