怎么强制限制div宽度

怎么设定div 使他只能在限定宽度内显示,如果超出宽度而不显示。

比如说这个

http://www.zbhome.cn/edu/tx/qq/kj/2006-11-13/200.html

图片超出宽度了,使得左边的变大 而使整个布局乱掉了

1、在css中加入一句


img {
max-width: 450px;width:expression(this.width > 450 ? "450px":this.width); 
/*如果图片大小超过450则自动按比例缩小到450*/
vertical-align:bottom;border:none;/*上半句是图片下沉,后面是无边框。常用*/
}


2、在文章内容的框架<td>里,或div里。加入

style="word-break:break-all;word-wrap:break-word;"


例如

<div style="word-break:break-all;word-wrap:break-word;">内容</div>





说明

css地址,在任何页面的头部找到

<link href="images/style.css" rel="stylesheet" type="text/css" />


images/style.css是css地址

/*这里面的文章是说明可以删除*/

第2个是为了防止英文过长导致撑破表格,因为 英文有不间断性。如果是连续的英文字母他不会换行的。

posted @ 2012-08-28 21:59  沐雪架构师  阅读(722)  评论(0编辑  收藏  举报