CSS:如何在桌面上放置图像
我有一个数字表,我想附加一个图像 在表格顶部的数据边框边缘。但是我没有 有人能给我指出正确的方向吗 以下是我想要实现的目标: 目前我的桌子上没有圆形的“箭头”和“=”图像 谢谢 根据以下建议,我已实现此代码:CSS:如何在桌面上放置图像,css,image,css-float,Css,Image,Css Float,我有一个数字表,我想附加一个图像 在表格顶部的数据边框边缘。但是我没有 有人能给我指出正确的方向吗 以下是我想要实现的目标: 目前我的桌子上没有圆形的“箭头”和“=”图像 谢谢 根据以下建议,我已实现此代码: <td> <img src="images/up.png" alt="increase" height="20" width="20" style="position: relative; left: 47px;"/>€<?php echo
<td>
<img src="images/up.png" alt="increase" height="20" width="20" style="position: relative; left: 47px;"/>€<?php echo $cSalePrice; ?>
</td>
&欧元;
给出以下结果:
如您所见,箭头图像未居中于块和
此外,文本“€65”也被向下推
有什么想法吗
好的,现在尝试评论的建议,它已经修复了“€65”轻推。
但图像仍然没有垂直居中于长方体:
一种解决方案是将
放置在左侧TD中,例如,为其提供以下样式以将其向右移动到布局位置:
position: relative;
left: 16px;
例如,一种解决方案是将
放置在左侧TD中,并为其提供以下样式以将其向右移动到布局位置:
position: relative;
left: 16px;
你的图像应该有一个绝对位置,上左(或右下)。它所处的
<td style="position:relative;">€65<img src="..." style="position:absolute; left:30px; top: 3px;"> </td>
&欧元;65
这样,您就可以相对于图像所在的td来定位图像
你应该使用类而不是内联代码,你的图像应该有一个绝对位置,左上角(或右下角)。它所处的
<td style="position:relative;">€65<img src="..." style="position:absolute; left:30px; top: 3px;"> </td>
&欧元;65
这样,您就可以相对于图像所在的td来定位图像
您应该使用类而不是内联代码,类似的方法可能会奏效。创建一个额外的列并使宽度为0。我使用的是div而不是图像,但它是一样的。你可以试试 css
table {
margin: 10px;
}
table td {
border: 1px solid black;
padding: 10px;
width: 100px;
}
table td.thin {
position: relative;
width: 0;
padding: 0;
border: none;
text-align: center;
}
table td.thin div {
position: absolute;
width: 20px;
height: 20px;
margin-left: -10px;
margin-top: -10px;
top: 50%;
left: 50%;
background: red;
text-align: center;
line-height: 20px;
border-radius: 10px;
}
还有html
<table>
<tr>
<td>r1c1</td>
<td class="thin"><div>×</div></td>
<td>r1c3</td>
</tr>
<tr>
<td>r2c1</td>
<td class="thin"><div>×</div></td>
<td>r2c3</td>
</tr>
</table>
r1c1
×
r1c3
r2c1
×
r2c3
这将确保垂直和水平居中,不会影响其他单元格。类似的操作可能会起作用。创建一个额外的列并使宽度为0。我使用的是div而不是图像,但它是一样的。你可以试试 css
table {
margin: 10px;
}
table td {
border: 1px solid black;
padding: 10px;
width: 100px;
}
table td.thin {
position: relative;
width: 0;
padding: 0;
border: none;
text-align: center;
}
table td.thin div {
position: absolute;
width: 20px;
height: 20px;
margin-left: -10px;
margin-top: -10px;
top: 50%;
left: 50%;
background: red;
text-align: center;
line-height: 20px;
border-radius: 10px;
}
还有html
<table>
<tr>
<td>r1c1</td>
<td class="thin"><div>×</div></td>
<td>r1c3</td>
</tr>
<tr>
<td>r2c1</td>
<td class="thin"><div>×</div></td>
<td>r2c3</td>
</tr>
</table>
r1c1
×
r1c3
r2c1
×
r2c3
这应确保垂直和水平居中,不会影响其他单元格。使表格相对 然后在te表中添加四个绝对定位的图像,并将它们定位到各自的角上。例如:
table{position:relative}
table img.topright{position:absolute;top:0;right:0;}
table img.bottomleft{position:absolute;bottom:0;left:0;}
etc使表格相对 然后在te表中添加四个绝对定位的图像,并将它们定位到各自的角上。例如:
table{position:relative}
table img.topright{position:absolute;top:0;right:0;}
table img.bottomleft{position:absolute;bottom:0;left:0;}
etc我宁愿设置位置:相对;到位置和位置:绝对;与图像一致。记住同时设置顶部和左侧,否则IE将失败。我宁愿设置位置:相对;到位置和位置:绝对;与图像一致。记住同时设置顶部和左侧,否则IE将失败。