如何使DIV部分可点击? [英] How to make a DIV section clickable?

查看:74
本文介绍了如何使DIV部分可点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个网页,其中的链接都包含在自己的标签中。我也用CSS(边框,背景颜色,填充)制作了所有按钮样式。如何启用单击整个DIV以激活链接?

I have written a web page in which links are all contained within their own tags. I've also made them all button styles with CSS (border, background color, padding). How do I enable the whole DIV to be clicked to activate the link?

推荐答案

实现此类效果的最佳方法(使链接像按钮一样)是将css应用于链接本身。这是一个基本的例子:

The best way to do this kind of effect (making links act like buttons) is to apply css to the links themselves. Here's a basic example:

a.mylink {
display: block;
padding: 10px;
width: 200px;
background-color: #000;
color: #fff;
}

测试一下 - 整个按钮都是可点击的。它尊重浏览器的正常链接操作,如右键单击,状态URL信息等。

Test it out - the whole of the button is clickable. And it respects the browser's normal link actions like right-clicking, status url information, etc.

这篇关于如何使DIV部分可点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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