display:none / visibility:hidden (螢幕閱讀器會忽略)h1 {
width: 300px; height: 50px;
background: url(title.png) no-repeat;
text-indent: -9999px; /* 或 -999em */
overflow: hidden; /* 防長文字撐破 */
}
<h1>Buy Widgets</h1>
缺點:極大負值可能觸發瀏覽器渲染 Bug、RTL 語系反向、效能微弱影響。
text-indent: 100% + white-space: nowrap.ir {
display: inline-block; /* 或 block */
width: 300px; height: 50px;
background: url(title.png) no-repeat center / contain;
text-indent: 100%; /* 推出可視區 */
white-space: nowrap; /* 防換行拉回 */
overflow: hidden; /* 隱藏溢出 */
}
inline-block 讓寬高生效且不換行;區塊層用 block。.ir-zero {
width: 300px; height: 50px;
background: url(title.png) no-repeat center / contain;
font: 0/0 a; /* 字體大小 0、行高 0、字體族系 fallback */
text-shadow: none; /* 確保無陰影殘留 */
color: transparent; /* 文字透明 */
overflow: hidden;
}
優點:不需 text-indent、無焦點外框偏移問題。缺點:部分舊瀏覽器 font:0/0 a 解析異常。
<h1 class="ir" aria-label="Buy Widgets">Buy Widgets</h1>
螢幕閱讀器直接讀取 aria-label,即使 CSS 失效也能獲得內容。
若僅為特殊字體,**直接載入 Web Font** 最佳:
@font-face {
font-family: 'MyBrand';
src: url('mybrand.woff2') format('woff2'),
url('mybrand.woff') format('woff');
}
h1 { font-family: 'MyBrand', sans-serif; }
font-display:swap 避免 FOIT。text-indent:100% 方案。overflow:hidden。