---
title: "CSS样式如何控超过页面宽度的图片正比例缩放"
author: "mywebcode"
date: "2011-05-17T14:31:00Z"
tags: []
slug: "css"
draft: false
lastmod: "2013-05-08T10:38:48Z"
id: 1863291
url: "https://mywebcode.iteye.com/blog/1863291"
---

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)"&gt;  
&lt;html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)"&gt;  
&lt;head&gt;  
&lt;meta http-equiv="Content-Type" content="text/html; charset=gb2312" /&gt;  
&lt;title&gt;无标题文档&lt;/title&gt;

&lt;style&gt;

p {  
margin:auto;  
width:950px;  
}  
p img{max-width: 100% !important; height: auto!important; width:expression(this.width &gt; 950 ? "950px" : this.width)!important;}  
&lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;p&gt;

&lt;img src="[http://www.tianshui.com.cn/Files195/BeyondPic/2008-1/30/Img254961375.jpg](http://www.tianshui.com.cn/Files195/BeyondPic/2008-1/30/Img254961375.jpg)" width="1024px;;" /&gt;

&lt;/p&gt;

&lt;/body&gt;  
&lt;/html&gt;