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 CSS Foundations Text, Fonts, and Lists More Text Properties

Ji Jiang
Ji Jiang
2,505 Points

word-wrap property doesn't work if I select anchor element

I am trying word-wrap property on the following HTML tags: <p class="word-wrap"><a href="#">a very very long link</a></p> In the CSS I have to select the .word-wrap class to wrap the link ( .word-wrap{word-wrap:break-word;} ).

If I select the anchor element like below, it doesn't wrap the link. a {word-wrap:break-word;} Can anyone tell me why? Thanks.

Sreng Hong
Sreng Hong
15,083 Points

Hi Ji, I think you can use both selector (.word-wrap and a) to make the link break. I've tested already. You can check your code again. If it's still problem, you can post your code here and I'll try to help again. Thanks

Ji Jiang
Ji Jiang
2,505 Points

Thanks for replying. Now I know what the problem is. I was using Eclipse to test my code and it doesn't work in eclipse. But if I test it on treehouse workspace it is working now. Thank you!

2 Answers

Dai Phong
Dai Phong
20,395 Points

apply word-wrap property to the container of elements which you want to wrap. ".word-wrap" is a container of "a" element so apply it to ".word-wrap" instead of "a" element.

Ji Jiang
Ji Jiang
2,505 Points

Thank you! Pls see above comment.

Hi Ji,

You should get the same result when applying directly to the link.

The word-wrap property is inherited so when you apply it to .word-wrap the link is going to inherit that value. Applying it directly to the link should have the same result.

Ji Jiang
Ji Jiang
2,505 Points

Thank you! Pls see above comment.