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

Modure Rares
PLUS
Modure Rares
Courses Plus Student 9,041 Points

How can I spread the width of a link to all the <li></li> container ?

I want to add <a> in a <li> to make a navigation menu and I want the link to be accessed even if the user presses somewhere inside the <li> item but not on the link. What CSS code should I use ????

Savannah Lynn
Savannah Lynn
13,662 Points

Hi Modure,

Do you have any padding applied to the inside of your li elements?

2 Answers

Since an li element is a block element by default, you could make the anchor tag a block element too and it would take up the full width (minus any padding on the li):

li a {
  display: block;
}
Michael Hernandez
Michael Hernandez
9,746 Points

Try placing the li element inside of the anchor tags.

Only li tags are allowed as direct children of a ul or ol element, for it to be valid HTML. Therefore the anchor/a tag should go within the li.