img标签没有src属性,但具有类属性给出了一个随机显示 [英] img tag without src attribute but with class attribute gives a random display

查看:248
本文介绍了img标签没有src属性,但具有类属性给出了一个随机显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到一个问题在stackoverflow用户想给一个图标在html,但不使用

I just come across one question in stackoverflow where user want to give an icon in html, but not using

<img src="smiley.gif" alt="Smiley face" width="42" height="42">

,但使用类

<img class="iconClass">

而css类是

.iconClass{
              background:url('smiley.gif')!important;
          }

我试过这个,但这对我有用,但很奇怪的是,图像被重复直到指定的宽度和高度。为什么会发生这种情况,以及如何解决?

I tried this, but this works for me, but wierd thing is that, the image is getting repeated till the width and height specified. Why this is happening, and how to solve it?

推荐答案

背景重复默认设置为重复。您应该设置:

background repeat is by default set to repeat. You should set:

.iconClass{
   background-repeat: no-repeat;
}

或:

.iconClass{
              background:url('smiley.gif')!important no-repeat;
          }

这篇关于img标签没有src属性,但具有类属性给出了一个随机显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆