TL;DR: I use PHP inside an external stylesheet, but it doesnt recognize the '/' as a PHP divider operator, this messes up my css any help is appreciated
OK so here's the deal.
I'm working on a simple website (I'm an intern, the assignment is not that hard, but i want to do it right) which loads the menu items dynamically from a page table in the dbase. with a recursive algorithm i get all the pages, and the child pages at the right place. In this function i count the amount of main menu items.
I do this because i need to make every <li>
in the main menu <ul>
such a width that it covers the whole width of the menu bar. I want this to be done dynamically so that if more pages are added as a main menu item, nothing has to change, only an insert to the database.
Now my question. i read right here: http://www.webmasterworld.com/forum83/2201.htm that its possible to configure apache so that it reads css as php files. Works as a charm, nothing wrong. Now i have:
<link rel="Stylesheet" type="text/css" href="<?php echo base_url().'css/css-reset.css'.'?item_count='.$menu_count; ?>" />
In my header ( as yuou can see i pass the menu item count as a post variable. This also works. My css:
<?php Header ("Content-type: text/css");?>
<?php
$wrapper_width = 900;
$menu_item_count = (int)$_REQUEST['item_count'];
$menu_item_width = $wrapper_width / $menu_item_count;
?>
/*lots more bhroing css */
div#wrapper
{
text-align:left;
width:<?php echo $wrapper_width.'px'; ?>;
}
div#menu a
{
display:block;
height:1.7em;
width:<?php echo $menu_item_width.'px'; ?>;
}
And this is where a weird thing comes up. if i set the $menu_item_count
to be just an int (ex: $menu_item_count=150
) it works as it should. But as soon as i use the divider operator between the two variables the css gets fucked up. other operators work.
the way i see it, the divider operator is special to css ( because of the comments?) and it doesnt read it as a php divider operator but as a css symbol.
Ive tried putting it in a function, the function works, but the divider operator fucks it up again.
So my questions are: Anyone ever worked with PHP in external Stylesheets? If so, can you help me figure out this problem?
Regards,
Menno