如何使背景图像可点击(javascript或css)
请看看这个 fiddle
如何使背景图片可点击?当点击“参加调查”时,将进入一个新页面。
<div style="height:300px;width:300px;border-style:solid;border-width:5px;background-image:url('http://cdn.survey.io/embed/1.0/right_top_blue.png'); background-repeat:no-repeat;background-position:right top;">
By default, the background-image property repeats an image both horizontally and vertically.
</div>
Javascript 或 CSS 都是首选。
编辑:我不想使用图像浮动到右角。
Please take a look this fiddle
How to make the background image clickable? When click "Take the survey" will go to a new page.
<div style="height:300px;width:300px;border-style:solid;border-width:5px;background-image:url('http://cdn.survey.io/embed/1.0/right_top_blue.png'); background-repeat:no-repeat;background-position:right top;">
By default, the background-image property repeats an image both horizontally and vertically.
</div>
Javascript or CSS are all preferred.
Edit: I don't want to use image float to right corner.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你不应该。
如果用户关闭了样式或者正在使用屏幕阅读器怎么办?他们也应该能够参加调查。
演示
You shouldn't.
What if a user has styles turned off, or is using a screen reader? They should be able to take the survey as well.
Demo
这是一个使用相对位置 + 绝对位置
http://jsfiddle.net/RZWCS/
的简单示例,您也可以考虑绝对定位链接并使用该图像作为链接背景(链接的文本可以与图像上显示的文本相同,并使用负文本缩进或类似技术移到外部)
that's a simple example using position relative + absolute
http://jsfiddle.net/RZWCS/
you could also think to absolute positioning the link and use that image as link background (the text of the link could be the same appearing on the image and moved outside with negative text-indent or similar techniques)
请在此处查看更多信息:http:// bluedogwebservices.com/css-trick-turning-a-background-image-into-a-clickable-link/
另外,您可以使 div 相对,然后只需将图像用锚点包裹并将其绝对放置在顶部右角。
编辑
HTML
CSS:
Check here for more info: http://bluedogwebservices.com/css-trick-turning-a-background-image-into-a-clickable-link/
Also, you could make the div relative, then just put image wrapped with anchor and position it absolutely in top right corner.
Edit
Html
CSS:
我在这里可能是错的,但我不认为 CSS 背景可以绑定事件。我个人会用透明的 div 覆盖它,或者使用真实的图像来访问 DOM 元素的事件。
如果有人有办法做到这一点,我会很感兴趣:)
I could be wrong here, but I don't think that CSS backgrounds can have events bound to them. I would personally cover it with a transparent div, or use a real image to tap into the events of the DOM element.
I would be interested if someone had a way to do this :)
直接把div变成
元素就可以了吗?
Just turn the div into an
<a>
element?