开发者社区 问答 正文

自适应左右对齐的css写法除了浮动还可以怎么写?

好像flexbox也可以,还有其他神奇的写法么?

展开
收起
a123456678 2016-03-26 14:10:54 2402 分享 版权
1 条回答
写回答
取消 提交回答
  • 还可以用绝对定位,然后指定 left 或 right,利用 width 和 padding 巧妙的模拟 float。
    
    <div style="position: relative">
     <div style="position: absolute; width: 100px;>左对齐</div>
     <div style="position: absolute; right: 0; width: 100px;">右对齐</div>
     <div style="padding: 0 115px">中间的内容</div>
    </div>
    2019-07-17 19:16:08
    赞同 展开评论