search

Home  >  Q&A  >  body text

css - Flex layout issue


The header uses flex layout. I want the search box to be horizontally centered, similar to the layout in native IOS


It is not affected by the content on the left and right sides, and is still horizontally centered
I remember that I implemented it before, but then I forgot about it when I used flex.css. Please see how to achieve it with this

曾经蜡笔没有小新曾经蜡笔没有小新2746 days ago1048

reply all(4)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-19 10:49:50

    .header{
        display:flex;
        flex-flow:row nowrap;
        align-item:center;
        justify-content:space-around;
    }

    To learn more about Flex layout, please see: http://www.ruanyifeng.com/blo...

    reply
    0
  • 阿神

    阿神2017-05-19 10:49:50

    Only three elements can be spread directly using space-between

    https://jsfiddle.net/straybug...


    You updated later

    Not affected by the content on the left and right, still horizontally centered

    Since it is not affected, the only way is to extract the absolute and then center it.

    https://jsfiddle.net/straybug...

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:49:50

    Mainly use align-items: center
    This is a demo

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:49:50

    Use absolute positioning for the middle one. If the left and right widths are different, it will affect the middle position

    .search {
        position: absolute;
        left: 50%;
        -webkit-transform: translateX(-50%);
        transform: translateX(-50%);
    }

    reply
    0
  • Cancelreply