我想要显示一个ASP.NET图像在一个DIV的中间(水平和垂直),我应该如何排列我的div和图像(图像应该是runat=server),我还应该为我的图像设置最大宽度和最大高度样式,div作为一个占位符,我的图像应该在DIV内,并且它应该在水平和垂直方向上都准确居中,你能显示正确的HTML和CSS吗?有样品吗?
发布于 2012-12-08 23:56:27
使用:
CSS
.placeholder{min-width:200px; min-height:200px;}
.placeholder img{
margin: 0px auto; /*centers element horizontally*/
vertical-align:middle; /*centers element vertically */
}您的html应该类似于:
<div class="container">
<div class="placeholder">
<!-- load image here -->
</div>
</div>发布于 2013-05-20 23:35:01
我真的很努力地寻找解决方案,希望它是100%有帮助的:-)
<html>
<style>
.placeholder {
width: 250px;
min-width: 250px;
height: 250px;
min-height: 250px;
display: block;
margin-left: auto;
margin-right: auto;
position: absolute;
left: 50%;
top: 40%;
margin: -100px 0 0 -125px;
}
</style>
<IMG class="placeholder" src="http://www.swoo.co.uk/content/images/icons/stackoverflow.png">
</html>替换您想要的任何img,以替换等于"src“的URL。请注意,当在浏览器中放大和缩小时,它也可以工作,它正好位于页面的中间,这是你能找到的最好的代码:)
https://stackoverflow.com/questions/13778616
复制相似问题