使图像不可选择
我正在 Dreamweaver CS5 中制作一个网站。我从 Photoshop 导出图像并将它们插入到表格中。当我查看该网站时,所有图像都是可选的(您可以将它们拖到桌面上)。我该如何改变这个???我想用 onclick 方法来做到这一点,另外我将如何实现这一点?
<td><img src="images/people_03.png" name="one" width="1000" height="156" id="one" ONCLICK="closeimages();"/></td>
I am making a website in dreamweaver CS5. I exported the images from photoshop an inserted them into a table. When I view the site all the images are selectable(you are able to drag them to your desktop). How do I change this??? I want to do it with an onclick method in addition how would I achieve this?
<td><img src="images/people_03.png" name="one" width="1000" height="156" id="one" ONCLICK="closeimages();"/></td>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在解决同样的问题时偶然发现了这个问题,但接受的答案对我来说并不是一个可能的解决方案。
我特别使用了此处找到的信息将以下样式添加到我的正文中的 css 中(这对我在 Firefox、Chrome 和Opera,我无法测试 IE)
不可选择的 html 标签似乎也有帮助,但它显然仅受 IE 和 Opera 支持:
以及 javascript 解决方案,据说可以在 IE 和 webkit 浏览器上工作:
注意。正如 Albert Renshaw 在评论中指出的那样,此方法在 Chrome 中不再有效 > 50.
I stumbled upon this question while struggling with the same problem but the accepted answer was not a possible solution for me.
I used the info found here , in particular adding the following styles to my body, inside the css (this worked for me in Firefox, Chrome and Opera, I cannot test for IE)
The unselectable html tag seems also helpful, but it's apparently supported only by IE and Opera:
as well as the javascript solution, that is said to work on IE and webkit browsers:
Note. As Albert Renshaw pointed in the comment this method no longer works in Chrome > 50.
我会在 CSS 中使用
pointer-events: none;
I would use
pointer-events: none;
in my CSS可靠的纯 CSS 解决方案
将以下 2 个 CSS 属性应用到您的
元素将完全实现您所描述的效果:
这在所有现代浏览器中都能可靠地工作。
示例:(尝试用光标选择并拖动图像!:D)
唯一的缺点是
pointer-events: none
会导致:hover
、:active
和其他与指针相关的 CSS 伪类停止工作。为了解决这个问题,您应该使用
或其他东西作为
的包装器,然后应用
:hover、
:active
包装器上的伪类,而不是本身。
例子:
如果您也不想或无法更改 HTML 标记,那么您将不得不求助于一些 JavaScript:
Reliable Pure CSS Solution
Applying the following 2 CSS properties to your
<img>
element(s) will achieve exactly what you described:This works reliably across all modern browsers.
Example: (Try to select and drag the image with your cursor! :D)
The only downside is that
pointer-events: none
causes your:hover
,:active
and other pointer-related CSS pseudo-classes to stop working.In order to solve this, you should use a
<div>
or something as a wrapper for your<img>
and then apply your:hover
,:active
pseudo-classes on that wrapper as opposed the<img>
itself.Example:
If you also don't want to or can't change your HTML markup, then you're gonna have to resort to some JavaScript:
我认为最简单的方法是将图像作为每个单元格的 css 背景图像
Easiest way I think would be to make the images as css background images to each cell