1

I am trying to customize the links on my site that are inserted via php. The reason they are inserted via php is for checking user login and editing the log options (the links in question) depending on their status so removing them from php is a no go as far as I can see. I've tried inline and external styling, and though, if I remember correctly, it has worked in the past for other things, it just will not work for these links. Anyone have any good ideas?

Here is the (immediate) code:

       $logOptions = $PM_envelope . '&nbsp;&nbsp; <a href="../index.php">home</a> &nbsp; <a href="../profile.php">profile</a> &nbsp; <a href="../settings.php">settings</a> &nbsp; <a href="../logout.php">logout</a>' ;

The styles are this:

     .loginmenulinks a:link {
         color:#09C; 
         text-decoration:none;
         font-family:GeosansLight, sans-serif; 
         font-size:12px;
         }

same for hover, etc.

I call for this in a div in the header:

   <div><?php echo $logOptions; ?></div>
4
  • Can you show us some of your code? Anything you dynamically add via PHP should still be styled by whatever stylesheets you currently have linked up to the document. Commented Apr 6, 2012 at 20:27
  • its quite long but ill add some to the question, just give me a second. Commented Apr 6, 2012 at 20:30
  • If you can give us a shortened example, that would be great. Commented Apr 6, 2012 at 20:32
  • I've added the log options itself where I have tried inline style and assigning classes, if you need me to I can add the surrounding code, but it is all working fine, including displaying the log options based on the log in of the user, just not the css. Commented Apr 6, 2012 at 20:37

2 Answers 2

1

Why in the world is there "no way to customize" the CSS of a link that PHP generated? PHP generates HTML, HTML and CSS are on the browser side. The browser has no way of knowing what came from PHP and what didn't, so how can it discriminate against such dynamic content?

<?php echo "<a href=\"#\" class=\"blah\">Text</a>"; ?>

CSS:

.blah {color: orange;}

Suddenly, an orange link appears.

Are you forgetting to maybe specify any styles in the first place?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for this answer, in regards to customization of a link generated by php, from what I've read and experienced an external style sheet doesn't work for php, but the logic in your statement makes sense, perhaps I, and those who have written what I've read have just been doing it wrong. In regards to the suggested code, this didn't work unfortunately. I am not sure by what you mean by did I forget to specify the styles, I made the style sheet and linked to it as above, I also did inline styles, none of them worked. Thanks for the post, and if I'm missing something please fill me in.
Perhaps it is not working because I am not echoing the links themselves, instead I am echoing logoptions in the header file, however this is connected to the same external style sheet?
0

You may add additional classes or id's to the a-tags to gain the ability to add your stylessheets from an external resource.

However it is not a good Idea to keep such things in your PHP Code, you should use some seperation between a view and a logical layer in your application.

Furthermore you should not use &nbsp; but css to gain spacing, as it is not intended to do that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.