30

I have something like this:

<li>Post by <a>Author</a></li>

And I want to display the link in a new line, like this

Post by
Author

How can I achieve this? Clear:left doesn't work.

Sebastian Starke
  • 4,676
  • 3
  • 21
  • 34

4 Answers4

61

Use the display property

a{
    display: block;
}

This will make the link to display in new line

If you want to remove list styling, use

li{
    list-style: none;
}
Stephen P
  • 13,259
  • 2
  • 40
  • 61
Shiva Avula
  • 1,816
  • 1
  • 16
  • 27
  • I have already made the link look like a button, and using `display:block;` makes the button too wide. How can I force the link to a new line while maintaining its width? – Levi Johansen May 08 '16 at 16:22
  • If you want to revert the effect, you can use `display:inline;` (for example in a media query). – Fabian von Ellerts Oct 11 '18 at 08:26
34

How about with a :before pseudoelement:

a:before {
  content: '\a';
  white-space: pre;
}
alxndr
  • 3,291
  • 3
  • 34
  • 32
  • 1
    This is great for situations in which you want to put an anchor element on a new line, but not have its clickable area take up the entire line's width. – KOVIKO Jun 27 '14 at 03:54
  • 2
    Loved your solution, even if I had a different problem than the one described here, Thank you! – Matteo Sep 29 '14 at 10:39
  • 2
    This is a great solution, thank you. Solved one of those problems where the client requests something outrageous and you just gotta do it! – Galaxy Nov 24 '16 at 00:55
  • 2
    In case someone wonders (like I did): The `\a` renders as a newline, see https://stackoverflow.com/a/33332670 – bleistift2 Apr 14 '18 at 15:17
2

or you can use:

a {
    display: inline-block;
  }
Ya Basha
  • 1,703
  • 5
  • 28
  • 43
  • this will display on the same line... the question refers to a 'new line', in which case either inline or block will work. inline-block will attempt to place on the same vertical axis. – josh.thomson Jun 16 '14 at 11:05
1

Use <br /> OR <br> -

<li>Post by<br /><a>Author</a></li>

OR

<li>Post by<br><a>Author</a></li>

or

make the a element display:block;

<li>Post by <a style="display:block;">Author</a></li>

Try

Ishan Jain
  • 7,501
  • 9
  • 45
  • 72