Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 733745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:17:28+00:00 2026-05-14T07:17:28+00:00

TL;DR: I use PHP inside an external stylesheet, but it doesn’t recognize the ‘/’

  • 0

TL;DR: I use PHP inside an external stylesheet, but it doesn’t recognize the ‘/’ as a PHP divider operator, this messes up my CSS. Any help is appreciated

I’m working on a simple website which loads the menu items dynamically from a page table in the database. 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 that it’s 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 you 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 boring 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 messed up. other operators work.

The way I see it, the divider operator is special to CSS (because of the comments?) and it doesn’t read it as a PHP divider operator but as a CSS symbol.

I’ve tried putting it in a function, the function works, but the divider operator messes 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:17:29+00:00Added an answer on May 14, 2026 at 7:17 am

    This is what went wrong: I added the query string to the wrong CSS file. Nothing wrong with the division operator or anything, just my stupid mind not working too well from staring at my monitor too long.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 424k
  • Answers 424k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are several different PHP packages; probably the one that… May 15, 2026 at 11:53 am
  • Editorial Team
    Editorial Team added an answer e is the event object that the handler receives. You… May 15, 2026 at 11:53 am
  • Editorial Team
    Editorial Team added an answer You may be thinking that when an exception is raised,… May 15, 2026 at 11:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.