Html <DIV> 内链接 (<a href="">) 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3092610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
<DIV> inside link (<a href="">) tag
提问by Kali Charan Rajput
I want to make a div click-able and but inside this <div>
i have another <div>
which also should be click-able or linked.
我想让一个 div 可点击,但在这个里面<div>
我有另一个<div>
也应该是可点击或链接的。
HTML
HTML
<a href="#">
<div class="box">
<div class="plus"><img src="aaa.jpg"/></div>
</div>
</a>
CSS
CSS
.box{
float:left;
width:100px;
height:100px;
}
.plus{
float:left;
width:30px;
height:30px;
}
Can i make both <div>
s to link and for different links?
我可以同时制作<div>
s 链接和不同的链接吗?
and Is this proper way use div inside a href
?
并且这是正确的方法在里面使用 diva href
吗?
回答by Starx
No,the link assigned to the containing <a>
will be assigned to every elements inside it.
不,分配给包含的链接<a>
将分配给其中的每个元素。
And, this is not the proper way. You can make a <a>
behave like a <div>
.
而且,这不是正确的方法。您可以使<a>
行为像<div>
.
An Example [Demo]
一个例子[演示]
CSS
CSS
a.divlink {
display:block;
width:500px;
height:500px;
float:left;
}
HTML
HTML
<div>
<a class="divlink" href="yourlink.html">
The text or elements inside the elements
</a>
<a class="divlink" href="yourlink2.html">
Another text or element
</a>
</div>
回答by Adam Hollow
As of HTML5 it is allowed to wrap links around a div.
从 HTML5 开始,允许在 div 周围包装链接。
回答by whostolemyhat
This is a classic case of divitis- you don't need a div to be clickable, just give the <a>
tag a class. Then edit the CSS of the class to display:block, and define a height and width like a lot of other answers have mentioned.
这是divitis 的一个经典案例——你不需要一个 div 就可以点击,只需给<a>
标签一个类。然后将类的 CSS 编辑为 display:block,并像许多其他答案提到的那样定义高度和宽度。
The <a>
tag works perfectly well on its own, so you don't need an extra level of mark-up on the page.
该<a>
标签很完善自身,所以你不需要加价的页面上的额外级别。
回答by Wind Chimez
Nesting of 'a' will not be possible. However if you badly want to keep the structure and still make it work like the way you want, then override the anchor tag click in javascript /jquery .
'a' 的嵌套是不可能的。但是,如果您非常想保留结构并仍然使其按照您想要的方式工作,那么请覆盖 javascript /jquery 中的锚标记单击。
so you can have 2 event listeners for the two and control them accordingly.
因此,您可以为两者设置 2 个事件侦听器并相应地控制它们。
回答by Julius A
I think you should do it the other way round.
Define your Div
s and have your a href
within each Div
, pointing to different links
我认为你应该反过来做。定义您的Div
s 并a href
在每个中放置您的s Div
,指向不同的链接
回答by Fidi
I would just format two different a-tags with a { display: block; height: 15px; width: 40px; }
. This way you don't even need the div-tags...
我只会用a { display: block; height: 15px; width: 40px; }
. 这样你甚至不需要 div 标签......