请问这里应该怎么写才能让图片里加上 margin-left:"图片宽度的一
jquery吧
全部回复
仅看楼主
level 1
coinsir 楼主
margin-left:-122.5px;
这个margin-left是图片宽度的一半
请问宽度怎么获取加到HTML里呢?
每个图片的宽度都不一样
JQ 请问这里应该怎么写才能让图片里加上 margin-left:"图片宽度的一半尺寸"
================================
$(function(){
var width = $(".rr img").width();
$(".rr img").css("margin-left","+width+");
});
=====================================
CSS.HTML
<style>
.rr{height: 160px;width:160px;border:1px solid #cc0000;overflow:hidden;position: relative;}
.cmListGrid .cmIItem {
width: 201px; height: 233px; overflow: hidden;
text-align: left; line-height: 20px; padding: 19px; border: 1px #ddd solid;
margin-right: -1px; margin-bottom: -1px;
}
.cmListGrid .cmIImg { height: 160px; text-align: center; display: block; margin-bottom: 10px;
}
.cmListGrid .cmIImg img { height: 160px;
position:absolute;
top:0;
left:50%;
/*margin-left:-122.5px;*/
}
</style>
<div class="clear cmListGrid">
<div class="cmIGrid">
<div class="cmIItem">
<div class="rr">
<a href="#" class="cmIImg" target="_blank" class="hidden">
<img src="
" alt="">
</a>
</div>
</div>
<div class="cmIGrid">
<div class="cmIItem">
<div class="rr">
<a href="#" class="cmIImg" target="_blank" class="hidden">
<img src="
" alt="">
</a>
</div>
</div>
2016年06月15日 13点06分 1
1