Skip to content

Commit adecc5d

Browse files
committed
New image replacement approach
This approach uses a pseudo-element to force the element's content downwards without covering the background of the element. The overflow is hidden. For IE 6/7, fallback to the cruder `text-indent` method. Known advantages: * Works in IE6+ (although better in IE8+). * Replaces any content in IE8+, including inner HTML. * Nothing new for people to learn. Works just like all "traditional" IR techniques (unlike NIR, which needs you to add the image using a pseudo-element's `content` and relies margins for sprite positioning). * Doesn't draw a large out-of-element box in modern browsers. You can even mix in something like `font: 10px/1 a` to reduce ce the size of the "off-screen" box, if you really need to. * Doesn't have any potential SEO problems from `font-size:0`. * Doesn't care about any minimum font-size that a browser might have. * Doesn't have any potential failed-IR problems from inherited styles, like text being positioned within the element's visible box (i.e., if you use other properties like `text-stroke`). Known issues: * Doesn't work when images are off or fail to load (same as every other IR technique apart from NIR). * If the IR'ed element has bottom-padding, then either it needs to be removed or the height of the pseudo-element needs to be bumped up (e.g., set to 200%). * Doesn't avoid the `inline-block` bug in IE 6/7 due to the text-indent fallback for those browsers. * Doesn't work on input elements (but they shouldn't be the subject of IR anyway). * There is the potential for some final-result differences between IE 6/7 and modern browsers, but this is already the case with other IR techniques. Fix gh-1149
1 parent fac03ef commit adecc5d

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Separate Normalize.css from the rest of the CSS (#1160).
88
* Improve `console.log` protection (#1107).
99
* Replace hot pink text selection color with a neutral color.
10-
* Change image replacement technique.
10+
* Change image replacement technique (#1149).
1111
* Code format and consistency changes (#1112).
1212
* Rename CSS file and rename JS files and subdirectories.
1313
* Update to jQuery 1.8 (#1161).

css/main.css

+11-4
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,18 @@ textarea {
130130
*/
131131

132132
.ir {
133-
border: 0;
134-
font: 0/0 a;
135-
text-shadow: none;
136-
color: transparent;
137133
background-color: transparent;
134+
border: 0;
135+
overflow: hidden;
136+
/* IE 6/7 fallback */
137+
*text-indent: -9999px;
138+
}
139+
140+
.ir:before {
141+
content: "";
142+
display: block;
143+
width: 0;
144+
height: 100%;
138145
}
139146

140147
/*

doc/css.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ You are free to modify or add to these base styles as your project requires.
4040

4141
#### `.ir`
4242

43-
Add the `.ir` class to any element you are applying image-replacement to. Be
44-
sure to include `background-image: url(pathtoimage.png);` for that specific
45-
element so that image replacement can occur.
43+
Add the `.ir` class to any element you are applying image-replacement to. When
44+
replacing an element's content with an image, make sure to also set a specific
45+
`background-image: url(pathtoimage.png);`, `width`, and `height` so that your
46+
replacement image appears.
4647

4748
#### `.hidden`
4849

0 commit comments

Comments
 (0)