473,399 Members | 2,159 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,399 software developers and data experts.

Adding a text marker to TD elements with CSS

I need to set up forms where some input fields are mandatory and
others are optional. A common convention is to place an asterisk on
the labels of the mandatory fields. Of course, I can just hard code
these asterisks, but I'd have thought it would be better to use a CSS
element to control how a mandatory field should be marked. For example
(using a table to lay out the fields):

<tr><td class=mandatory>Label 1:</td><td><input ....></td></tr>
<tr><td class=optional>Label 2:</td><td><input ....></td></tr>

I cannot find out how to set up a CSS element so that a piece of text
is added to the content.

(I realise it can be done with the :BEFORE pseudo-element, but it
doesn't work in IE6, which is the primary browser amongst users of
this site).

Any suggestions gratefully received.
Sep 16 '08 #1
6 4607
In our last episode,
<c5**********************************@2g2000hsn.go oglegroups.com>, the
lovely and talented Clive Backham broadcast on
comp.infosystems.www.authoring.html:
I need to set up forms where some input fields are mandatory and
others are optional. A common convention is to place an asterisk on
the labels of the mandatory fields. Of course, I can just hard code
these asterisks, but I'd have thought it would be better to use a CSS
element to control how a mandatory field should be marked. For example
(using a table to lay out the fields):
><tr><td class=mandatory>Label 1:</td><td><input ....></td></tr>
<tr><td class=optional>Label 2:</td><td><input ....></td></tr>
I cannot find out how to set up a CSS element so that a piece of text
is added to the content.
You cannot use CSS to add text to an element. You could use CSS to display
(or not) text that is already there:

<tr><td class=mandatory><span>*</span>Label 1:</td><td><input ....></td></tr>
<tr><td class=optional><span>*</span>Label 2:</td><td><input ....></td></tr>

..optional SPAN { display: none; }

In this case, you hide the asterisk for optional fields. But the asterisk
is in the text and will show in text browsers or when CSS is off.

There are also various tricks you can do with images, such as adding an
image with an asterisk as background to elements that are mandatory. This
too breaks more-or-less horribly in text browsing and requires special
attention if the page is to be printed successfully.

In both cases, CSS did not add text. In one case it hid text. In the other
it added a background image. CSS cannot alter the text.
(I realise it can be done with the :BEFORE pseudo-element, but it
doesn't work in IE6, which is the primary browser amongst users of
this site).
Any suggestions gratefully received.
--
Lars Eighner <http://larseighner.com/us****@larseighner.com
Love: The warm feeling you get towards someone who meets your neurotic needs.
Sep 16 '08 #2
Lars Eighner wrote:
In both cases, CSS did not add text. In one case it hid text. In the other
it added a background image. CSS cannot alter the text.
Well, yes, it *can* add text, using the content property with the
:before and :after pseudoelements, as the OP pointed out--when that
feature is supported, which it isn't in IE6 or IE7.
Sep 16 '08 #3
Clive Backham wrote:
I need to set up forms where some input fields are mandatory and
others are optional. A common convention is to place an asterisk on
the labels of the mandatory fields. Of course, I can just hard code
these asterisks, but I'd have thought it would be better to use a CSS
element to control how a mandatory field should be marked. For example
(using a table to lay out the fields):

<tr><td class=mandatory>Label 1:</td><td><input ....></td></tr>
<tr><td class=optional>Label 2:</td><td><input ....></td></tr>

I cannot find out how to set up a CSS element so that a piece of text
is added to the content.

(I realise it can be done with the :BEFORE pseudo-element, but it
doesn't work in IE6, which is the primary browser amongst users of
this site).
Yes, that *is* the way to do it in CSS and, yes, it doesn't work in IE,
so practically speaking you're out of luck.

However, given that your indicating whether a field is mandatory or not
is a significant piece of information, not just a stylistic detail, it
makes perfectly good sense to represent that information in the HTML and
not relegate it to the CSS.
Sep 16 '08 #4
Thanks to all who have replied.

On 16 Sep, 13:32, Harlan Messinger <hmessinger.removet...@comcast.net>
wrote:
However, given that your indicating whether a field is mandatory or not
is a significant piece of information, not just a stylistic detail, it
makes perfectly good sense to represent that information in the HTML and
not relegate it to the CSS.
I understand where you're coming from. My rationale in wanting to use
CSS was that if for some reason in the future I decide (or am asked)
to change the visual indicator from an asterisk to something else, it
would be a lot easier to edit one CSS element definition than change
the text in possibly dozens of HTML files. Or am I missing something?
Sep 16 '08 #5
Gazing into my crystal ball I observed Clive Backham
<go****@delback.co.ukwriting in news:2ba0367c-87a5-43c1-ac4f-
4f**********@k30g2000hse.googlegroups.com:
Thanks to all who have replied.

On 16 Sep, 13:32, Harlan Messinger <hmessinger.removet...@comcast.net>
wrote:
>However, given that your indicating whether a field is mandatory or
not
>is a significant piece of information, not just a stylistic detail,
it
>makes perfectly good sense to represent that information in the HTML
and
>not relegate it to the CSS.

I understand where you're coming from. My rationale in wanting to use
CSS was that if for some reason in the future I decide (or am asked)
to change the visual indicator from an asterisk to something else, it
would be a lot easier to edit one CSS element definition than change
the text in possibly dozens of HTML files. Or am I missing something?
I usually do something like:
<label class="required" for="field" id="field1">Field *</label>

..required {font-weight:bold; color: red;}

Users with CSS enabled will get a bold red label, and users without will
still get the asterisk, or as my Puerto Rican friend used to say "Leetel
Star" (from Greek asteriskos, literally, little star, diminutive of
aster-, aster).

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

Sep 16 '08 #6
Clive Backham wrote:
Thanks to all who have replied.

On 16 Sep, 13:32, Harlan Messinger <hmessinger.removet...@comcast.net>
wrote:
>However, given that your indicating whether a field is mandatory or not
is a significant piece of information, not just a stylistic detail, it
makes perfectly good sense to represent that information in the HTML and
not relegate it to the CSS.

I understand where you're coming from. My rationale in wanting to use
CSS was that if for some reason in the future I decide (or am asked)
to change the visual indicator from an asterisk to something else, it
would be a lot easier to edit one CSS element definition than change
the text in possibly dozens of HTML files. Or am I missing something?
Use a server-side include. Or create a server-side variable to contain
the asterisk and insert the variable everywhere in server-side code. ASP
example:

dim reqMark
reqMark = "*"

...

E-mail address<%=reqMark%>: <input ...
Sep 16 '08 #7

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

Similar topics

4
by: Werner Partner | last post by:
I'm looking for something like that: http://www.sonoptikon.de/praxis-mt/test.php The text should have a certain indent, and from the left border should come a "marker" which goes over the text...
5
by: kj | last post by:
I have elements of the form <TD><A name="marker"></A>foobar</TD> and I want to extract the text "foobar". How can I do this in IE? (I think I know how to do it for NS). Is there a way to...
15
by: crjunk | last post by:
I have 4 TextBoxes on my form that I'm trying to add together to get a grand total. Here is the code I'm using: <SCRIPT LANGUAGE="JavaScript"> <!-- Beginning of JavaScript - function...
1
by: Mickey | last post by:
Hi, I have a script which works in both IE but is sluggish in Firefox. The script is a simple text scroller. It works perfectly in IE however in Firefox, the text scroll slower and eventually...
9
by: Michelle | last post by:
I have a div that is initially empty. Clicking on a button will add some text boxes and other controls so the user can add additional records. In IE all works fine but in Netscape 7.0 when I add...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
4
by: SAM | last post by:
rfr a écrit : This below works for me in Firefox, you can put this script in the head of your page(s) <script language="JavaScript1.2" type="text/javascript"> // Based on watermark script...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.