Make flex container take width of content, not width 100%

前端 未结 2 1738
情歌与酒
情歌与酒 2020-12-03 14:29

In the below example, I have a button with the following styles...

.button-flexbox-approach {
    /* other button styles */
    display: flex;
    justify-co         


        
2条回答
  •  隐瞒了意图╮
    2020-12-03 14:39

    Instead of display: flex on the container, use display: inline-flex.

    This switches the container from block-level (which takes the full width of its parent) to inline-level (which takes the width of its content).

    This sizing behavior is similar to display: block vs. display: inline-block.

    For a related problem and solution see:

    • Make flex items take content width, not width of parent container

提交回复
热议问题