php中的文本对齐

php中的文本对齐,php,jquery,html,mysql,css,Php,Jquery,Html,Mysql,Css,我想调整我的文字,这样当我发送信息时,它会显示在左侧,但它是一个回复,文字会显示在右侧。。。我不知道是使用“文本对齐:左”,定位还是对齐。这是我的密码 if ($row['username'] == $username) { $color = 'blue'; $align:left; // dont know if this is right } else { $color = 'red'; $align:right; // dont know if this

我想调整我的文字,这样当我发送信息时,它会显示在左侧,但它是一个回复,文字会显示在右侧。。。我不知道是使用“文本对齐:左”,定位还是对齐。这是我的密码

if ($row['username'] == $username)
{
    $color = 'blue';
    $align:left; // dont know if this is right

}
else
{
    $color = 'red';
    $align:right; // dont know if this is right
}


echo '<i><p style="font-family:arial;color:'.$color.';font-size:15px;"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';

}
if($row['username']==$username)
{
$color='blue';
$align:left;//不知道这是否正确
}
其他的
{
$color='red';
$align:right;//不知道这是否正确
}
echo“

”$行['username']。':'$mymessage.“

”; }
将其设置为与设置颜色完全相同的方式

例如:

$align='right';

echo '<i><p style="font-family:arial;color:'.$color.';text-align:'.$align.';font-size:15px;"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';
$align='right';
echo'

”$行['username']。':'$mymessage.“

”;
将其设置为与设置颜色完全相同的方式

例如:

$align='right';

echo '<i><p style="font-family:arial;color:'.$color.';text-align:'.$align.';font-size:15px;"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';
$align='right';
echo'

”$行['username']。':'$mymessage.“

”;
这应该可以:

if ($row['username'] == $username)
{
    $color = 'blue';
    $align = 'left';

}
else
{
    $color = 'red';
    $align = 'right';
}


echo '<i><p style="text-align:' . $align . ';font-family:arial;color:'.$color.';font-size:15px;"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';
if($row['username']==$username)
{
$color='blue';
$align='left';
}
其他的
{
$color='red';
$align='right';
}
echo“

”$行['username']。':'$mymessage.“

”;
这应该可以:

if ($row['username'] == $username)
{
    $color = 'blue';
    $align = 'left';

}
else
{
    $color = 'red';
    $align = 'right';
}


echo '<i><p style="text-align:' . $align . ';font-family:arial;color:'.$color.';font-size:15px;"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';
if($row['username']==$username)
{
$color='blue';
$align='left';
}
其他的
{
$color='red';
$align='right';
}
echo“

”$行['username']。':'$mymessage.“

”;
只需使用:

if ($row['username'] == $username)

echo '<i><p style="font-family:arial;color:blue;float:left;font-size:15px;"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';

else
echo '<i><p style="font-family:arial;color:red;float:right;font-size:15px;"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';
if($row['username']==$username)
echo'

”$行['username']。':'$mymessage.“

”; 其他的 echo'

”$行['username']。':'$mymessage.“

”;
只需使用:

if ($row['username'] == $username)

echo '<i><p style="font-family:arial;color:blue;float:left;font-size:15px;"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';

else
echo '<i><p style="font-family:arial;color:red;float:right;font-size:15px;"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';
if($row['username']==$username)
echo'

”$行['username']。':'$mymessage.“

”; 其他的 echo'

”$行['username']。':'$mymessage.“

”;
如果使用CSS类来实现这一点,效果会更好

例如,您可以有一个class
消息
和一个class
回复

<style>

.message {
  color: blue;
  text-align: left;
}

.reply {
  color: red;
  text-align: right;
}

</style>

.留言{
颜色:蓝色;
文本对齐:左对齐;
}
.答复{
颜色:红色;
文本对齐:右对齐;
}
然后在PHP中:

if ($row['username'] == $username)
{
  $class = "message";
}
else
{
  $class = "reply";
}


echo "<p class='$class'>
  <strong>{$row['username']}</strong>: $mymessage
</p>';
if($row['username']==$username)
{
$class=“消息”;
}
其他的
{
$class=“回复”;
}
echo“

{$row['username']}:$mymessage

';

您的代码将看起来更加干净。

如果您使用CSS类来实现这一点会更好

例如,您可以有一个class
消息
和一个class
回复

<style>

.message {
  color: blue;
  text-align: left;
}

.reply {
  color: red;
  text-align: right;
}

</style>

.留言{
颜色:蓝色;
文本对齐:左对齐;
}
.答复{
颜色:红色;
文本对齐:右对齐;
}
然后在PHP中:

if ($row['username'] == $username)
{
  $class = "message";
}
else
{
  $class = "reply";
}


echo "<p class='$class'>
  <strong>{$row['username']}</strong>: $mymessage
</p>';
if($row['username']==$username)
{
$class=“消息”;
}
其他的
{
$class=“回复”;
}
echo“

{$row['username']}:$mymessage

';
你的代码看起来会更干净。

试试这个

$css =  ($row['username'] == $username) ? 'color:blue;text-align:left;' : 'color:red;text-align:right;';

echo '<i><p style="font-family:arial;font-size:15px;'.$css.'"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';
$css=($row['username']==$username)?”颜色:蓝色;文本对齐:左;':'颜色:红色;文本对齐:右;';
echo“

”$行['username']。':'$mymessage.“

”;
试试这个

$css =  ($row['username'] == $username) ? 'color:blue;text-align:left;' : 'color:red;text-align:right;';

echo '<i><p style="font-family:arial;font-size:15px;'.$css.'"> <strong>' . $row['username']. '</strong>: ' . $mymessage.'</i></p>';
$css=($row['username']==$username)?”颜色:蓝色;文本对齐:左;':'颜色:红色;文本对齐:右;';
echo“

”$行['username']。':'$mymessage.“

”;
尝试使用float:right或float:left
$align:left
不正确PHP语句为PHP代码中的元素生成特殊类,并在css中定义此类。@E_错误您的用户名是PHP使用该语句生成的用户名,这有点可笑尝试使用float:right或float:left
$align:left
是不正确的PHP语句吗?在PHP代码中为元素生成特殊类,并在css中定义该类。@E_错误您的用户名是PHP使用该语句生成的,这有点可笑