CSS3 implementation of the picture in the container medium scale and horizontal vertical center

Source: Internet
Author: User

In this paper, we will introduce an instance method of using pure CSS3 to realize the medium scale and horizontal vertical display of a picture in a specified container.

See implementation Code First

<!html>


The implementation effect is as follows:


If you change the size of the container. Like what:

Change the section's Width,height property to

width:200px;
height:400px;

Let's look at the effect again:


CSS3 Achieve Horizontal Vertical Center

Horizontal vertical center of the production we have encountered, the horizontal center method to deal with, but the vertical center of words or let a lot of people headache, I also met a lot of friends to ask how to make the element horizontal vertical center. We've also discussed how to get pictures, single-line text, and multi-line text to be centered horizontally vertically across various browsers.
Using a pure CSS3 real box method to achieve horizontal vertical center, now the implementation of the code fragment posted to share with you:

Htmlmarkup

<divclass= "center" >

</div>
<divclass=" center ">
<divclass=" Text "> I'm on a line of text </div>
</  div>
<divclass= "center" >
<divclass= "text" >
I'm a multiline text <br/>
I'm a multiline text.
</div>
</div>


Csscode

. center{
width:300px;
height:200px;
padding:10px; 
border:1px solid #ccc;
margin:20px Auto;
Display:-webkit-box;
-webkit-box-orient:horizontal;
-webkit-box-pack:center;
-webkit-box-align:center;
Display:-moz-box;
-moz-box-orient:horizontal;
-moz-box-pack:center;
-moz-box-align:center;
Display:-o-box;
-o-box-orient:horizontal;
-o-box-pack:center;
-o-box-align:center;
Display:-ms-box;
-ms-box-orient:horizontal;
-ms-box-pack:center;
-ms-box-align:center;
Display:box;
Box-orient:horizontal;
Box-pack:center;
Box-align:center;
} 
. Centerimg,
text{
border:1px solid #dedede;
padding:2px;
}


Key code to achieve horizontal vertical centering:

Display:-webkit-box;
-webkit-box-orient:horizontal;
-webkit-box-pack:center;
-webkit-box-align:center;
Display:-moz-box;
-moz-box-orient:horizontal;
-moz-box-pack:center;
-moz-box-align:center;
Display:-o-box;
-o-box-orient:horizontal;
-o-box-pack:center;
-o-box-align:center;
Display:-ms-box;
-ms-box-orient:horizontal;
-ms-box-pack:center;
-ms-box-align:center;
Display:box;
box-orient:horizontal;
Box-pack:center;
Box-align:center;


Because Flexbox is a new attribute of CSS3, the browser currently supported is only: ie10+,firefox2+,chrome4+,safari3.1+.

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.