The image based on jquery implementation is centered up down left and right in unknown containers at various resolutions

  • 2020-03-30 02:55:42
  • OfStack

DIV :


<div class="pic_conent">
<div class=" fn-pr pic_layer">
<!-- Picture text introduces the transparent layer -->
<section class="bg text_layer_home p10 font-yahei fn-bc">
   <h2 class="f14 fefefe">${pic.desc}</h2>
<aside class="f12 bbb">
<c:if test="${not empty pic.poi}">
<span class="scenery fn-fl">${pic.poi}</span>
</c:if>
<span class="fn-fr mt10">by ${pic.username}</span>
</aside>
</section>
<img src="${pic.picUrl}" width="320" height="420" />
</div>
</div>

CSS:


.pic_conent{
height: 720px;
text-align: center;
display: table-cell;
vertical-align: middle;
}
.pic_layer{text-align:center; width:100%; display:inline-block; vertical-align:middle;}

jquery:


$(function() {
var surH = $(window).height();
$(".pic_conent").height(surH);
window.onresize=function(){
var surH = $(window).height();
$(".pic_conent").height(surH);
} 


Related articles: