freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/applied-visual-design/push-elements-left-or-right...

2.0 KiB

id title challengeType videoUrl localeTitle
587d78a3367417b2b2512ace Push Elements Left or Right with the float Property 0 使用float属性向左或向右推送元素

Description

下一个定位工具实际上不使用position ,而是设置元素的float属性。浮动元素从文档的正常流中移除,并推送到其包含的父元素的leftright 。它通常与width属性一起使用,以指定浮动元素需要多少水平空间。

Instructions

给定的标记可以很好地用作两列布局,其中sectionaside元素彼此相邻。给#leftfloatleft#rightfloatright

Tests

tests:
  - text: id为<code>left</code>的元素的<code>float</code>值应为<code>left</code> 。
    testString: 'assert($("#left").css("float") == "left", "The element with id <code>left</code> should have a <code>float</code> value of <code>left</code>.");'
  - text: id为<code>right</code>的元素的<code>float</code>值应为<code>right</code> 。
    testString: 'assert($("#right").css("float") == "right", "The element with id <code>right</code> should have a <code>float</code> value of <code>right</code>.");'

Challenge Seed

<head>
  <style>
  #left {

    width: 50%;
  }
  #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>

Solution

// solution required