Home  >  Article  >  Web Front-end  >  DIV水平居中_html/css_WEB-ITnose

DIV水平居中_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 09:40:231324browse

.CContainer{	position:		absolute;	margin:		0 auto;                  /*有上面一行代码,这里就无用了……,但是我一定要用上面那一行……*/	padding:		0px 0px 0px 0px;	width:		1024px;	height:		auto;}


。。如何可以居中……
= =、备注在代码里


回复讨论(解决方案)

.CContainer
{
position:absolute; 
top:50%; 
left:50%; 
margin:-150px 0 0 -200px; 
width:400px; 
height:300px; 
border:1px solid red; 
}
DIV垂直居中,其实解决的思路是这样的:首们需要position:absolute;绝对定位。而层的定位点,使用外补丁margin负值的方法。负值的大小为层自身宽度高度除以二。

.CContainer
{
position:absolute; 
top:50%; 
left:50%; 
margin:-150px 0 0 -200px; 
width:400px; 
height:300px; 
border:1px solid red; 
}
DIV垂直居中,其实解决的思路是这样的:首们需要position:absolute;绝对定位。而层的定位点,……

.CContainer
{
position:absolute; 
top:50%; 
left:50%; 
margin:-150px 0 0 -200px; 
width:400px; 
height:300px; 
border:1px solid red; 
}
DIV垂直居中,其实解决的思路是这样的:首们需要position:absolute;绝对定位。而层的定位点,……  学习了。

#1 正解。。

= =我要的是水平居中,其实我已经自己解决了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn