473,378 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Inheritance, variables and CSS

I have inherited a stylesheet that has many of the same values over and
over. Can you use a variable in CSS so I only have to hardcode a
border color once, for instance?

Here is a snip from the current sheet:

.outlook_borderRight1
{
border-right: #ff9900 solid 2px;
}

.outlook_borderBottom1
{
border-bottom: #ff9900 solid 2px;
}

.outlook_borderIFrame
{
border-top: #ff9900 solid 2px;
border-left: #ff9900 solid 2px;
border-right: #ff9900 solid 2px;
}

Since "ff9900" is used over and over, can I just set it once somewhere?
Like

var BORDER_Tabulated_Result : #ff9900;

.outlook_borderBottom1
{
border-bottom: BORDER_Tabulated_Result solid 2px;
}

I know my syntax is wrong, but you (hope, hope) get the idea.

Can using "variables" be done?

Thanks,
Ann
PS: I am a backend programmer, who is new to CSS.

Jan 31 '06 #1
9 2367
Giggle Girl wrote:
Can you use a variable in CSS
No.
Here is a snip from the current sheet:
That's irrelevant, except as evidence that makes it probable that the
style sheet (and quite probably the markup, too) is poorly designed.
Since "ff9900" is used over and over, can I just set it once somewhere?
No, there are no variables in CSS.

You can, however, set e.g.
..foobar { border: solid 2px #f90; }
and then set just e.g. border-style: none for those sides that should
have no border.
PS: I am a backend programmer, who is new to CSS.


Lesson 0: CSS is not a programming language, and won't become one.

P.S. What you wrote about, or what I wrote about, has nothing to do with
inheritance (which is a CSS term and should be used only in that term
meaning when discussing CSS; it is also misunderstood by 99 % of people
who ask questions about CSS inheritance).
Jan 31 '06 #2
Giggle Girl wrote:
I have inherited a stylesheet that has many of the same values over and
over. Can you use a variable in CSS so I only have to hardcode a
border color once, for instance?


No, but see my attempt to explain what inheritance means in CSS, why
OOP-style inheritance isn't needed, and what alternatives there are to
OOP-tyle inheritance.

http://dorward.me.uk/www/css/inheritance/
--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jan 31 '06 #3
Thank you David Dorward for your reply. And the link was extremely
helpfull, too.

Thanks Jukka for your reply as well.

Ann

Jan 31 '06 #4
Furthermore, why do you people insist on asking such stooopid
questions?! Don't you pathetic newbies realize you are wasting my
important time by forcing me to be such an insufferably conceited twit?

Yucky, http://yuckykorpulent.com

Jan 31 '06 #5
Giggle Girl wrote:
I have inherited a stylesheet that has many of the same values over and
over. Can you use a variable in CSS so I only have to hardcode a
border color once, for instance?


As with HTML, the answer is no. And as with HTML, you can use a
server-side technology such as PHP or ASP or ASP.NET to generate the
code dynamically (making sure that at the top of the program or in the
web server configuration for the file, you set the content type of the
response to the proper value--"text/css" in this case). Then you can
have a largely static file with variables inserted wherever you want.
Feb 1 '06 #6
Giggle Girl wrote:
I have inherited a stylesheet that has many of the same values over and
over. Can you use a variable in CSS so I only have to hardcode a
border color once, for instance?

Here is a snip from the current sheet:

.outlook_borderRight1
{
border-right: #ff9900 solid 2px;
}

.outlook_borderBottom1
{
border-bottom: #ff9900 solid 2px;
}

.outlook_borderIFrame
{
border-top: #ff9900 solid 2px;
border-left: #ff9900 solid 2px;
border-right: #ff9900 solid 2px;
}

Since "ff9900" is used over and over, can I just set it once somewhere?
Like

var BORDER_Tabulated_Result : #ff9900;

.outlook_borderBottom1
{
border-bottom: BORDER_Tabulated_Result solid 2px;
}

I know my syntax is wrong, but you (hope, hope) get the idea.

Can using "variables" be done?

Thanks,
Ann
PS: I am a backend programmer, who is new to CSS.


As others have replied, there are no variables in CSS. And people get
upset when you call it a language or even use the phrase "programming"
for CSS.

But the purists can enjoy making objections as much as they like. All
you really want to know is how to *use* CSS to achieve what you want to
do

You could try this
..outlook_borderRight1 , .outlook_borderBottom1 , .outlook_borderIFrame
{
border-right: #ff9900 solid 2px;
}
..outlook_borderIFrame
{
border-top: #ff9900 solid 2px;
border-left: #ff9900 solid 2px;
}
which is quite valid CSS

This is part of the cascading rule.

A border-right style has been defined for .outlook_borderIFrame, so
this cascades into the lower defintion of .outlook_borderIFrame

In effect the style for .outlook_borderIFrame is
{
border-right: #ff9900 solid 2px;
border-top: #ff9900 solid 2px;
border-left: #ff9900 solid 2px;
}
whereas that for .outlook_borderRight1 and .outlook_borderBottom1 is
{
border-right: #ff9900 solid 2px;
}

I think this is what you want.

Feb 1 '06 #7
Tue, 31 Jan 2006 18:53:57 +0000 from David Dorward
<do*****@yahoo.com>:
No, but see my attempt to explain what inheritance means in CSS, why
OOP-style inheritance isn't needed, and what alternatives there are to
OOP-tyle inheritance.

http://dorward.me.uk/www/css/inheritance/


I notice you suggest assigning multiple classes to an element.

IIRC, that's not supported in MSIE. You might want to mention that,
if it's true; otherwise people will complain that your suggestion
"doesn't work" when in fact it's MSIE that doesn't work.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2.1 spec: http://www.w3.org/TR/CSS21/
validator: http://jigsaw.w3.org/css-validator/
Why We Won't Help You:
http://diveintomark.org/archives/200..._wont_help_you
Feb 1 '06 #8
Deciding to do something for the good of humanity, Stan Brown
<th************@fastmail.fm> declared in
comp.infosystems.www.authoring.stylesheets:
I notice you suggest assigning multiple classes to an element.

IIRC, that's not supported in MSIE.


It is supported by IE - from version 5 at least. What isn't supported
correctly is using multiple class selectors *in CSS*, e.g.
p.someclass.otherclass {}

http://css-discuss.incutio.com/?page=MultipleClasses

--
Mark Parnell

I give up:
http://blinkynet.net/comp/uip5.html
Feb 1 '06 #9
Wed, 1 Feb 2006 17:26:52 +1100 from Mark Parnell
<we*******@clarkecomputers.com.au>:
<th************@fastmail.fm> declared in
comp.infosystems.www.authoring.stylesheets:
I notice you suggest assigning multiple classes to an element.

IIRC, that's not supported in MSIE.


It is supported by IE - from version 5 at least. What isn't supported
correctly is using multiple class selectors *in CSS*, e.g.
p.someclass.otherclass {}


Thanks, Mark. I guess my memory was wrong.

It's good to know -- I've had one or two situations where multiple
classes would be useful, but I forbore to use them because of that
issue. Now I can.
--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2.1 spec: http://www.w3.org/TR/CSS21/
validator: http://jigsaw.w3.org/css-validator/
Why We Won't Help You:
http://diveintomark.org/archives/200..._wont_help_you
Feb 1 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Mike Meng | last post by:
hi all, I'm a newbie Python programmer with a C++ brain inside. I have a lightweight framework in which I design a base class and expect user to extend. In other part of the framework, I heavily...
6
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
7
by: Asapi | last post by:
When a derived class inherits from a base class, does the former inherits everything, including public/protected/private instance data, static data, and various methods(static, private/public,...
4
by: Busin | last post by:
When a child class inherits from a base class, will the child class inherits everything of the base class, including all member variables and functions? Or is such inheritance "selective", like not...
2
by: Kevin Newman | last post by:
I have been playing around with a couple of ways to add inheritance to a JavaScript singleton pattern. As far as I'm aware, using an anonymous constructor to create a singleton does not allow any...
6
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public...
3
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public...
36
by: Pacific Fox | last post by:
Hi all, haven't posted to this group before, but got an issue I can't work out... and hoping to get some help here ;-) I've got a base object that works fine with named arguments when called...
12
by: not_a_commie | last post by:
What's the technical reason for not allowing structs to be hierarchical? WPF has a nice Point3D struct. I wanted to add some additional constructors to it for converting from my data types.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.