move a relatively positioned element with css offsets - zilongxuan001/LearnFreecode GitHub Wiki

使用CSS偏移来移动相对位置的元素

理解

CSS偏移的top,botton,left,right,是告诉浏览器条目相对原来的文档自然流偏移多少。

你可以偏移元素从一个给定的点,移动元素到指向的边(通常是相反的方向)。正如你在最后一个挑战里看到的,使用top偏移h2往下。同样,使用左偏移就是把一个条目移到右边。

练习

使用CSS偏移,移动h2到右边15px,到上方10px。

<head>
<style>
  h2 {
    position: relative;
    left: 15px;
    bottom: 10px;
    
    
  }
</style>
</head>
<body>
  <h1>On Being Well-Positioned</h1>
  <h2>Move me!</h2>
  <p>I still think the h2 is where it normally sits.</p>
</body>

来源

Applied Visual Design: Move a Relatively Positioned Element with CSS Offsets | Learn freeCodeCamp

CHANGELOG

2018-10-23 16:28:27

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