Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I distinguish between overlapping segments of text using HTML?

Tags:

html

Easy question, it is valid to have overlapping spans in html?

Example:

<span id="1">This is <span id="2"> some text </span> some other text </span>
                                              ^                        ^
                                            End1                     End2

Edit:

I see now that the spans closing tag would be ambiguous about which one it is closing, and that first </span> would close span id = 2, not 1 like I intended.

My problem is, I have a block of text which I'm trying to highlight based on what the mouse hovers over. This block of text is composed of sections, some of which "overlap" eachother. I'm trying to use some jQuery and HTML to present this document so when I hover over the sections, the appropriate one will be highlighted.

So, in my example above, the first span is meant to be ended with the first span close tag, and the second span is meant to be ended to with the second span close tag. This is because of the semantics of my document, these are two overlapping segments.

I want it so when I hover to the left, it will only highlight up to span id = 1 and the first span close, if I hover between the two "overlapping" spans, it will highlight both of them, and if I hover to the right, it will highlight from span id=2 to the last span close.

However, I'm starting to think this isn't possible. Is there any way I can distinguish segments of text in HTML that allows overlapping? So my jQuery script that highlights when I hover over different spans will highlight the correct portions.

Should I alternate between div's and spans? Would that disambiguate what I'm closing then and allow me the do the proper highlighting with my jQuery hover script? I'm wondering about more than 2 segments overlapping now. Sigh, I wish I could just be explicate about what I'm closing.

like image 685
Siracuse Avatar asked Apr 28 '10 00:04

Siracuse


People also ask

Why is my content overlapping in HTML?

The reason for the overlapping lines is quite simple: The line height is not sufficient to contain the text size. You have "hard-coded" the font-size via inline CSS but did not adjust the line-height , for instance.

Is Tag overlapping is allowed in HTML?

If two sets of HTML tags are overlapped, only the first tag will be recognized. You will find this problem when the text does not display properly on the browser screen. Hence answer is false.

What is content overlapping?

Instances of content overlap can be split into two groups; the first involves construct overlap, where an unclear boundary exists between two constructs, and the second involves measurement overlap, where a measure is potentially contaminated with items that better assess a different construct.


1 Answers

No tags can overlap in HTML - they must be properly nested. The HTML you have posted is valid, but may not semantically be what you are expecting. A </span> is going to terminate the previous <span> in the same scope. You haven't identified which <span> you are expecting to be closed with each </span>

<span id="span1">This is <span id="span2"> some text </span> (ends span2) </span> (ends span1)

This would certainly make a big difference in this case:

<span>This is <span> some text </span> and more text </span>
like image 75
Cade Roux Avatar answered Sep 19 '22 21:09

Cade Roux