Home > Web Front-end > HTML Tutorial > The difference between image paths in css and javascript

The difference between image paths in css and javascript

WBOY
Release: 2016-11-30 23:59:33
Original
1228 people have browsed it

When I was typing code today, I wanted to write a function to switch avatars, but here comes the problem, the avatar just doesn’t appear. Suddenly, I had an idea. Is it possible that the way to write image paths in CSS and JavaScript is different? ? ? ... " and "script" are used to store the used .css files and .js files

index.html contains

<div id="pic">
<p>开心吗</p>
</div>
Copy after login
    If I want to set the image background of the tag with the ID of pic, write this in the css file:
  1. #pic{ background:url(../images/bg1.png); }
    Copy after login
  2. In the js file, the path must be written as images/bg1.png
  3. In short,
  4. (1) For js scripts, html loads the script into the page and parses it together (it is the same as writing your js script directly on this page)
    (2) For css files, it only provides a link and does not load it into the html page. For example, in this example, html looks for the required image file in the css file according to the link.
  5. The image file path of css is relative to itself, and the image file path of js is relative to the file where it is located.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template