CSS example code for implementing sliding doors

CSS example code for implementing sliding doors

The so-called sliding door technology means that the box background can automatically stretch to accommodate texts of different lengths. That is, when the text increases, the background will also appear longer.

Most of them are used in navigation bars, such as WeChat navigation bar:

The specific implementation method is as follows:

1. First, each piece of text content is composed of a tag and span tag

<a href="#">
        <span></span>
    </a>

2. The a tag only specifies the height but not the width.

3. After setting the background image in the a tag, specify a padding-left value, the same size as the left semicircle (this ensures that the left background remains unchanged and the middle background can be stretched).

4. The span tag also specifies the background image, without specifying the width, and specifies the padding-right value to display the right half of the image (this is if the image position is set to the right)

The specific code is as follows:

a {
            color: white;
            line-height: 33px;
            margin: 100px;
            display: inline-block;
            text-decoration: none;
            /* a cannot give width*/
            /* */
            height: 33px;
            background: url(Images/vx.png) no-repeat;
            padding-left: 15px;
        }
        
        a span {
            display: inline-block;
            height: 33px;
            background: url(Images/vx.png) no-repeat right;
            padding-right: 15px;
        }

The background of span should be specified as right

 <a href="#">
        <span>一</span>
    </a>
    <a href="#">
        <span>One sentence</span>
    </a>
    <a href="#">
        <span>One sentence</span>
    </a>
    <a href="#">
        <span>A long sentence</span>
    </a>
    <a href="#">
        <span>A super super super super super long sentence</span>
    </a>

The results are shown as

It can be found that as the length of the text in the span tag changes, the background image will stretch.

Summarize

The above is the example code of how to implement sliding doors with CSS that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  Detailed explanation of how to use Teleport, a built-in component of Vue3

>>:  Simple operation of installing vi command in docker container

Recommend

MySQL 5.6.33 installation and configuration tutorial under Linux

This tutorial shares the installation and configu...

mysql5.7.20 installation and configuration method graphic tutorial (mac)

MySQL 5.7.20 installation and configuration metho...

How to build and deploy Node project with Docker

Table of contents What is Docker Client-side Dock...

MySQL kill command usage guide

KILL [CONNECTION | QUERY] processlist_id In MySQL...

How to implement draggable components in Vue

This article shares with you how to implement dra...

Teach you a trick to achieve text comparison in Linux

Preface In the process of writing code, we will i...

How to write a MySQL backup script

Preface: The importance of database backup is sel...

Detailed steps to change the default password when installing MySQL in Ubuntu

Step 1: Enter the directory: cd /etc/mysql, view ...

MariaDB under Linux starts with the root user (recommended)

Recently, due to the need to test security produc...

Solutions to Mysql index performance optimization problems

The optimization created by MySQL is to add index...

Detailed steps to use Arthas in a Docker container

What can Arthas do for you? Arthas is Alibaba'...

Some details about semicolons in JavaScript

Preface Semicolons in JavaScript are optional, an...

Steps for Vue3 to use mitt for component communication

Table of contents 1. Installation 2. Import into ...

Sample code for implementing 3D book effect with CSS

Without further ado, let's take a look at the...

mysql5.7.17 installation and configuration example on win2008R2 64-bit system

123WORDPRESS.COM has explained to you the install...