rplus.github.io
rplus.github.io copied to clipboard
[POST] Styling Broken Images with Pseudo-element
Styling Broken Images by Ire Aderinokun 2016-03-08 http://bitsofco.de/styling-broken-images/
fix broken <img> with pseudo-element
原理是 是 replaced element,原本內容物是外部資源在控制的
但在圖檔壞掉或未載入時,pseudo-element 就能顯示出來了
這篇文主要的技巧就是這一點 利用將 pseudo-element 套用不同的樣式來提醒瀏覽者:「圖片未載入唷」
雖然在 Safari & iOS 環境下無用 但在 desktop & android 還算是個不錯的應用技巧
而基本上若採用 alt 去加強的話
在支援與不支援這技巧的瀏覽器上都能起到最基本的提示效果哩~
後記:
https://jsbin.com/ronexu/edit?html,css,output
做了個實驗來試試 img 的 pseudo-element 的生效時機點
看來是 load fail 才會出現
在壞檔時才會載 pseudo-element 用到的背景圖
frontend ##tricks
fb: https://www.facebook.com/rplus.tw/posts/1073740006027115 re-tweet: https://twitter.com/RplusTW/status/707743776853233664 source: https://twitter.com/ireaderinokun/status/707501875919200256