Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting HTML- anchor tags

Tags:

html

tabs

anchor

Today I was working on a tab navigation for a webpage. I tried the Sliding Doors approach which worked fine. Then I realized that I must include an option to delete a tab (usually a small X in the right corner of each tab).

I wanted to use a nested anchor, which didn't work because it is not allowed. Then I saw the tab- navigation at Pageflakes, which was actually working (including nested hyperlinks). Why?

like image 455
ollifant Avatar asked Aug 21 '08 19:08

ollifant


People also ask

Can you nest anchor tags?

I learned that nesting anchor tags is not standards compliant HTML. From W3: Links and anchors defined by the A element must not be nested; an A element must not contain any other A elements. Since the DTD defines the LINK element to be empty, LINK elements may not be nested either.

How do you nest a tag within a tag?

You cannot nest 'a' tags. Instead set outer container as 'position:relative' and second 'a' as 'position:absolute' and increase its z-index value. You'll get the same effect. Save this answer.


2 Answers

Nested links are illegal

like image 51
Jarosław Przygódzki Avatar answered Oct 21 '22 05:10

Jarosław Przygódzki


They must be doing some really crazy stuff with JavaScript to get it to work (notice how neither the parent nor the nested anchor tags have a name or href attribute - all functionality is done through the class name and JS).

Here is what the html looks like:

<a class="page_tab page_tab">
  <div class="page_title" title="Click to rename this page.">Click & Type Page Name</div>
  <a class="delete_page" title="Click to delete this page" style="display: block;">X</a>
</a>
like image 45
Yaakov Ellis Avatar answered Oct 21 '22 07:10

Yaakov Ellis