0

I have the following code the links appear on separate lines. How do I place them on a single line on the web page-

<p><a href="new.php">Add a new record</a></p>
<p><a href="view.php">View, Edit or Delete Existing Records</a></p>
<p><a href="index.html">Go to Home Page</a></p>
Aditya Dev
  • 3
  • 1
  • 2
  • 5

7 Answers7

4

If you can't change your html, one way is to add display: inline to your <p> tags.

p {
  display: inline;
}
<p><a href="new.php">Add a new record</a></p>
<p><a href="view.php">View, Edit or Delete Existing Records</a></p>
<p><a href="index.html">Go to Home Page</a></p>

Or if you will need to do things like specify height or width, display: inline-block would be the answer.

p {
  display: inline-block;
  height: 50px;
  background: grey;
}
<p><a href="new.php">Add a new record</a></p>
<p><a href="view.php">View, Edit or Delete Existing Records</a></p>
<p><a href="index.html">Go to Home Page</a></p>

However, if you want them inline I wouldn't put each link in it's own paragraph, as this is not good practice. Remove the <p> tags, as below:

<a href="new.php">Add a new record</a>
<a href="view.php">View, Edit or Delete Existing Records</a>
<a href="index.html">Go to Home Page</a>
CalvT
  • 2,965
  • 6
  • 38
  • 51
  • @C0dekid I'm not sure if it would make a difference in this case, but I'll edit my answer. – CalvT Jun 22 '16 at 07:03
  • @C0dekid What `inline-block` has over `inline` is that you can add height and width - thats the only difference - see http://stackoverflow.com/questions/8969381/what-is-the-difference-between-display-inline-and-display-inline-block – CalvT Jun 22 '16 at 07:05
  • @C0dekid You do realize the OP said *How do I place them on a single line on the web page* right? – CalvT Jun 22 '16 at 07:10
  • Oh.. i'm sleeping I think, I'm sorry! Haha, have my upvote :-) – node_modules Jun 22 '16 at 07:11
2

Although it is possible to do it the way you did it with p tag I would recommend doing it with ul and then li tags.

li
{
  display:inline-block;
}
<ul>
  <li><a href="new.php">Add a new record</a></li>
  <li><a href="view.php">View, Edit or Delete Existing Records</a></li>
  <li><a href="index.html">Go to Home Page</a></li>
</ul>
Quentin Roy
  • 7,164
  • 2
  • 30
  • 48
wegelagerer
  • 3,420
  • 9
  • 39
  • 59
1

<a href="new.php">Add a new record</a>
<a href="view.php">View, Edit or Delete Existing Records</a>
<a href="index.html">Go to Home Page</a>
The <p> tag creates a new paragraph so if you want the links to appear in a single line, you just need to get rid of them
sonali
  • 728
  • 9
  • 22
0

Delete the p

<a href="new.php">Add a new record</a>
<a href="view.php">View, Edit or Delete Existing Records</a>
<a href="index.html">Go to Home Page</a>
prgrm
  • 3,384
  • 13
  • 37
  • 73
0

Try this

<a href="new.php">Add a new record</a>
<a href="view.php">View, Edit or Delete Existing Records</a>
<a href="index.html">Go to Home Page</a>
Vipul
  • 356
  • 6
  • 18
0

You can also do it with display:inline-block. Because inline elements can not have a width and height set, but inline-block elements respects height and width, respects top and bottom margins and paddings.

a {
  display: inline-block;
}
<a href="new.php">Add a new record</a>
<a href="view.php">View, Edit or Delete Existing Records</a>
<a href="index.html">Go to Home Page</a>
kkakkurt
  • 2,735
  • 1
  • 33
  • 31
0

P tag is block level element so it will take full width so if you need this in one line then you can add css display:inline-block for p tag.

Best way of navigation in one line:

You can use ul instead on p tag:

<ul>
    <li><a href"#">test</a></li>
    <li><a href"#">test</a></li>
    <li><a href"#">test</a></li>
</ul>

Css for above HTML:

li{display:inline-block}
Pradeep Pansari
  • 1,287
  • 6
  • 10