hewei's rss

何为 > DIV+CSS > 正文

如何避免层被图片撑大?

老问题了,如果是表格,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})}

不过好像第二个不好用,不能判断自动缩放。

返回顶部网友评论»查看所有评论

发表评论:(内容不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。)

您的昵称:验证码: 验证码查看所有评论

About Hewei.org

何为的博客。记录我的生活点滴,技术经验,奇思妙想。无聊的时候看看自己记录的思想,也是一种享受。

订阅何为的博客
  • ZhuaXia 订阅到抓虾
  • SouYo 订阅到沙发
信息检索 In Hewei.org
Hot标签
最新推荐主题
最新推荐专题
  • google adsense
  • firfox
  • 域名无忧
  • 在线交友
XHTML 1.0 StrictValid CSS 2.1
何为博客!意欲何为?大有作为!Copyright © HeWei.Org
皖ICP备06010916号