which of this html markup is more right

Kyojimaru

I have a HTML markup for each brand in my page like this

<ul>
    <li>
        <a title="mallname" href="/brand/mallname">
            <div class="image">
                <img src="/Images/mallname.png" alt="mallname" />
            </div>
            <div class="title">
                <h2>mallname</h2>
            </div>
        </a>   
    </li>
</ul>

is that heading position ok inside a hyperlink, or should I change it to

<ul>
    <li>    
        <h2>
            <a title="mallname" href="/brand/mallname">
                <div class="image">
                    <img src="/Images/mallname.png" alt="mallname" />
                </div>
                <div class="title">
                    mallname
                </div>
            </a>   
        </h2>
    </li>
</ul>

which one is the more right way to write it, and what is the result that will be read by crawler for the heading in both case?

If in the first one, the heading content is only mallname, will the second one be read as mallname mallname mallname as there is a title attribute in the hyperlink and alt attribute in the image inside the heading

here's one of the result of the list item

Result Image

unor

In your first example, the h2 doesn’t describe the content of the li. In scope of this heading is everything following it, until the next heading starts. So in fact, the previous heading would describe the following content, and so on. This problem always arises when using headings without sectioning elements in lists.

In your second example, the h2 probably contains more than it should (two times "mallname"; the one in the title attribute is not considered to be part of the heading content). But what is the actual content here? There is only a heading, which doesn’t seem to make sense.

Your alt content is probably not correct/useful. When it is exactly the same as the corresponding heading, the you should probably use an empty alt value. But it’s likely that the image represents something in addition to the heading: describe this in the alt content.

Duplicating the heading content in the title attribute doesn’t seem to make sense, either. Only use it for additional helpful (but not essential) content.

So you should use something else: sectioning elements. Judging from the screenshot, it might be the case that article is appropriate (if not, use section).

By using a sectioning element like article, the heading doesn’t have to be placed on the top.

<ul>
  <li>
    <article>
      <a href="/brand/mallname">
        <img src="/Images/mallname.png" alt="Mallname offers … and …. It’s ….">
        <h2>mallname</h2>
      </a>
    </article>
  </li>
</ul>

However, use this only when the h2 describes the ìmg! When the image is only an alternative to the heading (or only decoration, and the actual image content isn’t relevant in this context), why use headings at all? In that case you’d have just a list of links:

<ul>
  <li><a href="/brand/mallname"><img src="/Images/mallname.png" alt=""> mallname</a></li>
</ul> 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Haskell: `reverse` or right `cons`, which is more efficient

From Dev

Haskell: `reverse` or right `cons`, which is more efficient

From Dev

Setting regular expression to test input text which contain HTML markup

From Dev

Form inside table or table inside form, which one is the right for valid Twitter Bootstrap markup?

From Dev

Is there a more succinct way to have an html column all align=right?

From Dev

NSString without HTML markup

From Dev

Overlapping HTML Markup

From Dev

Removing all html markup

From Dev

Literal HTML markup doxygen

From Dev

Logic and markup, html and php

From Dev

Remove HTML MarkUp

From Dev

push td to the right without extra markup

From Dev

How to get an image HTML which parent has more children?

From Dev

Match HTML elements which have two or more <br> elements in a string

From Dev

How to get an image HTML which parent has more children?

From Dev

combobox as gridcolumn in ExtJs 4.2. Which one is better and more importantly right way to do

From Dev

R markup Loading more than one package

From Dev

Storing HTML markup in a PHP string

From Dev

Correct HTML Markup for Diagram References

From Dev

Timeout an HTML markup in AJAX Success

From Dev

Weird issue with PHP and html markup

From Dev

XPATH Needed from HTML Markup

From Dev

How to make responsive HTML markup?

From Dev

Storing HTML markup in a PHP string

From Dev

HTML markup small table in the side

From Dev

If statement inside html email markup

From Dev

Put HTML markup in PHP if function

From Dev

HTML5 markup for a slideshow

From Dev

Timeout an HTML markup in AJAX Success