0

How can you set a link inside of a li element to where its background is longer that the actual text and they are all even with one another?

Example

CSS

.popoutsidebar li { margin-bottom: 20px; padding: 5px; }
.popoutsidebar li a { background-color: #E5E5E5; color: #B94A48; padding: 10px; border-radius: 5px; }
.popoutsidebar li a:hover { background-color: #B94A48; color: #FFFFFF; text-decoration: none; }
1
  • 2
    can we see a jsfiddle or some html code?
    – Keith
    Commented Jul 29, 2013 at 17:44

1 Answer 1

3

<a>nchor tags are inline by default. Try something like this:

.popoutsidebar li a { display:block }

The display property lets you define how a certain HTML element should be displayed.

display: block means that the element is displayed as a block, as paragraphs and headers have always been. A block has some whitespace above and below it and tolerates no HTML elements next to it, except when ordered otherwise (by adding a float declaration to another element, for instance).

display: inline means that the element is displayed inline, inside the current block on the same line. Only when it's between two blocks does the element form an 'anonymous block', that however has the smallest possible width.

http://quirksmode.org/css/css2/display.html

2
  • That fixes it! Haha Thanks. So by switching it to a block it fills the row.
    – John Ayers
    Commented Jul 29, 2013 at 17:48
  • Correct. I added an explanation of the differences between the two display types to my answer. Commented Jul 29, 2013 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.