Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding :hover style in line 2

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I need to inline style a section of text as in the following code, which styles the ordinary text and works ok but I also need to style the link as well.
How do I set the active and hover params in this example?
I have googled the problem but none of the 'solutions' appear to work.
Code:
<div style='{width:250px; height:337px; padding:5px;}'>
text
<a href='link.htm'>Link</a>
</div>
This section has to be done inline so I cannot take the params from my style sheet.

Keith
 
I have had to come up with a solution and as it is a script created page, I opted for editing the style sheet at run time. This works a treat but I seem to have a caching problem. The stylesheet is edited and saved before the page is called but the changes do not show until after a manual refresh.
Does anyone have any suggestions of how to get round this problem?

Keith
 
Yes, Use a style sheet. Even a secondary one you can apply just for those links is easier than having to come up with scripting methods to bypass it.

I'm sure there's a valid reason why you can't use a style sheet that would be one additional line of code in the page. Heck you could even use styles inside the page in question if you don't want to link to an external file.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Let me explain the problem in a little more detail as you seem to be of the opinion that I am anti stylesheet.
At the moment, users of the portal can select their own colour scheme from a selection of templates, There are 10 different templates each with 9 separate class entries in the stylesheet (90 classes). Some users have asked the host to add more templates and I decided to investigate the possibility of users being able to style their own templates and store their settings in their user profile.
Their pages would then be created dynamically and the relevant inline styles added to their pages. This is all up and running but I have hit a snag with regard to links and hovers, hence the original question in the thread.
I may be approaching this from the wrong direction but I can see being very useful, if I could just see a way through.

Keith
 
I don't think you are anti- style sheets I just think that adding inline styles would seem to me more difficult than adding a style section to the page with whatever you want in it.

If you are already going to the trouble of having a script add additional inline styles to many things in the page, I think it would benefit you more and be easer to maintain if you add a styles section to the page based on the user.

Again it would be pretty much the same method, except you would only need to add in one place: the head of the page and it would have more relevance than the template styles.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I'd do it like this...

1) Anything that isn't adjustable by the user should go in an external style sheet that's common to all users. Stuff like the width, height & padding definition in your original question shouldn't go inline. Remember that you can define a class' properties in multiple places.

2) The user-specific changes should produce a single block of CSS which amends the generic stylesheet referred to above. Either

(a) Produce a dynamically generated external sheet that all pages link to

or (b) Add a <style> element to the <head> of each page that contains the user's customisations.

There's a pay-off to consider here: Method (a) should cache on the user's machine, making the site run faster - but causing temporary problems when they change things. If they don't change things very often, that may not be important. Method (b) gets over the caching problem, but makes each page bigger than it needs to be. If you're only talking about a few lines of CSS, this probably isn't a big issue.

For all that, I find myself more attracted to method (a). It's a more self-contained solution than inserting an element into every page, and there is a work-around for the caching issue. Let's suppose that your user's stylesheet is generated by the url [tt]example.com/style.php?userid=99[/tt]. What you need to do is retrieve a timestamp for the last time the user changed their preferences and add it to the url: [tt]example.com/style.php?userid=99&ts=20083004120000[/tt]. You don't need to change the style generating code - the [tt]ts[/tt] parameter can be ignored, but because the URL is changed it'll force the browser to fetch a new version whenever the user makes a change.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thanks guys
I have tried various methods and inserting inline styles is not a problem as the pages are dynamic anyway. I am only having to investigate new methods because of the issue with hovers. I suggested to the client that all links on the site should be of a colour scheme consistent with the main site and only the main page background and borders should be user defined. It appears that some people would like a black background, bright green text with purple hovers, strange but true.
This is what is moving me towards letting them fully customise the whole thing for their own enjoyment. The inline idea was my preferred method as the params were read from the users profile and their pages were styled from that. The non user defined styles were read from the stylesheet in the normal way.

I have gone with the idea of putting the styles in the head section as this meant that the stylesheet did not need to be edited and each user can have what ever settings they want. I have had a few people test it and it didn't take long for some ???? (insert your own expletive here) to set all the colours to black and wonder why they couldn't read anything.

Keith
 
When you give customization control to people they are likely to do strange things. But of course you can't really control that. Well you could but there would be lots of scripting required.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top