Why can't floated elements set their left and right margins

后端 未结 3 1123
情话喂你
情话喂你 2021-01-02 06:58

In a wrapper div, the floated elements don\'t seem to respond to left and right margin settings. Example:

html:

<
3条回答
  •  借酒劲吻你
    2021-01-02 07:24

    @Marcus's answer is good. Another way to fake having margins on a floated element is to put the content inside of another container and use padding:

    .outer
    {
        float: left;
        padding: 10px;
    }
    
    .inner
    {
    }
    

提交回复
热议问题