相思资源网 Design By www.200059.com
解决图片长\宽大于容器,一边长一边宽,小于容器
在ff,ie里都通过
这里是js代码:
复制代码 代码如下:
<HTML>
 <HEAD>
  <TITLE>  www.jb51.net New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <style type="text/css">
*{margin:0px; padding:0px; font-size:12px;  }
body{ font-size:0.8em; color: #333;}
ul{ list-style:none}
.clear:after {
    content: "."; 
    display: block;
    height: 0; 
    clear: both; 
    visibility: hidden;}
img{border:0px;}
.clear1{    clear: both; width: 100%; height: 1px; overflow: hidden;}
a{ text-decoration: none; color:#404040 }
body{ background:#f7f3d0 url(../images/bg.jpg) repeat-x left 210px;}
/**/
#pic{border:1px solid #000; width:800px; height:auto!important;height:300px; min-height:300px;background:#fff}
#pic dl{width:215px;height:200px; overflow: hidden;border:1px solid #000;margin:10px;float:left}
#pic dt{height:161px; width:209px;overflow:hidden;border:1px solid red;text-align:center}

  </style>
 <script language="javascript" src="/UploadFiles/2021-04-02/tt.js"> <script language="javascript">
  <!--
  imgsrc={
   vh:'161',   //高
    vw:'209', //宽

    addEvent: function(elm, evType, fn, useCapture){
    if (elm.addEventListener){
        elm.addEventListener(evType, fn, useCapture);
        return true;
        } else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, fn);
        return r;
        } else {
        elm['on' + evType] = fn;
        }
    },
    init:function()
    {
        var divn=document.getElementById("pic")
       var dln=divn.getElementsByTagName("dl")
        for (var i=0;i<dln.length ;i++) {
       var dtn=dln[i].getElementsByTagName("dt");
       var imgn=dtn[0].getElementsByTagName("img");

      
      if(imgn[0].height>imgsrc.vh||imgn[0].width>imgsrc.vw)
      {
         if(imgn[0].height/imgsrc.vh > imgn[0].width/imgsrc.vw)
         {
          imgn[0].heigh=imgsrc.vh
          imgn[0].width=imgsrc.vh/imgn[0].height*imgn[0].width
         }
         else
         {
          imgn[0].width=imgsrc.vw
          imgn[0].heigh=imgsrc.vw/imgn[0].width*imgn[0].heigh
         }

      }
      if(imgsrc.vh-imgn[0].height>0)
      {
      var hh=(imgsrc.vh-imgn[0].height)/2
     imgn[0].style.margin=hh+" 0px 0px 0px"
      }

     

    }
    }

  }
  imgsrc.addEvent(window,"load",imgsrc.init,false)
  //-->
  </script>

 </HEAD>
 <BODY>
<div id="pic">
<dl>
<dt><a href="images/_1.jpg" title=""><img src="/UploadFiles/2021-04-02/_1.jpg"><dd>图片1</dd>
</dl>

<dl>
<dt><a href="images/_2.jpg" title=""><img src="/UploadFiles/2021-04-02/_2.jpg"><dd>图片1</dd>
</dl>
<dl>
<dt><a href="images/_3.jpg" title=""><img src="/UploadFiles/2021-04-02/_3.jpg"><dd>图片1</dd>
</dl>

<dl>
<dt><a href="images/_4.jpg" title=""><img src="/UploadFiles/2021-04-02/_4.jpg"><dd>图片1</dd>
</dl>

<dl>
<dt><a href="images/_5.jpg" title=""><img src="/UploadFiles/2021-04-02/_5.jpg"><dd>图片1</dd>
</dl>

<dl>
<dt><a href="images/_6.jpg" title=""><img src="/UploadFiles/2021-04-02/_6.jpg"><dd>图片1</dd>
</dl>

<dl>
<dt><a href="images/_1.jpg" title=""><img src="/UploadFiles/2021-04-02/_1.jpg"><dd>图片1</dd>
</dl>

<dl>
<dt><a href="images/_2.jpg" title=""><img src="/UploadFiles/2021-04-02/_2.jpg"><dd>图片1</dd>
</dl>

<dl>
<dt><a href="images/_3.jpg" title=""><img src="/UploadFiles/2021-04-02/_3.jpg"><dd>图片1</dd>
</dl>

<dl>
<dt><a href="images/_4.jpg" title=""><img src="/UploadFiles/2021-04-02/_4.jpg"><dd>图片1</dd>
</dl>

<dl>
<dt><a href="images/_5.jpg" title=""><img src="/UploadFiles/2021-04-02/_5.jpg"><dd>图片1</dd>
</dl>

<dl>
<dt><a href="images/_6.jpg" title=""><img src="/UploadFiles/2021-04-02/_6.jpg"><dd>图片1</dd>
</dl>
<div class="clear1"></div>
</div>



 </BODY>
</HTML>


包太大上传不了,我把html文件放上来,自己放图片看看就行了

标签:
js,图片,居中,底部对齐

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“用js 让图片在 div或dl里 居中,底部对齐”

暂无用js 让图片在 div或dl里 居中,底部对齐的评论...