push elements left or right with the float property - zilongxuan001/LearnFreecode GitHub Wiki

使用float属性推动元素到左边或右边

理解

这个定位工具并不是实际上用position,而是设置元素的属性为float

浮动(floating)元素就是从文档自然流中移除该元素,然后放到父元素的左边或右边。

使用width属性设置浮动元素偏离多少水平空间。

练习

这里有两个列的布局,sectionaside两个是挨着的。

#left条目一个leftfloat,给#right条目一个rightfloat

<head>
  <style>
  #left {
    float:left;
    width: 50%;
  }
  #right {
    float:right;
    width: 40%;
  }
  aside, section {
    padding: 2px;
    background-color: #ccc;
  }
  </style>
</head>
<body>
  <header>
    <h1>Welcome!</h1>
  </header>
  <section id="left">
    <h2>Content</h2>
    <p>Good stuff</p>
  </section>
  <aside id="right">
    <h2>Sidebar</h2>
    <p>Links</p>
  </aside>
</body>

来源

Applied Visual Design: Push Elements Left or Right with the float Property | Learn freeCodeCamp

CHANGELOG

2018-10-25 09:42:30

⚠️ **GitHub.com Fallback** ⚠️