Jez
Jez

Reputation: 210

Remove line break with new <p> tags

I have this PHP code on my website:

<?php
$usernametext = "<p style=" . '"' . "color:#969CB3;font-size:120%" . '"' . ">Username: </p>" . "<p style=" . '"' . "color:black;font-size:150%" . '"' . ">";
echo $usernametext . htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');
?>

But this is what it displays as.

enter image description here

I want it to be on one line and display like this.

enter image description here

The <p> tags (with styling) create a line break (or two) which I don't want. I have tried to put the <p> tags out of the PHP and had no luck. Is this possible to do?

Upvotes: 2

Views: 6647

Answers (4)

Jack jdeoel
Jack jdeoel

Reputation: 4584

add display :inline property for that ...

<style>
 p {
    display :inline;
  }
 </style>
<?php
$usernametext = "<p style=" . '"' . "color:#969CB3;font-size:120%" . '"' . ">Username: </p>" . "<p style=" . '"' . "color:black;font-size:150%" . '"' . ">";
echo $usernametext . htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');
?>

Upvotes: 0

PacMan
PacMan

Reputation: 1358

the <p> is not the right one for your work you should use an inline tag such as <span> see this it may be helpful

<?php
$usernametext = "<span style=" . '"' . "color:#969CB3;font-size:120%" . '"' . ">Username: </span>" . "<span style=" . '"' . "color:black;font-size:150%" . '"' . ">";
echo $usernametext . htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');
?>

and here is a Snippet for it

<span>username is</span>
<span>XYZ</span>

color:#969CB3;font-size:120%
<span>username is<span>
  <span>XYZ</span>

Upvotes: 1

Felipe Guerra
Felipe Guerra

Reputation: 155

Easy, change p to span since by definition, each p represents a new paragraph (probabily there is a way to avoid line break when using p, but this approach doesn't pays off).

Upvotes: 0

Gurtej Singh
Gurtej Singh

Reputation: 235

Use span tag instead of p tag

<?php
$usernametext = "<span style=" . '"' . "color:#969CB3;font-size:120%" . '"' . ">Username: </span>" . "<span style=" . '"' . "color:black;font-size:150%" . '"' . ">";
echo $usernametext . htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');
?>

Upvotes: 3

Related Questions