Jump to content

Recommended Posts

Hey, i like to do all my formatting in css so i never have any html formatting in my pages. For the most part it works well. But now that i'm doing some more advanced things with php im having a problem. For example if i want to display

 

Number of posts: 20

 

If i want the "number of posts" bit to be styled a certain way and the 20 to be styled different i run into problems.

 

I usually have it in a single div like this

 

echo "<div class =\"numberofposts\">Number of posts:" .$numberofposts."</div>";

Then obviously when i changed the style properties of numberofposts in css both would change and look the same. To combat that i tried splitting it into two divs

 

echo "<div class =\"numberofposts\">Number of posts:</div><div class=\"result\"" .$numberofposts."</div>";

 

When i do that i can get the text to display how i want, but it displays on two lines as opposed to 1 line. I suppose i could mess around with the sizes of the divs but that seems akward.

 

so what i have been doing is adding a bold tag and formatting the numberofposts b{} in the css

 

echo "<div class =\"numberofposts\">Number of posts:<b>" .$numberofposts."</b></div>";

 

Again this isnt 100 ideal, because mabye i want to use the bold tag later in the same div but its style has been changed. Is there any proper way of doing this without using html formatting on the page?

 

 

Link to comment
https://forums.phpfreaks.com/topic/117345-question-about-php-displayed-with-css/
Share on other sites

you can use the span tag and some funky css

 

<style>
.numberofposts {
  font-size: 18px;
  color: red;
}

.numberofposts span {
  font-size: 20px;
  color: green;
  font-weight: bold;
}
</style>
<?php
$numberofposts = 40;
echo "<div class =\"numberofposts\">Number of posts: <span>" .$numberofposts."</span></div>";
?>

 

in the style ".numberofposts span" you are formatting the span tag INSIDE the numberofposts class. So only the span tags withing this particular div will have the format.

 

Ray

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.