Discussion on image path issues in css (same package/different package)

Discussion on image path issues in css (same package/different package)
In CSS files, sometimes you need to use background, that is, add a background image, which is generally used when making button styles.

Adding background images in CSS can be divided into the following types according to the relative position of the image and the CSS file:
1. In the same package: background: url(aaa.gif);
2. Different packages:
In this case, there are two ways to set it. One is to use an absolute path, that is, upload/2022/web/www.iteye.com, but it is generally not recommended and is not conducive to project migration; the other is to use a relative path. First, you need to find a root directory common to the image file and the css file, and then add the subdirectory of the image, for example:
CSS file location: WebRoot/test/css/a.css
Image file location: WebRoot/platform/resource/images/icons/a.gif
If you want to find the common root directory, you need to use "../". This path means the parent directory. If there are two parent directories, it is "../../". Then, according to this writing method, the background image css in a.css should be written like this:

Copy code
The code is as follows:

background:url(../../platform/resource/images/icons/a.gif)

Why?

First, we observe the location of these two files and find that the common root directory is WebRoot.
We first find the WebRoot at the location of a.css, so we have "../../" and then the path of the subdirectory of the spliced ​​image is "platform/resource/images/icons/a.gif". Putting them together is the result above.

<<:  Detailed explanation of HTML style tags and related CSS references

>>:  Detailed explanation of common template commands in docker-compose.yml files

Recommend

Detailed analysis of when tomcat writes back the response datagram

The question arises This question arose when I wa...

A brief discussion on the problem of forgotten mysql password and login error

If you forget your MySQL login password, the solu...

WeChat Mini Program Basic Tutorial: Use of Echart

Preface Let’s take a look at the final effect fir...

Vue event's $event parameter = event value case

template <el-table :data="dataList"&...

Vue implements verification code countdown button

This article example shares the specific code of ...

Three ways to communicate between React components (simple and easy to use)

Table of contents 1. Parent-child component commu...

Implementation of MySQL5.7 mysqldump backup and recovery

MySQL backup Cold backup:停止服務進行備份,即停止數據庫的寫入Hot ba...

Building a KVM virtualization platform on CentOS7 (three ways)

KVM stands for Kernel-based Virtual Machine, whic...

React event binding details

Table of contents Class component event binding F...

Vue3 + TypeScript Development Summary

Table of contents Vue3 + TypeScript Learning 1. E...

Mysql optimization techniques for querying dates based on time

For example, to query yesterday's newly regis...

Vue+express+Socket realizes chat function

This article shares the specific code of Vue+expr...