turkman Posted July 30, 2008 Share Posted July 30, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/117345-question-about-php-displayed-with-css/ Share on other sites More sharing options...
craygo Posted July 30, 2008 Share Posted July 30, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/117345-question-about-php-displayed-with-css/#findComment-603612 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.