473,890 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_border Right1
{
border-right: #ff9900 solid 2px;
}

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

.outlook_border IFrame
{
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_Tabulate d_Result : #ff9900;

.outlook_border Bottom1
{
border-bottom: BORDER_Tabulate d_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 2384
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_border Right1
{
border-right: #ff9900 solid 2px;
}

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

.outlook_border IFrame
{
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_Tabulate d_Result : #ff9900;

.outlook_border Bottom1
{
border-bottom: BORDER_Tabulate d_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 "programmin g"
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_borde rRight1 , .outlook_border Bottom1 , .outlook_border IFrame
{
border-right: #ff9900 solid 2px;
}
..outlook_borde rIFrame
{
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_border IFrame, so
this cascades into the lower defintion of .outlook_border IFrame

In effect the style for .outlook_border IFrame is
{
border-right: #ff9900 solid 2px;
border-top: #ff9900 solid 2px;
border-left: #ff9900 solid 2px;
}
whereas that for .outlook_border Right1 and .outlook_border Bottom1 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.infosystem s.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.oth erclass {}

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*******@clar kecomputers.com .au>:
<th************ @fastmail.fm> declared in
comp.infosystem s.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.oth erclass {}


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
2873
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 use the instance of this base class (or its children class). How can I ensure the instance IS-A base class instance, since Python is a fully dynamic typing language? I searched and found several different ways to do this:
6
3198
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
425
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, etc.) in base class? What happens to static data and methods during inheritance? What is an accurate definition of inheritance? Thanks!
4
2287
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 inheriting all constructors, assignment operators, destructor, etc.? Thanks!
2
6357
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 kind of inheritance: singletonObj = new function() { this.prop = true; } Here are two ways to create a singleton with inheritance:
6
1684
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 AuthHeaderName As String Public SessionKey As String = "Default" End Class Public Class ServiceTicket:Inherits AuthHeader
3
304
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 AuthHeaderName As String Public SessionKey As String = "Default" End Class Public Class ServiceTicket:Inherits AuthHeader
36
2744
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 on it's own. However when I call the child object I get an error " has no properties (in firefox)." I simple test:
12
7287
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.
0
11222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10811
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10919
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10461
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5846
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4674
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3275
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.