Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Unused CSS Stages Transitions and Transforms Transitions: Part 1

Chris Kwong
Chris Kwong
10,266 Points

How do I make .box keep the hitbox consistent?

When hovering the mouse over the edge of the square it will start to transition into a circle. The area where it detects the hover is no long effective on the edge and the mouse is moved the shape will automatically change back. How do I make the hover consistent between both shapes?

1 Answer

Hi Chris,

I'm not sure exactly what you mean but I think you want the hover area to always be the original box.

I think that you will need 2 elements to do this. A parent element to be the size of the original box and transparent. Then a child element which will be the colored box and transition to the circle.

I saved the codepen that was linked to in this video. It shows 1 way you could do this with the ::before pseudo element instead of adding another element in the html.

http://codepen.io/anon/pen/LEVzyq

html:

<div class="box"></div>

css:

.box,
.box::before {
  width: 300px;
  height: 300px;
  border-radius: 15px;
}

.box {
  margin: auto;
}   

.box::before {
  content: '';
  position: absolute;
  background: steelblue;
  -webkit-duration: .3s;
  -moz-duration: .3s;
  -o-duration: .3s;
  transition-duration: .3s;
 }

.box:hover {
  cursor: pointer;
}

.box:hover::before {
  background: lightcoral;
  border-radius: 50%;
}

Let me know if you were talking about something else.

Chris Kwong
Chris Kwong
10,266 Points

Yes, that's exactly it. Thank you very much.