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,246
  • 6
  • 18
  • 35

4 Answers4

36

Have you tried float:left; clear:left ?

Sangram Nandkhile
  • 17,634
  • 19
  • 82
  • 116
Ricardo Castañeda
  • 5,746
  • 6
  • 28
  • 41
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
  • 8,368
  • 2
  • 33
  • 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
  • 17,904
  • 5
  • 47
  • 59
0

You can just apply word-break: break-all;

.parent-block {
  max-width: 250px;
  width: 100%;
  border: solid 1px black;
}

.long-link {
  word-break: break-all;
}
<div class="parent-block">
<a class="long-link">https://stackoverflow.com/questions/10000674/make-an-a-tag-move-onto-a-new-line-without-using-displayblock</a>
</div>
sandroid
  • 311
  • 2
  • 5