23

I would like the navigation links on this page to each appear on their own line:

A. Without using "display:block" - as that makes the hover animation take up the full width of the container, not just the <a> element.

B. Without using <br> tags, as I am eventually looking to create a responsive site with a horizontal navigation on smaller screens.

Thanks for your help.

Caroline Elisa
  • 1,216
  • 6
  • 17
  • 34

3 Answers3

31

Have you tried float:left; clear:left ?

Sangram Nandkhile
  • 15,287
  • 17
  • 75
  • 111
Ricardo Castañeda
  • 5,318
  • 6
  • 25
  • 38
5

wrap you navigation in ul, li:

<ul>
    <li><a href="#">Link 1</a></li>
    <li><a href="#">Link 2</a></li>
    <li><a href="#">Link 3</a></li>
    <li><a href="#">Link 4</a></li>
</ul>

css:

ul {list-style: none} li {display: block}

This lets you style your anchors accordingly while forcing them to break lines.

David Nguyen
  • 7,953
  • 2
  • 27
  • 49
4

You can wrap the <a>'s in <div>'s and apply CSS to the div's to float:left, clear:left;

div.anchorContainer
{
    float:left;
    clear:left;
}

<div class="anchorContainer">
    <a href="#">text</a>
</div>

<div class="anchorContainer">
    <a href="#">text</a>
</div>

<div class="anchorContainer">
    <a href="#">text</a>
</div>
Khan
  • 16,500
  • 3
  • 42
  • 57