By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,526 Members | 1,895 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,526 IT Pros & Developers. It's quick & easy.

Variables?

P: n/a
Hi,

does anybody know if it's possible to assign variables within css files?

Best Regards,

Oliver

May 8 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Oliver Block wrote:
does anybody know if it's possible to assign variables within css
files?


It is not possible.

--
-bts
-Warning: I brake for lawn deer
May 8 '06 #2

P: n/a
Oliver Block wrote:
does anybody know if it's possible to assign variables within css files?


http://dorward.me.uk/www/css/inheritance/ might be of use.

May 8 '06 #3

P: n/a
Beauregard T. Shagnasty wrote on 08 mei 2006 in
comp.infosystems.www.authoring.stylesheets:
Oliver Block wrote:
does anybody know if it's possible to assign variables within css
files?


It is not possible.


except serverside.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 8 '06 #4

P: n/a
Evertjan. wrote:
Beauregard T. Shagnasty wrote:
Oliver Block wrote:
does anybody know if it's possible to assign variables within css
files?


It is not possible.


except serverside.


which would be writing a new/different CSS with each page-serve. <g>

--
-bts
-Warning: I brake for lawn deer
May 8 '06 #5

P: n/a
Beauregard T. Shagnasty wrote on 08 mei 2006 in
comp.infosystems.www.authoring.stylesheets:
Evertjan. wrote:
Beauregard T. Shagnasty wrote:
Oliver Block wrote:

does anybody know if it's possible to assign variables within css
files?

It is not possible.


except serverside.


which would be writing a new/different CSS with each page-serve. <g>


css files are read and "execute" once anyway.
My suggestion means the css-fiel cashing has to be switched off,
so is not very practical.

in-file css however can easily be modified by serverside scripting:

<style>
body {font-size:<%=request.cookies("fontSz") %>pt;}
....

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 8 '06 #6

P: n/a
On Mon, 08 May 2006 16:51:33 GMT Beauregard T. Shagnasty <a.*********@example.invalid> wrote:
| Evertjan. wrote:
|
|> Beauregard T. Shagnasty wrote:
|>
|>> Oliver Block wrote:
|>>
|>>> does anybody know if it's possible to assign variables within css
|>>> files?
|>>
|>> It is not possible.
|>
|> except serverside.
|
| which would be writing a new/different CSS with each page-serve. <g>

Generate it with PHP. PHP has variables.

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
May 8 '06 #7

P: n/a
Beauregard T. Shagnasty wrote:
except serverside.
which would be writing a new/different CSS with each page-serve. <g>


Only if you fail to send suitable cache control headers.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
May 8 '06 #8

P: n/a
On Mon, 08 May 2006 17:54:17 +0200 Oliver Block <ne********@block-online.eu> wrote:

| does anybody know if it's possible to assign variables within css files?

Do you want variables that are evaluated once?

CSS appears to be a language that defines the construction of a lookup table
which is (frequently) accessed for property information. If CSS were to
have an ability to assign values to variables and substitute them, it would
likely do so once as the code is parsed and evaluated, and the constants
placed in that lookup table structure.

Do you want variables that are evaluated at every lookup access?

Something would have to change those variables between lookup accesses for
that to have any useful effect. Would this be done in Javascript? What
about a DOM structure for the stylesheet?

Could special relationships be sufficient?

Maybe a value for one property could be based on some aspect of an object
already rendered, or to be rendered, such as specifying the width of one
object to be the same as that of another object, or the width to be twice
its height (say, to set a fixed aspect ratio).

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
May 8 '06 #9

P: n/a
On Mon, 08 May 2006 20:41:24 +0100 David Dorward <do*****@yahoo.com> wrote:
| Beauregard T. Shagnasty wrote:
|>> except serverside.
|
|> which would be writing a new/different CSS with each page-serve. <g>
|
| Only if you fail to send suitable cache control headers.

I think he means that the content would be different, and that a new CSS
file would have to be sent each time. If variable substitution is done
server-side, you'd have to disable caching, and then you'd have a new CSS
delivered each time, whether same or different. The idea I think he is
wanting to do is have some values in the CSS file be variables that can
be substituted at some point (based one something doing that, I know not
what) so that only one CSS file serves all purposes.

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
May 8 '06 #10

P: n/a
ph**************@ipal.net wrote:
On Mon, 08 May 2006 20:41:24 +0100 David Dorward <do*****@yahoo.com> wrote:
| Beauregard T. Shagnasty wrote: [Evertjan wrote:]|>> except serverside.
|
|> which would be writing a new/different CSS with each page-serve. <g>
|
| Only if you fail to send suitable cache control headers.
Only if the same named external css file is rewritten.
I think he [the OP] means that the content would be different, and
that a new CSS file would have to be sent each time. If variable
substitution is done server-side, you'd have to disable caching, and
then you'd have a new CSS delivered each time, whether same or
different. The idea I think he is wanting to do is have some values
in the CSS file be variables that can be substituted at some point
(based one something doing that, I know not what) so that only one
CSS file serves all purposes.


I think you're right, phil. The OP didn't indicate that he knows about
(or thought about) writing CSS on-the-fly, so to speak.

It is trivial to write code to add or change <style></style> blocks in
the head of the pages.

--
-bts
-Warning: I brake for lawn deer
May 8 '06 #11

P: n/a
On Mon, 08 May 2006 20:58:37 GMT Beauregard T. Shagnasty <a.*********@example.invalid> wrote:
| ph**************@ipal.net wrote:
|
|> On Mon, 08 May 2006 20:41:24 +0100 David Dorward <do*****@yahoo.com> wrote:
|>| Beauregard T. Shagnasty wrote:
| [Evertjan wrote:]
|>|>> except serverside.
|>|
|>|> which would be writing a new/different CSS with each page-serve. <g>
|>|
|>| Only if you fail to send suitable cache control headers.
|
| Only if the same named external css file is rewritten.

If it is really a dynamically generated object at the server, such as
a CGI program/script, or PHP, then that would be the effect of being
rewritten.
|> I think he [the OP] means that the content would be different, and
|> that a new CSS file would have to be sent each time. If variable
|> substitution is done server-side, you'd have to disable caching, and
|> then you'd have a new CSS delivered each time, whether same or
|> different. The idea I think he is wanting to do is have some values
|> in the CSS file be variables that can be substituted at some point
|> (based one something doing that, I know not what) so that only one
|> CSS file serves all purposes.
|
| I think you're right, phil. The OP didn't indicate that he knows about
| (or thought about) writing CSS on-the-fly, so to speak.
|
| It is trivial to write code to add or change <style></style> blocks in
| the head of the pages.

Perhaps what he had in mind was a big CSS file that had several variable
references within, and an @import for another CSS file that would have
some kind of settings for those variables. The big file can be cached
because it is static and never changes, while the other file might be
small and perhaps dynamically generated. Or maybe he will set those
variables in the HTML, such as within <style></style> if CSS did have a
way to set and use variables. It's an interesting concept. I'm not
sure how generally (as in for everyone) useful it would be.

I've found that some of what would otherwise be complex things can in fact
be done fairly simple by just referencing multiple classes from HTML elements
and letting the effects of those classes mix appropriately. I don't know
what the OP ultimately wants to accomplish, so I don't know if this would be
at least some way around his issue, or not.

As far as I know, there is no need for the file extension to be ".css" for
a file to be used as style. It just needs the correct MIME type and be
referenced in the appropriate context. If the extension is ".php" then
he could generate it with PHP easily enough by having the server treat it
as such.

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
May 9 '06 #12

P: n/a
RC
Oliver Block wrote:
does anybody know if it's possible to assign variables within css files?

Hahaha.....!! I know what you want, but the answer is impossible.

Sometimes, you can use JavaScript to change the value(s) of CSS.
May 10 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.