Can I combine position: relative and float: left?

前端 未结 5 1611
逝去的感伤
逝去的感伤 2021-02-01 14:40

Can I apply both position: relative and float: left on one element? Like this:

div {
  float: left;
  position: relative;
  top: 0px;
          


        
5条回答
  •  旧巷少年郎
    2021-02-01 15:32

    Yes, You can use both.

    You will use float:left to position element to left side and permit next element to position right side of this.

    position:relative will affect itself and it's children, to take own position. when you will use left:npx;top:npx it will move this element left,right,top and bottom.

    You can check this demo: jsfiddle link

提交回复
热议问题