简体   繁体   English

链接图像但显示另一个?

[英]Link an image but display another?

I'm trying to display an image on a website that has different color based on the website Color Scheme... I need to link an alternate image instead of this image in both html and browser>right-click, so that although this alternate-colored image is displayed user gets access to only the standard alternate image. 我正在尝试在基于网站配色方案的具有不同颜色的网站上显示图像...我需要在HTML和浏览器中都链接一个替代图像而不是该图像>右键单击,以便尽管该替代图像显示彩色图像,用户只能访问标准备用图像。

For example, the color scheme of the website is : dark grey. 例如,网站的配色方案是:深灰色。 So image image has to be in : white. 因此,图像图像必须为:白色。 But the standard color of the image is: dark blue. 但是图像的标准颜色是:深蓝色。 So I had to change the image color to : light blue. 因此,我不得不将图像颜色更改为:浅蓝色。 So, instead of showing the standard colored image, I'm showing an image that's been altered according to the new dark color scheme. 因此,不是显示标准的彩色图像,而是显示根据新的深色方案进行了更改的图像。

Although I cannot alter the stylesheet, I need to add some css to the html page's "style" tags to be able to display this new image, and link the user to the standard image. 尽管我无法更改样式表,但是我需要在html页面的“样式”标签中添加一些CSS,以便能够显示此新图像,并将用户链接到标准图像。

My html for the div is: 我的div的html是:

<div class="picture">
    <div class="picture-div">
        <a class="picture-link" href="image_info.html">
            <img class="picture-img" src="img.png">
            <span class="picture-title">
                <span class="picture-title-div">Title for the Image</span>
            </span>
        </a>
    </div>
</div>

The image is placed under a.picture-link , with class="picture-img" . 图像放在a.picture-link class="picture-img" a.picture-link下。 CSS as per Chrome's Inspect Element is: 根据Chrome的Inspect元素,CSS为:

elements * {
margin: 0;
padding: 0;
border: 0;
outline: 0;
vertical-align: baseline;
background: 0 0;
}

.picture {
clear: both;
float: left;
height: 100%;
position: relative;
z-index: 1;
}

.picture-div {
font-size: 0;
}

.picture-link {
display: block;
height: 100%;
overflow: visible;
color: #666;
}

.picture-img {
display: block;
max-width: 100%;
}

img {
border: 0;
-ms-interpolation-mode: bicubic;
max-width: 100%;
height: auto;
}

.picture-title {
line-height: inherit;
}

.picture-title {
display: none;
font-size: 30px;
line-height: 30px;
white-space: normal;
}

I cannot alter the main stylesheet, cause I've minified it. 我无法更改主样式表,因为我已将其缩小。 Although, I'm adding required alterations in a separate stylesheet, so, if the solution is via CSS, I can only add the solution to my separate stylesheet, not to the main stylesheet. 虽然,我在单独的样式表中添加了所需的更改,但是,如果解决方案是通过CSS进行的,则只能将解决方案添加到单独的样式表中,而不能添加到主样式表中。

My problem, as discussed above is that I need to display an image, while restricting user to an alternate image only. 如上所述,我的问题是我需要显示图像,同时仅将用户限制为替代图像。 So, if an image is downloaded/linked, right-clicked, or anything that could duplicate the image elsewhere, it must be an alternate image and not the image displayed. 因此,如果下载/链接图像,单击鼠标右键或其他可以在其他位置复制该图像的图像,则该图像必须是备用图像,而不是显示的图像。

I was thinking of add a z-index to both the images, while keeping the image with positive z-index to opacity:0; 我当时想在两个图像上都添加一个z-index,同时保持z-index为正的图像的opacity:0; . That way if the image is accessed, only the invisible standard image will be accessed, preventing link to the alternate image. 这样,如果访问该图像,将仅访问不可见的标准图像,从而防止链接到备用图像。

I tried the following options, but these methods didn't help. 我尝试了以下选项,但是这些方法没有帮助。

a.picture-link { position: absolute }

Image vanishes from the view, and none of the image is visible. 图像从视图中消失,并且没有图像可见。

Also, tried this method : 另外,尝试此方法

.newclass {
    background:url(2.jpg) no-repeat;
    display:inline-block
}
.newclass img {
    position:relative;
    z-index:-1
}

I'm trying to look for solutions based on either jQuery , CSS , javascript . 我正在尝试寻找基于jQueryCSSjavascript的解决方案。 Although, my preference is CSS, cause css is supported by most browsers. 虽然,我的首选是CSS,但大多数浏览器都支持css。

Please could someone provide help? 请有人可以提供帮助吗? Thanks! 谢谢!

Working fiddle using CSS position & opacity: 使用CSS位置和不透明度的工作方式:

.image{position:relative}
.png-over{position:absolute; top:0; left:0;

opacity: 0;
    filter: alpha(opacity=0); /* For IE8 and earlier */
}

http://jsfiddle.net/jNpaH/67/ http://jsfiddle.net/jNpaH/67/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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