img tag not working with relative path in src

后端 未结 5 1205
星月不相逢
星月不相逢 2020-12-17 16:00

This is not working:

\"Alternative

But this is working:



        
相关标签:
5条回答
  • 2020-12-17 16:42

    "../assets/images/image.jpg" -This means

    1. '../' go up one directory from where I am now
    2. find the 'assets/' folder
    3. find the 'images' folder
    4. find the 'image.jpg' file.

    That relative link will only work if your page is in a subfolder in

    "http://localhost/abc/def/geh/"

    If the location of your page really is

    "localhost/asdf/asdf/asdf/asdf/index.php"

    (which seems ridiculous) to get to the assets folder relatively you would have to go all the way to the root.

    '../../../../abc/deh/geh/assets/images/image.jpg;

    Alternatively you could use a base tag in your head tag to make the URL in the actual src attribute more friendly.

    0 讨论(0)
  • 2020-12-17 16:51

    I will make your life very very simple.
    Use it in following manner

    <img src="../image_store/Part2.jpg" alt="Dress Picture"/>

    0 讨论(0)
  • 2020-12-17 16:55

    I suspect you didn't actually do what I told you to so here is a screenshot:

    enter image description here

    If the image opens in a new tab then you have some kind of bug or extension that's messing it up in the html. If you messed up the relative path, you'll most likely get 404 but you'll be able to see the path as absolute. It may look like http://localhost/asdf/asdf/asdf/asdf/assets/assets/image.jpg Either way, send a screenshot of the above operation.

    0 讨论(0)
  • 2020-12-17 16:59

    In React:

    1. import the image:

      import image from '../../assets/random-image.png'
      
    2. use the imported variable as a value of a src attribute:

      <img src={image} />
      
    0 讨论(0)
  • 2020-12-17 17:00
    <img src="assets/images/image.jpg" alt="Alternative Text">
    

    should be working.You shouldn't have put '../' at the begining of the image path.

    For better understanding about relative paths vs. absolute paths, refer this link

    0 讨论(0)
提交回复
热议问题