Jump to content

PHP alignment


chelnov63

Recommended Posts

Hi I'm looping thoguth a recordset and trying to displaying three pieces of information (date, title, and read more link) for each record on one line.

 

However Im havign a problem with the positioning of the text elements... it seems the position of the Read More link depends upon the number of charaters of the article title. Its like the padding is added on from where the text ends.

 

Anyone know how i can fix this i.e set it so the Read More links are all aligned..

 

p.s the code is  as follows:

 

<div style="width: 420px; height: 275px;color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;text-align:justify;padding-right:11px;" >
        <?php do { ?>
        <?php $link = "news.php?id=".$row_rsNews['id']; ?>
        <?php echo "<strong><span class='stuff'>".date("d/m/y", strtotime($row_rsNews['date_added']))."</span></strong>"; ?>
        <?php echo "<span class='stuff' style='padding-left:45px'>".$row_rsNews['title']."</span>"; ?>
        <?php echo "<span class='stuff' style='padding-left:95px'><a href='".$link."'>Read More</a><span><br>"; ?>
        <?php echo "<img src='bar.png' />"; ?>
        <?php } while ($row_rsNews = mysql_fetch_assoc($rsNews)); ?>
</div>

 

The result looks something like

 

 

02/09/08 news again man      Read More

01/01/70 News item man       Read More

01/01/70 Article 5       Read More

01/01/70 Artciel 4       Read More

01/01/70 Article 3       Read More

01/01/70 Article 2       Read More

01/01/70 Article 1       Read More

 

Thanks in advance for any help

Link to comment
https://forums.phpfreaks.com/topic/122360-php-alignment/
Share on other sites

Start with making your code readable (and non-nonsensical... is 'sensible' a word for that?):

 

<div style="width: 420px; height: 275px;color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;text-align:justify;padding-right:11px;" >
<?php 
do {
$link = "news.php?id=".$row_rsNews['id'];
echo "<strong><span class='stuff'>".date("d/m/y", strtotime($row_rsNews['date_added']))."</span></strong>";
echo "<span class='stuff' style='padding-left:45px'>".$row_rsNews['title']."</span>";
echo "<span class='stuff' style='padding-left:95px'><a href='".$link."'>Read More</a><span><br>";
echo "<img src='bar.png' />";
} while ($row_rsNews = mysql_fetch_assoc($rsNews)); 
?>
</div>

 

 

Link to comment
https://forums.phpfreaks.com/topic/122360-php-alignment/#findComment-631803
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.