C# 如何在Windows窗体中将图像放置在文档中心
在Windows窗体中使用C# 如何在Windows窗体中将图像放置在文档中心,c#,html,css,winforms,C#,Html,Css,Winforms,在Windows窗体中使用WebBrowser控件时,如何将图像放置在文档中心(水平和垂直方向) 以下代码在JSFiddle()中工作,但在WebBrowser控件中不工作: this.webBrowser.DocumentText = "<!DOCTYPE HTML>" + "<html>" + "<head>" + "<st
WebBrowser
控件时,如何将图像放置在文档中心(水平和垂直方向)
以下代码在JSFiddle()中工作,但在WebBrowser
控件中不工作:
this.webBrowser.DocumentText =
"<!DOCTYPE HTML>" +
"<html>" +
"<head>" +
"<style type=\"text/css\">" +
"img.center {" +
"position: absolute;" +
"top: 0; bottom:0; left: 0; right:0;" +
"margin: auto;" +
"}" +
"</style>" +
"</head>" +
"<body>" +
"<img class=\"center\" src=\"https://d1u2uhea8ugy8e.cloudfront.net/info/static/img/globals/loading.gif\">" +
"</body>" +
"</html>";
this.webBrowser.DocumentText=
"" +
"" +
"" +
"" +
“img.center{”+
“位置:绝对;”+
顶部:0;底部:0;左侧:0;右侧:0+
“保证金:自动;”+
"}" +
"" +
"" +
"" +
"" +
"" +
"";
它给了我以下结果:
以下是预期的行为:
为什么??我做错了什么?我怎样才能修好它
提前感谢。你应该选择一个div,并将中间类交给该div,而不是img标签 看看这个例子
.center{
宽度:100%;
文本对齐:居中;
垂直对齐:中间对齐;
高度:300px;
填充顶部:130px;
}
尝试使用此代码 哈哈哈,这个问题很好。您应该在internet explorer中检查JSFIDLE。您正在使用
webBrowser
控件,其功能与IE相同。您还可以帮助我进行文本对齐(水平和垂直对齐)吗?
img.center {
position: absolute;
top: 50%;
margin-top: -25px; //half of image height
left: 50%;
margin-left: -25px; //half of image width
}