Learn Intermediate CSS by Building a Cat Painting - Step 25 (Why does the "absolute" set for the "position" property make the trapezoid into a triangle?)

Tell us what’s happening:

Why does the trapezoid turn into a triangle after placing the position property with a set of absolute?

Your code so far

<!-- file: index.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 class="cat-ears">
          <div class="cat-left-ear">
            <div class="cat-left-inner-ear"></div>
          </div>
          <div class="cat-right-ear">
            <div class="cat-right-inner-ear"></div>
          </div>
        </div>
      </div>
    </main>
</body>
</html>
/* file: styles.css */
* {
  box-sizing: border-box;
}

body {
  background-color: #c9d2fc;
}

.cat-head {
  position: absolute;
  right: 0;
  left: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  background: linear-gradient(#5e5e5e 85%, #45454f 100%);
  width: 205px;
  height: 180px;
  border: 1px solid #000;
  border-radius: 46%;
}


/* User Editable Region */

.cat-left-ear {
  
  border-left: 35px solid transparent;
  border-right: 35px solid transparent;
  border-bottom: 70px solid #5e5e5e;
  position: absolute;
  top: -26px;
  left: -31p
}

/* User Editable Region */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Challenge Information:

Learn Intermediate CSS by Building a Cat Painting - Step 25

I personally don’t know how to explain this.
Best thing to do, is for you to transform the code you have right now, one line at a time,
into the following. Start from the top and add the .cat-ears so you can see what the cat-ear container looks like first then work your way down, changing the code you have, line by line so you can see what is happening.


.cat-ears {
  border: 3px solid blue;
}
.cat-left-ear {

  border-left: 35px solid red;
  border-right: 35px solid red;
  border-bottom: 70px solid red;
  width: 50%;
  width: 75%;
  width: 100%;
  position: absolute;
  width: auto;
  top: -26px;
  left: -31px;
}

I’m hoping when you’re done you’ll understand:
1- the original .cat-left-ear was a rectangle shape
2- the transparent colors were hiding parts of the rectangle
3- the rectangle was the size of its containing element cat-ears
4- making the rectangle have absolute position moved its location so it is ‘free’ of the container.
5- then top and left refined the position further

Edit: i changed the order a bit so you can see things better.

1 Like

Thank you! I understand it now! :smiley:

1 Like