can I define constants in HTML ... if yes what is the syntax

liunx

Guest
Hi, I wonder if I can define my own constant in HTML just like 'red' is a constant. Lets say that I use a certain value like a font size in many places in my code and want to be able to change it in one place for the change to be carried out where ever I use the constant. Can I do that ? If yes, what is the syntax and can I define the constant and assign it its value in the header secton of the HTML file and use it in the body section.<br />
<br />
Thanks<br />
Salam<!--content-->It's called CSS.<br />
<br />
To define a text size try something like this:<br />
<br />
<style type="text/css"><br />
body<br />
{<br />
font-size: 14 px;<br />
}<br />
</style><br />
<br />
That will set the default font size for all text on your page to 14 px...<!--content-->...and the beauty is of course that you can define your own:<br />
<br />
so you could have something like<br />
<br />
.info{<br />
text-align: "center" ;<br />
color: #989898 ;<br />
font-size: "75%" ;<br />
font-weight: "bold" ; <br />
margin: 5px ; }<br />
<br />
and in your html you would say <br />
<br />
<p class="info">This text would be formatted as specified above</p>, and it would be.<!--content-->Hi, thanks for your repply again :) The answers were usefull for me even though I didn't mean it that way.<br />
<br />
What I ment with the original question is as a general rule in HTML & not restricted to fonts wether or not I can define constants. If I can then what is the syntax. In other words, can I define a constant to be the number 5 and use that constant in my code where ever I can use the number 5.<br />
<br />
Example that ilustrates what I mean:<br />
----------------------------------------<br />
<br />
<head><br />
fontsize_1: 40 px;<br />
fontsize_2: 20 px;<br />
</head><br />
<br />
<body><br />
<br />
<font size=fontsize_1 ><br />
font test 1 <br />
</font><br />
<br />
<font size=fontsize_2 ><br />
font test 2 <br />
</font><br />
<br />
</body> <br />
<br />
----------------<br />
Its clear that I can achieve that for fonts (in the way jpmoriarty explained) BUT MY QUESTION IS GENERAL AND NOT RESTRICTED TO FONTS. <br />
----------------<br />
<br />
Thanks<br />
Sam<!--content-->HTML is built upon SGML and XHTML is built upon XML and both SGML and XML have constants. They're called entities and they're declared in the Document Type Definition. In the HTML 4.01 DTD you will find:<br />
<br />
<!ENTITY copy CDATA "&amp#169;"><br />
<br />
When you use &copy; the browser understands &169;. And you can add your own entities to a DTD:<br />
<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" <br />
[<!ENTITY foo "fee, fie, foe, fum">]><br />
<br />
Note: that second example is from XHTML which defines entities just a little bit differently that HTML does. And the entities can also represent the content of other files. The problem with all of this is that browser support is spotty to say the least. MSIE 6 will pay attention to your entities, but only in XML mode. You will have to use XHTML and use the XML file extension. And if you do not include an XSLT style sheet, then MSIE will display the tree structure of the document. The solution is to pre-process your XML files and transform them into HTML. I've been using Saxon for this and it seems to work quite well. However, if you are still using the FONT element then this is way over your head.<!--content-->
 
Back
Top