简体   繁体   中英

How to set full div clickable?

I have this code for div

      <div align="center" id="1_2" class="class_div" onclick="DoAction(1)" style="float: left;  height: 60px; width: 250px; margin: 10px"><h1>&nbsp;&nbsp;&nbsp;&nbsp;Class :Class-1</h1>&nbsp;&nbsp;&nbsp;&nbsp; Class Teacher :Manan</div>

When cursor moves on the div it shows text-cursor . I want that div to be clickable and the click-cursor should come there.How could this be done.Please help??

添加cursor: pointer CSS中class_div类的样式规则的cursor: pointer

您需要像这样更改样式-

<div style="cursor:pointer" ....></div>.

To make it fully clickable, you need to add cursor:pointer; display:inline-table; text-align:center; properties respectively to the div.

Without display:inline-table , the whole of the div will not be clickable and will create a gap between two lines of text.

Here is the WORKING SOLUTION

The HTML:

<div align="center" id="1_2" class="class_div" onclick="DoAction(1)" style="float: left;  height: 60px; width: 250px; margin: 10px"><h1>&nbsp;&nbsp;&nbsp;&nbsp;Class :Class-1</h1>&nbsp;&nbsp;&nbsp;&nbsp; Class Teacher :Manan</div>

The CSS:

div{cursor:pointer; display:inline-table; text-align:center;}

Hope the helps.

PS: I have illustrated with div as the selector, but alternatively, you can apply the styles to the class also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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