XHTML:将DIV放置在A标记中 [英] XHTML: Placing DIVs in A tags

查看:84
本文介绍了XHTML:将DIV放置在A标记中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吗将div标签放在锚标签中?
将div的内容重定向到锚标签的href?

解决方案


<


是的,如果:


  1. 您正在使用HTML5 / XHTML5;和

  2. 锚标记不在内联上下文中。即只允许短语内容的元素的后代。

否则否。

在HTML5 / XHTML5中,< a> 元素不像HTML4 / XHTML1中的内联元素。相反,它有一个透明的内容模型,这意味着其内容的验证规则是相同的,如果它不存在。



例如

 < div> 
< div> Hello World< / div>
< / div>

有效,所以

 < DIV> 
< a href =#>
< div> Hello World< / div>
< / a>
< / div>

也是。



p>

 < p> 
< div> Hello World< / div>
< / p>

无效,所以

 < p为H. 
< a href =#>
< div> Hello World< / div>
< / a>
< / p>

不是。


Is it alright to place div tags inside anchor tags? Will contents of the div redirect the page to the href of the anchor tag?

解决方案

Is it alright to place div tags inside anchor tags?

Yes, if:

  1. You are using HTML5/XHTML5; and
  2. The anchor tag is not in an inline context. i.e. a descendant of an element that only allows phrasing content.

Otherwise no.

In HTML5/XHTML5 the <a> element in not simply an inline element as it is in HTML4/XHTML1. Instead it has a transparent content model, which means that the validation rules for its content are the same as if it wasn't there.

So for example

<div>
   <div>Hello World</div>
</div>

is valid, so

<div>
   <a href="#">
      <div>Hello World</div>
   </a>
</div>

is too.

But

<p>
   <div>Hello World</div>
</p>

is not valid, so

<p>
   <a href="#">
      <div>Hello World</div>
   </a>
</p>

isn't either.

这篇关于XHTML:将DIV放置在A标记中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆