简体   繁体   English

我如何使整个DIV可点击

[英]how do I make entire DIV clickable

I am creating some pagination. 我正在创建一些分页。 Each page number contained within it's own DIV. 自己的DIV中包含的每个页码。

Currently the page number is clickable. 当前页码是可单击的。 Is it possible to make the entire DIV within which the number sits to be clickable? 是否可以使数字所在的整个DIV都可点击?

Here's my CSS 这是我的CSS

#article_pagination{
float: left;
padding: 0px 4px 0px 4px;
margin: 0px 3px 0px 0px;
border: 1px solid #999999;
display:block;
cursor:pointer;
}

#article_pagination:hover{
border: 1px solid #333333;
background-color: #99C0F3;
}

#article_pagination a:hover{
color:#FFFFFF;
}

Here' my php/HTML for one of the pagination DIV's 这是我的分页DIV的php / HTML

'<div id="article_pagination"><a href="'.$base_url.'/article_view.php?channel='.$channel_view.'&page='.$Next_Page.'">Next >></a></div>'

The simple way is to put the div inside the a element: 简单的方法是将div放在a元素内:

'<a href="'.$base_url.'/article_view.php?channel='.$channel_view.'&page='.$Next_Page.'"><div id="article_pagination">Next &gt;&gt;</div></a>'

Note that I have also changed >> to &gt;&gt; 请注意,我还将>>更改为&gt;&gt; to make your code valid. 使您的代码有效。

You may think, "Hang on, a elements can't contain div elements." 您可能会想,“等等, a元素不能包含div元素。” They can, under certain conditions. 他们可以在某些条件下。 Basically, as long as the element inside the a element doesn't contain any interactive content (links, buttons, etc.), it works fine. 基本上,只要a元素内的元素不包含任何交互式内容(链接,按钮等),它就可以正常工作。

a is defined as what HTML5 calls a "transparent element" , so long as no interactive content is inside it. a定义为HTML5所谓的“透明元素” ,只要其中没有交互式内容即可 This means: 这意味着:

the elements required in the part of the content model that is "transparent" are the same elements as required in the part of the content model of the parent of the transparent element in which the transparent element finds itself (source) 内容模型的“透明”部分所需的元素与透明元素的自身(源)所在的透明元素的父级的内容模型部分所需的元素相同

you could add #article_pagination a{ display: block; } 您可以添加#article_pagination a{ display: block; } #article_pagination a{ display: block; } should work. #article_pagination a{ display: block; }应该可以。 Greetings, Kevin 凯文,问候

Put it inside an <a> tag. 将其放在<a>标记内。 Anything in such a tag is clickable and can have a link attached. 此类标签中的任何内容都是可点击的,并且可以附加链接。

A better way is to use a little javascript. 更好的方法是使用一些JavaScript。 You can find some copypaste code :) 您可以找到一些复制粘贴代码:)

Place onclick="window.open('http://yourpage.com','_blank');" 放置onclick="window.open('http://yourpage.com','_blank');" after the div. 在div之后 Remove ,'_blank' if you want it to open in the parent. 如果要在父级中打开,'_blank'请将其删除。 Also, stylize it with style="cursor:pointer;cursor:hand;" 另外,使用style="cursor:pointer;cursor:hand;"将其style="cursor:pointer;cursor:hand;" if you want the mouse to change into a pointer. 如果您希望鼠标变为指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM