如何避免层被图片撑大?
老问题了,如果是表格,baidu上搜索都是,css控制table
table {
table-layout: fixed;
word-break: break-all;
}
如果是层呢,还是有办法,css控制div
div {
table-layout: fixed;
word-break: break-all;
width: 加上宽度;
overflow: hidden; (让多出来的不显示。)
}
要显示怎么办,那只能用js控制了
<script language="JavaScript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width>=510){
ImgD.width=510;
ImgD.height=(image.height*510)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
//-->
</script>
在图片的img 加入 onload="javascript:DrawImage(this);"
还有一种方法
img{flost:expression(onload=this.width=500)}
img{flost:expression(onload=function(){if(this.width>500)this.width=500})}
不过好像第二个不好用,不能判断自动缩放。
- 相关文章
- 理解background-position属性 - 2008-02-19
- 单行图片与文字垂直居中的解决 - 2007-10-11
- form的margin - 2007-03-26
- 关于层的height在ie下面失效的问题 - 2007-01-07
- div背景自动延伸的解决 - 2006-10-22
- CSS 中 position:absolute 与 z-index 对层次结构影响 - 2006-10-12
- 奇怪的问题css下面显示不全 - 2006-09-18
- 用!important解决IE和Mozilla的布局差别 - 2006-09-16
- 昏,图片把界面撑的不成形状 - 2006-05-26
- DIV+CSS重构 - 2006-05-13
- 上一篇:css制作横向菜单和块状链接
- 下一篇:关于css的重复定义











