Horizontal text Center (mobile) and text Center

Source: Internet
Author: User

Horizontal text Center (mobile) and text Center

In this case, the overall picture and nickname of the third-party joint login are centered,

For such a requirement, you cannot simply use margin: 0 auto for the div containing the Avatar and nickname, because the length of the nickname is unknown.

Solution 1: Use the padding-left attribute of the row element. Place the image in the padding-left area, set the text center for the div element on the external layer, and set line-height for the span element to center the text vertically.

<div class="container">    <span class="wrap">            Username    </span></div>.container {    height: 10rem;    text-align: center;    background: #819121;}.wrap {    display: inline-block;    position: relative;    margin-top: 3rem;    padding-left: 3rem;    line-height: 2rem;    background: #BB9391;}.icon {    position: absolute;    left: 0;    top: 0;    height: 2rem;}

 

:

 

Solution 2: center box layout, box-pack for div elements, and display: block for span elements. To be lazy, the compatible mode is omitted.

 

<div class="container">        <span class="username">Username</span></div>.container {    display: -webkit-box;    -webkit-box-pack: center;    height: 10rem;    background: #B2B2CD;}.icon {    margin-top: 2rem;    height: 2rem;}.username {    display: block;    margin-top: 2rem;    padding-left: 1rem;    line-height: 2rem;}

 

:

 

Comments: solution 1 will be relatively stable, while solution 2 is easy to maintain.

Related Article

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.