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

simon buysse
simon buysse
9,716 Points

Anchor padding out of container

Hi there, I'm trying to create a couple of divisions that have the same height as their width and in the same time having responsive dimensions (so I'm working with percentages).

I found this lovely article on how to do this (http://alistapart.com/article/creating-intrinsic-ratios-for-video) And it works! So far so good. But when I add an anchor element to the division and set it's padding to 100%, in order for the anchor element to fill up its container, it flows outside of its container.

You can see what I did over here http://codepen.io/anon/pen/Wvrryx As you can see, clicking next to the container, also works...

3 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi Simon.

The padding and margin settings might increase the clickable area of the link but they also affect how different elements interact with each other.

Try the following styles for a link that spans the entire width of its parent but doesn't affect the elements around the container.

.top-wrapper a{
  display: block;
  width: 100%;
  height: 100%;
  text-align: center;
}

Have you tried ensuring that the anchor tag is being displayed as block? I think the anchor element is inherently displayed as inline. Would that affect it's boundary settings within the container?

simon buysse
simon buysse
9,716 Points

This seems to work! Thanks for your help Seab and Jonathan. One bonus question though: how come that adding a padding of 100% doesn't work? Shouldn't it take 100% of its parent container? Or does this work differently for an inline element?

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

That would make sense actually that inline elements are different as, as you'll know an anchor element is inline, so by default it only takes up the amount of width as the sum of its contents.

Maybe experiment with padding when you make an anchor element a block element but personally I think using widths and heights is better. :-)