Can I combine <span> tags at runtime?

E

Ethan Strauss

Hi,
I have some methods which generate html formatting for text on the fly. I
generally use <span> tags and that works fine. But, I would like to be able
to combine different formatting elements on the fly. For example if I have
<span text-decoration: "underline">
and want to add to that
<span BACKGROUND-COLOR:"red">,
I would get
<span text-decoration:"underline"; Background-Color:"red"> (or whatever the
correct syntax is).

Before I embark on writing my own struct to do this, does anyone know if
something like this exists already or if there is a better way?
Thanks!
Ethan

Ethan Strauss Ph.D.
Bioinformatics Scientist
Promega Corporation
2800 Woods Hollow Rd.
Madison, WI 53711
608-274-4330
800-356-9526
(e-mail address removed)
 
P

Peter Bromberg [C# MVP]

You haven't really provided a lot of background information, but essentially
what it looks like you want is this:

<span style="text-decoration:underline; background-color:red;">

You can see how the CSS style selector attributes are presented. Or, you can
use a separate CSS style sheet with named classes, thus:

<span class="myCustomSpan">

There are really a lot of different HTML / CSS markup generators out there
in the wild, but without knowing more about exactly how your situation works
it would be difficult to recommend one. Is the HTML going to be served via
the web into a user's browser? In that case, you have the ASP.NET Framework.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: htp://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net
 
E

Ethan Strauss

Thanks for the reply!
Here is some more detail. I hope it clarifies things.


I have a Formatter class which formats strings (generally DNA sequences).
This class contains Format structs which have start points, end points, and
formatting tags.
The way it works is that the formatter class steps through each character in
the string and checks if there is formatting which is supposed to start at
that position or end at that position. If so, it inserts the appropriate open
or close tag.
The problem is that the specific formats desired for a string are determine
on the fly and can overlap. For example, with a string of 100 characters I
could have a pair of format objects like this
Format object 1:
start = 10
end = 50
tag = "<span text-decoration:underline>"
Format object 2:
start = 40
end = 80
tag = "<span background-color:red >"

I would then want the string to come out with characters from 40 to 50 both
underlined and highlighted in red.


In this situation it is pretty easy, but it is not so simple if I allow
arbitrary styling commands in the two Format objects are allow for the
possibility of three (or more) overlapping formats. If I need to, I write my
own formatting type structure which will deal with some of this, but if
something already exists that would be great!
Thanks,
Ethan

ps. You might take a look at
http://epicentersoftware.com/images/sequence_a.jpg It contains some fomatting
of the sort I want to be able to generate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top