如何在表格单元格的 div 区域中进行图像换行?
我做了一个练习,编写一个不使用任何库或 jquery 的图像库。我将图像放入表格单元格中。我在 javascript moveLeft() 和 moveright() 中有函数。
图像移出单元格区域的错误。我希望用户在通过单元格边框时只能看到图像的一部分。
css 代码:
#moving_image {
background-image: url(picture/13.jpg);
background-repeat: no-repeat;
position: relative;
border:1px solid red;
width: 130px;
height: 100px;
left: 10px;
}
单元格的 html 代码:
.....
<tr height="130">
<td width ="420" height="130">
<div id= "moving_image">
</div>
</td>
</tr>
moveRight() 的 Javascript 代码,{作为示例。我还有 moveLeft()}:
<script language=javascript type="text/javascript">
var x=10;
function moveRight()
var layerElement = document.getElementById("moving_image");
x+=10;
layerElement.style.left=x;
}
....
</script>
那么,我该怎么做才能将图像包装在表格单元格中?谢谢
I do an exercise to write an image gallery w/o using any libraries or jquery. I put an image into a table cell. I have functions in javascript moveLeft() and moveright().
The bug that images moves out of the cell area. I want user will see only the part of the image when it passes cell border.
The css code:
#moving_image {
background-image: url(picture/13.jpg);
background-repeat: no-repeat;
position: relative;
border:1px solid red;
width: 130px;
height: 100px;
left: 10px;
}
The html code for cell:
.....
<tr height="130">
<td width ="420" height="130">
<div id= "moving_image">
</div>
</td>
</tr>
Javascript code for moveRight() ,{as example. I also has moveLeft()}:
<script language=javascript type="text/javascript">
var x=10;
function moveRight()
var layerElement = document.getElementById("moving_image");
x+=10;
layerElement.style.left=x;
}
....
</script>
So, what I do in order to wrap an image in the table cell? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试对表格行和包含图像的 div 使用 z-index
或给表行 CSS 参数“overflow:hidden”
Try using z-index for table row and the div containing your image
or give to table rows CSS parameter "overflow:hidden"
尝试用另一个 div 进行包装,并将该 css 应用于包装 div,如下所示:
try wrapping with another div and apply that css to the wrapping div like:
解决方案很简单,将 chaneg 设置为背景位置,而不是移动 div。
The solution is simply to make chaneg the
background-position
instead of moving the div.