About the big Picture Center display ~ Adapt to the mobile side

Source: Internet
Author: User

Today to modify the project encountered a problem, the mobile side click on the small picture, open a large picture display; Since the proportions of this large picture are uncertain, how to display them becomes a problem.

The initial feature was to set a CSS3 property, and then something went wrong on the Android phone,

-webkit-align-self:center;-ms-flex-item-align:center;align-self:center;

Then I checked this property:

Some Android machines are not able to use this property because of the version.

I looked for the center of the display of information, looked at the image of Baidu image display method, found that they are each image to do the calculation size, and then display; If you want to go, you can only use JS.

The first way to use table is enough to make the picture centered.

<Divclass= "box">     <Divclass= "Table">         <Divclass= "TD">             <imgsrc= "Dmn.png"alt="">         </Div>     </Div></Div>
*{margin:0px;padding:0px;}. Box{width:300px;Height:300px;Border:2px solid #ccc;}. Table{Display:Table;width:100%;Height:100%;}. TD{Display:Table-cell;vertical-align:Middle;text-align:Center;}

Next on the phone display, think big picture in small screen mobile phone can also display completely, and according to the aspect ratio display complete, need JS to judge a bit.

//determine the size of the picture-the display of different picture sizes on different screens          varW = $ (". Box"). width (); varH = $ (". Box"). Height (); $(". Box img"). each (function(){            varIMGW = $ ( This). width (); varIMGH = $ ( This). Height (); if(Imgh/imgw > h/w && imgh>=h) {              $( This). Height (h); }Else if(IMGH/IMGW <= h/w && imgw>=W) {$ ( This). Width (w); }          })

With JQ written, go to the public Library of Baidu (http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js) load a good, very convenient.

The technology is limited, the thing is very simple, mainly is holding the exchange mentality, also hoped can give the novice friend to provide some ideas.

Welcome to criticize, have a better idea of more exchanges ~

About the big Picture Center display ~ Adapt to the mobile side

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.