使div成为一个链接 [英] making a div a link

查看:83
本文介绍了使div成为一个链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个完整的div,成为一个链接。


i目前有代码

I need to make a whole div, become a link.

i currently have the code

展开 | 选择 | Wrap | 行号

推荐答案


我需要制作一个完整的div,成为一个链接。


i目前有代码

< a href =" temp.html">< div>一些文字< / div>< / a>


但是这并没有验证为xhtml严格。


将链接放在div中只会使文本成为链接而不是整个di v。

我之所以有div的原因是因为我用它来创建一个盒子并为它添加彩色背景。


我还需要能够通过列表项来实现相同的功能。

例如我目前有

< ul>

< a href =" temp.html">< li> item 1< / li>< / a> ;

< a href =" temp2.​​html">< li> item 2< / li>< / a>

< a href = " temp3.html">< li>第3项< / li>< / a>

< / ul>


不验证
I need to make a whole div, become a link.

i currently have the code
<a href="temp.html"><div>some text</div></a>

but this does not validate as xhtml strict.

putting the link in the div will only make the text a link and not the whole div.
the reason i''ve got the div in there is becuase i use it to create a box and add a colored background to this.

I also need to be able to achieve the same thing, with a list item.
e.g. I currently have
<ul>
<a href="temp.html"><li>item 1</li></a>
<a href="temp2.html"><li>item 2</li></a>
<a href="temp3.html"><li>item 3</li></a>
</ul>

which does not validate



它没有验证,因为它应该是这样的:



[HTML] < div>< a href =" temp.html">一些文字< / a>< / div> [/ HTML]


[HTML]< ul> ;

< li>< a href =" temp.html"> item 1< / a>< / li>

< li>< ; a href =" temp2.​​html"> item 2< / a>< / li>

< li>< a href =" temp3.html"> item 3< ; / a>< / li>

< / ul> [/ HTML]


我不知道你在哪里学习,但是我会停下来尝试这里这是一个非常好的HTML教程。



希望它有所帮助,死亡

It doesn''t validate because it should be like this:


[HTML]<div><a href="temp.html">some text</a></div>[/HTML]

[HTML]<ul>
<li><a href="temp.html">item 1</a></li>
<li><a href="temp2.html">item 2</a></li>
<li><a href="temp3.html">item 3</a></li>
</ul>[/HTML]

I don''t know where your learning from, but I would stop. Try here It''s a pretty good tutorial on HTML.


Hope it helps, Death


他知道它应该是死亡的方式,但是他想让ENTIRE div成为一个链接,我不确定该怎么做,除非你使用Javascript,此时它将是

[html]

< div OnClick =" document.location =''http: //google.com''"><noscript><a href =" http://google.com">< / noscript> some text< noscript>< / a>< / noscript>< / div>

<! - 那么,除非客户端没有javascript,否则你会获得链接的div,这将导致文本成为链接.--> ;

<! - 同样适用于您的清单 - >

< ul>

< li OnClick =" document.location =''http://yahoo.com''">< noscript>< a href =" http://yahoo.com" >< / noscript>更多文字< noscript>< / a>< / noscript>< / li>

< / ul>

[/ html]

这有帮助吗?我想不出XHTML严格的做法,否则......


哦,w3schools.com是HTML,CSS和PHP(恕我直言)的绝佳来源,虽然我不认为你需要它......
he knows that is how it should be death, but he wants to make the ENTIRE div a link, which I am not sure how to do, unless you went with Javascript, at which point it would be
[html]
<div OnClick="document.location=''http://google.com''"><noscript><a href="http://google.com"></noscript>some Text<noscript></a></noscript></div>
<!--THus, you will get divs that are links, unless the client has no javascript, which will cause the text to be links instead.-->
<!--the same for your lists -->
<ul>
<li OnClick="document.location=''http://yahoo.com''"><noscript><a href="http://yahoo.com"></noscript>More Text<noscript></a></noscript></li>
</ul>
[/html]
Does that help? I cannot think of an XHTML strict way to do it otherwise...

Oh, and w3schools.com is an excellent source for HTML, CSS, and PHP (IMHO), although I don''t think you need it...


div不能成为一个链接。它是一个结构元素和块级别,并不是内容本身。 < a取代;仅内联,不适用于块级元素。
A div cannot be made into a link. It is a structural element, and block level, and is not content by itself. <a> is inline only and will not work on block level elements.


这篇关于使div成为一个链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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