简体   繁体   English

如何设置链接的背景图片?

[英]How to set background image for a link?

The code below is a link which has a class through which I want to add a background image. 下面的代码是一个链接,该链接具有一个我想通过其添加背景图像的类。 I am not able to display background image however same code sets background color correctly so what I am missing here? 我无法显示背景图像,但是相同的代码可以正确设置背景颜色,所以我在这里缺少什么? I don't want to use <img> tag inside link because I want to change background image on hover. 我不想在链接内使用<img>标签,因为我想在悬停时更改背景图片。

 .dropbtn{background: url(http://images.freeimages.com/images/previews/356/cubes-1425949.jpg) 50px 50px no-repeat;} 
 <a class="dropbtn">image</a> 

背景图片类 See Clearly i used class and in css,me use background-image.It is not necessary to do 1 thing from only one method.there are many options to do any anything 清楚地看到我使用了类,并且在css中,我使用了背景图像。不必只用一种方法做一件事。有很多选择可以做任何事情

You can try this way.Wrap the <a> with a div then style below this way.Hope this will help you. 您可以尝试使用这种方法。 <a>div然后在下面的style中包裹,希望这会有所帮助。

 .hello { width: 100%; background-image: url(http://images.freeimages.com/images/previews/356/cubes-1425949.jpg); height: 700px } 
 <div class="hello"><a class="dropbtn">image</a> </div> 

You are showing 50px 50px Is your link 50px heigh? 您正在显示50px 50px您的链接50px高吗? My guess is that you should start with 0 0 and see where the image is. 我的猜测是,您应该从0 0开始,然后查看图像在哪里。 Is there a lot of transparent or white space on the canvas so the actual image is not in view especially with the 50px right and top positions added also? 画布上是否有很多透明或白色的空间,所以实际的图像不可见,尤其是在添加了50px的右边和顶部位置的情况下?

Add height to your link and remove the image positioning by using left top. 使用左上角增加链接的高度并删除图像的位置。

you are using wrong class for css use below code 您正在使用错误的类为css使用以下代码

.dropbtn{background-image:url( http://images.freeimages.com/images/previews/356/cubes-1425949.jpg ) 50px 50px no-repeat; .dropbtn {background-image:url( http://images.freeimages.com/images/previews/356/cubes-1425949.jpg )50px 50px不重复;

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

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