Helpful Information
 
 
Category: CSS Help
PHP and CSS problem

The following is an example of what's in a cs.css.phtml style sheet:

p {font-family:arial; font-size: <? echo $sp; ?>pt; color:<? echo $p; ?>}
p.sm {font-family:arial; font-size: <? echo $spsm; ?>pt; color:<? echo $psm; ?>}
p.bbig {font-family:arial; font-size: <? echo $spbig; ?>pt; color:<? echo $pbig; ?>}

There is a table with size and color values for the styles defined above. The color portions work fine, however the size attribute is not working as intended.

When I link to the stylesheet (or include the code directly on the page itself), any p class style is treated as the first p above. In other words, <p class="bbig"> is the same size as <p>, despite having different numerical values.

Someone mentioned before that they had successfully managed to integrate PHP with CSS. I'd like to know if I'm doing this correctly, or if I'm missing something important.

Thanks!

Not very experienced with CSS, but syntactically the only difference between your color definitions and size is that there is no space after the colon in

color:<? echo $p; ?> etc. and there is one after the font-size:. Maybe that's the problem. *crosses fingers* Also you don't technically need the semi-colon to end a statement if the "<?" and "?>" are on the same line. Not a big deal, just pointing out.

Good suggestions, but unfortunately no dice.

The color will change, but not the font size.

I think the problem may be with your installed fonts and your font-family declaration. Try changing that declaration to "font-family: arial,sans-serif;" and I think that may help you out.

Also, it's usually cleaner to define font sizes in px instead of pt.

If that doesn't work out for you, you may want to double-check that your variables are actually getting assigned.

Hope this helps!

p {font-family:arial; font-size:8pt; color:black}
p.sm {font-family:arial; font-size:8pt; color:black}
p.big {font-family:arial; font-size:12pt; color:black}

Looks A-OK to me.

.............

I'm testing a seperate phtml document, with only some text and the style sheet.

So far everything is working as it should.

I just substituted php variables for size numbers, and it works. Trying with colors and numbers... that works also. *scratches head*

Problem solved.

I used AddType to make apache parse .css files with php.

That seemed to do it. The external, php equipped style sheet is working like charm now.

Thanks for your input!










privacy (GDPR)