how to evenly distribute elements in a div next to each other?

后端 未结 9 1151
有刺的猬
有刺的猬 2020-12-02 07:26

This is meant for a menu.
For example I have a div element with 3 spans in it, all of which have some margin, max-width and float (left or right).
It is positioned s

9条回答
  •  清歌不尽
    2020-12-02 07:49

    If someone wants to try a slightly different approach, they can use FLEX.

    HTML

    Div 1
    Div 2
    Div 3
    Div 4

    CSS

    .test {
        display: flex;
        flex-flow: row wrap;
        justify-content: space-around;
    }
    .test > div {
        margin-top: 10px;
        padding: 20px;
        background-color: #FF0000;
    }
    

    Here is the fiddle: http://jsfiddle.net/ynemh3c2/ (Try adding/removing divs as well)

    Here is where I learned about this: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

提交回复
热议问题