bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Use New Image Replacement Hack

Open TechRemarker opened this issue 14 years ago • 14 comments

Rather than text-indent: -99999px which actually forces the browser to draw that canvas use the performance savings variation of text-indent: 100% for the caret class in dropdown.less. See Zeldman.com's post today for details:

http://www.zeldman.com/2012/03/01/replacing-the-9999px-hack-new-image-replacement/

.hide-text {
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}

TechRemarker avatar Mar 01 '12 21:03 TechRemarker

I don't think we need to even use the text-indent hack on the carets, but I'll add this as a mixin and check that out.

mdo avatar Mar 03 '12 22:03 mdo

Ended up removing the text-indent in the carets so we don't need this anymore, but I'll add it to the mixins for those who might need it.

mdo avatar Mar 12 '12 04:03 mdo

I know this was already added to v2.0.2 - but HTML5's version seems to work a bit better IMHO https://github.com/h5bp/html5-boilerplate/commit/aa0396eae757c9e03dda4e463fb0d4db5a5f82d7 Maybe something to look at for the future. Thanks!

zslabs avatar Mar 13 '12 02:03 zslabs

Ah, I was just about to mention this and @zslabs has beaten me to it. I think @scottkellum (the originator of this new IR technique) is also in agreement with the modified IR technique that @necolas introduced to @h5bp.

nimbupani avatar Mar 13 '12 19:03 nimbupani

@nimbupani Actually I am still on the fence for using it myself as a heavy user of ems. Bootstrap is pixel/percent based so the font: 0/0 a method is better in those situations.

scottkellum avatar Mar 13 '12 19:03 scottkellum

Just an FYI: Compass users revolted when I changed the default hide-text to the font: 0/0 approach because of the issues with em-based margins. But I really like the font: 0/0 approach because you can use it to hide inline content for display but it will still be consumed by screen readers. So I am using text-indent: 110% for the default hide-text mixin in compass (110% seems to keep inline-block elements from breaking). And I added a squish-text mixin for when the font: 0/0 approach is needed. http://compass-style.org/reference/compass/typography/text/replacement/

chriseppstein avatar Mar 14 '12 16:03 chriseppstein

@chriseppstein ++ thanks Chris.

scottkellum avatar Mar 14 '12 16:03 scottkellum

I am using text-indent: 110% for the default hide-text mixin in compass (110% seems to keep inline-block elements from breaking)

Nope. That doesn't prevent it seriously breaking for inline-block elements in IE6/7.

Another problem to be aware of with the positive text-indent method is that the text is revealed in several screenreaders when focus is placed on the IR-ed element - https://github.com/h5bp/html5-boilerplate/commit/aa0396eae757c9e03dda4e463fb0d4db5a5f82d7#commitcomment-1052728

IMO, the negative text-indent is the way to go if you want to preserve em use. It doesn't have the most significant drawbacks of the positive text-indent method, and only seems to be problematic in 1st gen ipads when the element is also being animated.

The NIR method is the way to go if you're IE8+ - appears to have none of the drawbacks and even works with images off.

necolas avatar Mar 14 '12 16:03 necolas

Is inline-block really something we care about on IE<=7 as inline-block is already broken on those browsers?

scottkellum avatar Mar 14 '12 20:03 scottkellum

inline-block is already broken on those browsers

*display:inline; *zoom:1 - IE6/7 inline-block hack.

necolas avatar Mar 14 '12 21:03 necolas

I do the same except put the display inline and zoom 1 loaded via a class with conditional statements (the HTML5 Boilerplate way) to keep the CSS valid.

TechRemarker avatar Mar 14 '12 21:03 TechRemarker

Negative text-indent would also fix this background positioning problem in IE7: http://jsfiddle.net/salantsa/3DYd2/

antsa avatar Mar 26 '12 11:03 antsa

@antsa I noticed this in one of my text cases too - http://jsfiddle.net/necolas/drHaR/2/ - IMO the positive text-indent method is too buggy.

necolas avatar Mar 26 '12 12:03 necolas

So. It might seem ugly, but you can also just include a tiny 1px x 1px image (always the same image so it isn't downloaded multiple times... and put the alt text on that image. It doesn't cause display bugs or perf issues.

I'm also not convinced that the -9999px method really causes perf issues. I was unable to measure any difference between the two.

stubbornella avatar Aug 22 '12 18:08 stubbornella