我已经在网上阅读了很多东西,但我还没有找到让它发挥作用的方法..
我想要的:
我有一个正文背景图片,我被要求将它作为广告链接。问题是无论我尝试什么都会使整个页面成为一个链接,而我只希望网页的背景充当关联。是否有可能,通过 html 和 css?或者甚至使用 javascript?接受任何解决方案...我被卡住了...提前致谢!
最佳答案
你不能让背景图片成为链接。您可以使用 JS 捕获正文上的所有点击,但不能捕获其子项之一
// This is not cross browser, that would be a separate question
document.body.onclick = function(e) {
if (e.target === document.body) {
window.location = "link.html"
}
}
您可以将 jQuery 用于跨浏览器版本
$('body').click(function(e){
if (e.target === this) {
window.location = "link.html"
}
});
如果你想给背景光标的外观,你可以应用下面的CSS
body {
background-image: url(http://www.blutest.com/sites/default/files/butterfly2_large_0.jpg);
cursor: pointer;
}
body, html {
width: 100%;
height: 100%;
}
body * {
cursor: default;
}
查看实际效果 here
关于javascript - 使正文背景图像充当链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13349677/