简体   繁体   English

内容CSS以及与IE的兼容性

[英]Content CSS and compatibility with IE

I have inserted an icon with an image inside. 我插入了一个带有图像的图标。

In chrome I see the icon 在Chrome中,我看到了图标

在此处输入图片说明

But in IE icon disappear. 但是在IE图标中消失了。

Here's my CSS 这是我的CSS

<div class="infoIcon"></div>

.infoIcon {
    content: url('/assets/img/info-sign.png');
    background-color: #919191;
    width:15px;
    border-radius: 8px;
    margin-left:10px;
    display: inline;
    vertical-align: sub
}

you can achieve this using HTML entity. 您可以使用HTML实体来实现。

 .infoIcon { font-size: 40px; } 
 <div class="infoIcon">&#9432;</div> 

In css "content" applies to ::before & ::after pseudo selectors. 在CSS中,“内容”适用于:: before和:: after伪选择器。

As to why it Chrome is showing the image, Chrome tends to be flexible with css syntax most of the times. 关于Chrome为什么显示图像的原因,Chrome通常在大多数情况下都倾向于使用CSS语法。 IE and FireFox are not showing the image because it is not the right syntax. IE和FireFox没有显示图像,因为它的语法不正确。

Edit: Example If you want to keep 'content' You'll have to move your content to .:before 编辑:示例如果要保留“内容”,则必须将内容移动到。:before

.icon:before{
content: url('src');
}

However you'll need to scale your image to the right size. 但是,您需要将图像缩放到合适的尺寸。 (Icon libraries use fonts where they can change the font-size easily) (图标库使用字体,可以轻松更改字体大小)

Second option is continue as you are now but switch to background-image 第二种选择是像现在一样继续,但是切换到背景图像

.info{
background-image:url('icon.svg.png');
background-size: 100% 100%;
width:40px;
height: 40px;
}

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

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