How to use the <i> tag with icons?

I have an icon set and CSS code to attach icons to an element, but I can’t get the "i" tag to work with the icon set without filling it with content. Should I add custom code for the tag?

I saw Twitter Bootstrap use the "i" tag for icons. In addition, I tried the span tag, and this does not work either. It works when I use the tags "li" or "div", tho.

What am I missing? Thanks in advance!

It does n’t work

<i class="icon icon-accessibility"></i> 

This one works

 <i class="icon icon-accessibility">BLAH</i> 

example of my CSS

 .icon {background: url('/images/icons.png') no-repeat top left;} .icon-accessibility{ background-position: 0 0; width: 32px; height: 32px; } 
+4
source share
4 answers

The <i> used to indicate that the text inside should be in italics. In this context, it makes no sense to use it.

If you still want to save it and not use something like a div , the problem is that the <i> is an inline element and not a block element like a div . Add display: inline-block; into your CSS and it will work.

+8
source

Brthr, just add “display: inline-block” to your “.icon”, it may work

+2
source

Unlike semantics, you don’t see anything, because by default the element is <i/> inline . You probably want to add display: inline-block; into the .icon rule set to match how Bootstrap displays its icons.

If you need semantics, use <div/> or <span/> instead.

+1
source

You can simply use the img tag to display the icon. This is more important semantically, because in the end it’s embedded content, and the icon will be tangible.

0
source

Source: https://habr.com/ru/post/1489724/


All Articles