A new CSS image replacement technique (background display and text moving off screen) to say goodbye to 9999px

A new CSS image replacement technique (background display and text moving off screen) to say goodbye to 9999px
-9999 px image replacement technology has been popular for the best part of a decade. To replace a text element with an image, you can use the following code:

Copy code
The code is as follows:

<h1>This Text is Replaced</h1>
<style>
h1
{
background: url("myimage") 0 0 no-repeat;
text-indent: -9999px;
}
</style>

The element's background is displayed and its text is moved offscreen so that it doesn't get in the way. Simple and effective. It's often used to display graphic captions - this is rarely necessary now that we have webfonts, but you'll still find it useful when using it on the web.
Until now.
A new technology has been discovered:

Copy code
The code is as follows:

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

Code indents the text beyond the width of its container, but it does not wrap and overflow is hidden.
While this is a little longer and harder to remember, it can improve performance because the browser is no longer drawing a 9999px box behind the scenes. It will also prevent the weird left expanded outlines you'll see around links by using hidden text.

<<:  Specific use of Mysql prepare preprocessing

>>:  Some ways to solve the problem of Jenkins integrated docker plugin

Recommend

React hooks pros and cons

Table of contents Preface advantage: shortcoming:...

Detailed explanation of the practical application of centos7 esxi6.7 template

1. Create a centos7.6 system and optimize the sys...

Analysis of multi-threaded programming examples under Linux

1 Introduction Thread technology was proposed as ...

VUE+Canvas implements the game of God of Wealth receiving ingots

Welcome to the previous canvas game series: 《VUE ...

Use CSS to create 3D photo wall effect

Use CSS to create a 3D photo wall. The specific c...

How to set up Windows Server 2019 (with pictures and text)

1. Windows Server 2019 Installation Install Windo...

CSS3 simple cutting carousel picture implementation code

Implementation ideas First, create a parent conta...

Example code for implementing triangles and arrows through CSS borders

1. CSS Box Model The box includes: margin, border...

Detailed explanation of the solution to forget the password in MySQL 5.7

ENV: [root@centos7 ~]# uname -r 3.10.0-514.el7.x8...

MySQL 5.7 generated column usage example analysis

This article uses examples to illustrate the usag...

Brief analysis of the MySQL character set causing database recovery errors

Importing data with incorrect MySQL character set...

Detailed explanation of Vue components

<body> <div id="root"> <...

Detailed explanation of MySQL partition table

Preface: Partitioning is a table design pattern. ...