简体   繁体   中英

Image in <div img>

Not working with my images that are inside a folder 'images'.

<img src....> in the div won't help me. I need to do it inside the div <div style=..[here]> .. because it's not something default.

Thank you.

The only way to set an image source from the style property is to set it as a background image. The syntax for that is: <div style="background-image: url('/folder/path/image2.jpg');">

Note that background image and img styling are very different.

It seems like what you're saying though is you need to set an image dynamically. If so, you're going to have to use a little javascript:

<script type="text/javascript">
  document.getElementById("myImage").src = "image2.jpg";
</script>

or if you really do want to set a background image:

<script type="text/javascript">
  document.getElementById("myImage").style.backgroundImage = "url('image2.jpg')";
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM