Back to Freecodecamp

Step 15

curriculum/challenges/english/blocks/learn-intermediate-css-by-building-a-cat-painting/64770351e8586671ec0911f0.md

latest1.9 KB
Original Source

--description--

The last position property value is sticky. sticky positioning is a hybrid of relative and fixed positioning. It allows an element to stick to a specific position within its containing element or viewport, based on the scroll position.

Change the value of the position property of .cat-head to sticky, set top to 0, then remove left and its value.

Note: To see how sticky works, you have to place a couple of texts before and after your .cat-head div element. If you scroll down after that, you'll see that the .cat-head gets stuck to the top and remains there.

--hints--

Your .cat-head selector should have a position property set to sticky. Make sure you add a semicolon.

js
assert(new __helpers.CSSHelp(document)?.getStyle('.cat-head')?.position === 'sticky')

Your .cat-head selector should have a top property set to 0. Make sure you add a semicolon.

js
assert(new __helpers.CSSHelp(document)?.getStyle('.cat-head')?.top === '0px')

You should not have the left property and its value in your code.

js
assert.notMatch(code, /left:\s*100px;?/)

--seed--

--seed-contents--

html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>fCC Cat Painting</title>
    <link rel="stylesheet" href="./styles.css">
</head>
<body>
    <main>
      <div class="cat-head"></div>
      <div class="box"></div>
    </main>
</body>
</html>
css
* {
  box-sizing: border-box;
}

body {
  background-color: #c9d2fc;
}

.cat-head {
--fcc-editable-region--
  position: fixed;
  top: 100px;
  left: 100px;
--fcc-editable-region--
  background: linear-gradient(#5e5e5e 85%, #45454f 100%);
  width: 205px;
  height: 180px;
  border: 1px solid #000;
  border-radius: 46%;
}

.box {
  width: 200px;
  height: 600px;
  background-color: #000;
  position: absolute;
  left: 650px;
  top: 800px;
}