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

后端 未结 3 1127
情话喂你
情话喂你 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条回答
  •  猫巷女王i
    2021-01-02 07:28

    A more recent CSS technique that works perfectly in this scenario is to use the CSS transform property with a translate X or Y. This acts on the floated element only, so does not have the unintended effect of moving other elements around.

    An example transform is this:

    .floated-element {
      // move the floated element 10 pixels to the left
      transform: translateX(-10px);
    }
    

提交回复
热议问题