简体   繁体   English

没有显示的背景css图象

[英]Background css image not showing

I have a link on my HTML page that I want like to display. 我的HTML页面上有一个我想要显示的链接。 The icon is not appearing and I'm not sure why. 图标没有出现,我不知道为什么。 The image icon is located in a sub folder within my project and it can be found (double checked). 图像图标位于我项目中的子文件夹中,可以找到它(双重检查)。 I'm using the brackets IDE. 我正在使用括号IDE。

Html file: Html文件:

  <div class="delivery"><a href="Delivery-Options.html">£2.99 Delivery >>More info</a></div>

Css file: Css文件:

.delivery {
           float:left; width:59%; padding-left:48px;
           background:#ccc; background-image: url(images/delivery.jpg) 8px center;
          }

background-image does not accept the shorthand you are using. background-image不接受您正在使用的简写。 Change to background instead. 改为改为background

As pointed out by @Gezzasa in the comment, using background shorthand will overwrite a previous background-color . 正如@Gezzasa在评论中指出的那样,使用background速记将覆盖以前的background-color Updated snippet shows both. 更新的代码段显示了两者。 Note that the colour should appear after the image. 请注意,颜色应出现图像之后。

 .delivery { float: left; width: 59%; padding-left: 48px; background: url(https://picsum.photos/200/300) #ccc; background-repeat: no-repeat; background-position: 8px center; } 
 <div class="delivery"><a href="Delivery-Options.html">£2.99 Delivery >>More info</a></div> 

You're using background position in your background-image param. 您在background-image参数中使用了背景位置。

Remove that and put it in to background-position 删除它并将其放入background-position

ex: background-position: 8px center; background-image: url(images/delivery.jpg); 例如: background-position: 8px center; background-image: url(images/delivery.jpg); background-position: 8px center; background-image: url(images/delivery.jpg);

This shows the image on left side as icon. 这会将左侧的图像显示为图标。 You can change the background-size. 您可以更改背景大小。

.delivery {
        width:59%; 
        padding-left:48px;
        background-size: 18px 18px;
        background-image:url(coffee.jpg) ;
        background-repeat: no-repeat;
    }

html HTML

<div class="delivery"><a href="Delivery-Options.html">£2.99 Delivery >>More info</a></div>

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

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