简体   繁体   English

背景图像不适用于图像

[英]Background Image Not Working For Image

I would like to make a background image for one of my images.我想为我的其中一张图片制作背景图片。 The background image is transparent and can be seen at http://webmaster.tsaprotectandserve.com/new_design/images/view_site.png (and I'm pretty sure I have the correct url relative to the document in the code) and the idea is just that one you hover over the images, you can see the view site background image.背景图片是透明的,可以在http://webmaster.tsaprotectandserve.com/new_design/images/view_site.png看到(我很确定我有正确的相对于代码中的文档的网址)和想法就是将鼠标悬停在图像上的那个,您可以看到查看站点的背景图像。 Before I move the background image to a hover class and center it on the image, I wanted to make sure it works properly just as a background image but it isn't showing up.在我将背景图像移动到悬停类并将其置于图像中心之前,我想确保它可以像背景图像一样正常工作,但没有显示出来。

My code is我的代码是

<img style="float: left; margin-bottom: 20px; background-image: url(images/view_site.png)" src="images/white_house_website.PNG" width="490" height="231" alt="White House Website">

My website with the issue is here and the image with the problem can be found if you scroll all the way to the bottom.我有问题的网站在这里,如果您一直滚动到底部,可以找到有问题的图像。 It is the white house image.这是白宫的形象。

It is actually working.它实际上正在工作。 the image is covering up the "Veiw Site" image.该图像掩盖了“Veiw Site”图像。 Because its the background.因为是背景。

i removed the top image via google chrome...我通过谷歌浏览器删除了顶部图片...

在此处输入图片说明

What you want to do is set the "View Site" image as separate div as child of a div around the image.您想要做的是将“查看站点”图像设置为单独的 div 作为图像周围 div 的子级。 and set it to appear on hover.并将其设置为出现在悬停时。 something like http://jsfiddle.net/hWcMK/类似于http://jsfiddle.net/hWcMK/

CSS: CSS:

.imagebox:hover .viewsite{
    display:block;

}

.viewsite{
    width:125px;
    height:125px;
    background-image: url("http://webmaster.tsaprotectandserve.com/new_design/images/view_site.png");
    margin-top:-150px;
    position:absolute;
    display:none;


}

and the HTML:和 HTML:

<div class="imagebox">
<img src="http://webmaster.tsaprotectandserve.com/new_design/images/abc_website.PNG" width="80%"/ >
    <div class="viewsite"></div>    
</div>    

u can view my working solution in jsfiddle: http://jsfiddle.net/avi_sagi/Ea78j/3/你可以在 jsfiddle 中查看我的工作解决方案: http : //jsfiddle.net/avi_sagi/Ea78j/3/

CSS Rules CSS 规则

.thumb{
    width:490px;
    height:231px;
    background:url('images/view_site.png') no-repeat center;
    background-size:100%;    
}
.thumb:hover .view_site{
    width:490px;
    height:231px;
    background:url('images/white_house_website.PNG') no-repeat center;
    background-size:128px 128px;
}

if your css is in external stylesheets remember to change the url of the background image or mention absolute url to be safe.如果您的 css 在外部样式表中,请记住更改背景图片的 url 或提及绝对 url 以确保安全。

HTML HTML

<div class="thumb">
    <div class="view_site"></div>
</div>

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

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