解决图片长\宽大于容器,一边长一边宽,小于容器
在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文件放上来,自己放图片看看就行了
在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,图片,居中,底部对齐
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“用js 让图片在 div或dl里 居中,底部对齐”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。