简体   繁体   English

如何在div中添加图片?

[英]How do i add an image in a div?

I need to insert a image to be zoom in and out but some website told me that it is suppose to be use with path="image url". 我需要插入图像以进行放大和缩小,但是一些网站告诉我,它应该与path =“ image url”一起使用。 The image didn't appear so i want to use background-image: url("image url"). 该图像没有出现,所以我要使用背景图像:url(“ image url”)。 So how do i put it in to allow image to show? 那么我该如何放置才能显示图像呢?

<style type="text/css">

#html{
    height:100%;
}

#body{
    height:100%;
    margin:0px;
    padding:0px;

}

#hr{ 
    border:0;
    width:50%;
}


</style>


<body>


<div id="outerDiv0">
  <div id="outerDiv" style="position:relative;height:99%;width:100%;border:1px solid black;overflow:hidden;">

    <div style="position: absolute; top: 10px; left: 10px; z-index: 1">
      <img src="zoomin_off.gif"
           onclick="ZoomIn()" alt="zoomin"/>
    </div>
<div style="position: absolute; top: 10px; left: 90px; z-index: 1">
      <img src="zoomout_off.gif"
           onclick="ZoomOut()" alt="zoomout"/>
    </div>

    <div id="Nav" style="display:none;position: absolute; top: 70px; left: 20px; z-index: 1"><div><a href="javascript:slidePrev();" id="slidePrev"><img src="prev.gif" alt="prev"/></a></div>
<div style="position: absolute; top: 0px; left: 79px;"><a href="javascript:slideNext();" id="slideNext"><img src="next.gif" alt="next"/></a></div></div>

    <div id="imageTiles" style="position:relative;top:0;left:0;z-index:0;width:100%;"></div>
    <div id="imageLabels" style="position:relative;top:0;left:0;z-index:1;width:900000px;height:900000px;"></div>
    </div>

  <div id="overlay"><div id="theScale"></div><div id="theInfo">
  </div>
  <div id="Thumb0"><div id="Thumb"></div><div id="Thumb2"></div></div>
  </div>

  <div id="wheelMode">Mouse Wheel:<input type="radio" onclick="wheelMode1()"          />&nbsp;Zoom<input type="radio" onclick="wheelMode2()" />&nbsp;Next/Prev</div>
  <div id="coords" style="position:absolute;top:2px;right:10px;z-index:10;"></div>



  </div>

Without any example code we can only guess. 没有任何示例代码,我们只能猜测。 Maybe your div did not have any dimensions. 也许您的div没有任何尺寸。 Try adding width and height with css to your div: 尝试使用CSS将宽度和高度添加到div中:

<div style="width:300px;height:300px;background:url('http://webpage/path/to/image.jpg')"></div>

Can you try this, 你可以试试这个吗

CSS: CSS:

.Bg{
  width:300px;
  height:300px;
  background-image:url('imagepath');
 }

HTML: HTML:

 <div class='Bg'></div>

Its hard to understand what exactly you want to do,however if you want to add background image to div you can do it as follows 很难理解您到底想做什么,但是如果要将背景图像添加到div中,则可以按照以下步骤进行操作

<div class="show">
some text
</div>

in CSS 在CSS中

.show
{
background-image:url('paper.gif');
//other css properties of div
}

ref REF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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