Search code examples
phpinline-code

php - inline font style for print statement?


I know its possible to apply inline styles to echo statements but can this be done with print statements as well?

In my pagination I have links to previous and next records using the greater and less than symbols <> and a running count of the current record against the total number of records. e.g.

<
1/2

or

>
2/2

I have styled them in css but want to decrease the size of the count only. If I make changes to the css the font size for the previous and next links and count all change, I only want to target the count.

<div class="nextcard"><?php if($nextlink != ""){ print ($nextlink."<br/>".$next."/".$count); } ?></div>

I have tried :

<div class="nextcard"><?php if($nextlink != ""){ print 'style=font:50px' ($nextlink."<br/>".$next."/".$count); } ?></div>

But get syntax errors.


Solution

  • One approach would be to add a class rather than inline styles. However, you have forgotten to append the string correctly.

    Here is what I would personally do: (Note I replaced print with echo, TBH, there would be no different)

    <div class="nextcard">    
       <?php
            if($nextlink != "")
                echo '<span class="mark">'.($nextlink."<br/>".$next."/".$count).'</span>'; 
    
        ?>
    </div>
    

    If you still want to style it inline, you should simply do:

    <div class="nextcard">    
           <?php
                if($nextlink != "")
                    echo '<span style="font-size:50px;">'.($nextlink."<br/>".$next."/".$count).'</span>'; 
    
            ?>
    </div>