Moving ends split layout extension

Source: Internet
Author: User

Original link: http://caibaojian.com/mobile-just-center.html

Flex method

1, insert four empty tags, set flex:1, the answer is the most (this method is suitable for multiple layouts, but the code is a bit bloated, to see a person's preferences, there is a need to use)

<ul class= "Share-list" >    <li class= "gap" ></li>    <li class= "Share-item" ><span> Text Center </span></li>    <li class= "gap" ></li>    <li class= "Share-item" ><span> Front-end Development blog </span></li>    <li class= "gap" ></li>    <li class= "Share-item" ><span >http://caibaojian.com</span></li>    <li class= "gap" ></li>    <li class= " Share-item "><span> yard headlines </span></li>    <li class=" gap "></li></ul>
. share-list{    Display:flex;}. share-item{    width:60px;    height:60px;}. gap{    flex:1;    width:1%;}. share-item{width:60px;height:60px; background:orange;}

Demonstrate:

How to implement text centering

According to a previously written "Mobile Vertical Center Alignment": Http://caibaojian.com/mobile-translate.html can help us achieve the above mobile side of the horizontal center alignment. (Welcome message to share more methods)

The first kind: transform+ relative positioning (recommended, compatibility is better, but need to add a width)

. share-item{width:60px;height:60px; background:orange; position:relative;}. Share-item span{position:absolute; left:50%; top:100%; min-width:80px; transform:translate ( -50%,0); Text-align: Center;}

The second type: Flex method

. Share-item span{Display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;- Webkit-box-align:center;-moz-box-align:center;-ms-flex-align:center;-webkit-align-items:center;align-items: Center;-webkit-box-pack:center;-moz-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center; Justify-content:center; White-space:nowrap; margin-top:100%;}

The following code is no longer in the text center code, there are problems please refer to the above two. Back to the body theme.

2, the first and third sets Flex to 1, the second is the fixed width of the icon, and the embedded layer handles the specific icon width.

<ul class= "Share-list" >    <li class= "Share-item" ><div class= "Item-inner" ></div></li >    <li class= "Share-item" ><div class= "Item-inner" ></div></li>    <li class= " Share-item "><div class=" Item-inner "></div></li></ul>
. share-list{    Display:flex;}. Share-item:nth-child (1),. Share-item:nth-child (3) {    flex:1;    width:1%;}. Share-item:nth-child (2) {    width:60px;}. item-inner{    width:60px;    Marigin-left:auto;    Margin-right:auto;}

Look at the code, found not suitable to expand to multiple split, not recommended (PS: If you find that can improve, please let me know)

3, to justify-content: space-between; make a flexible

每个间隙的宽度 = (100% - 60px * 3)/ 4 = 25% - 45px

First coat a layer wrap, set around the padding you 25%, and then the list set negative left and right margin you 45px (equivalent to the padding reduced 45px), get the first and last gap; the gap in the middle is justify-content: space-between; freely distributed

By the above formula, we have also expanded to four. Width per gap = (100%-60px*4)/5 = 20%-48px

<div class= "Share-list-wrap" >  <ul class= "share-list" >    <li class= "Share-item" ><span > Weibo sharing </span></li>    <li class= "Share-item" ><span> sharing </span></li>    <li class= "Share-item" ><span>http://caibaojian.com/</span></li>    <li class= " Share-item "><span> Friends </span></li>  </ul></div>
Code from http://caibaojian.com/mobile-just-center.html.share-list-wrap{    padding-left:20%;    padding-right:20%;}. share-list{    Display:flex;    Margin-left: -48px;    Margin-right: -48px;    Justify-content:space-between;}

Demonstrate:

Moving ends split layout extension

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.