好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

div居中的问题_html/css_WEB-ITnose

div {
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0
bottom: 0;
width: 100px;
height: 100px;
border:1px solid red;
}
将产生一个div, width: 100px; height: 100px; 外边框 1px 红色实线 ;
div居于屏幕中间,对于居于中间这点,我无法理解,为何下面的做法不可以?
div {
margin: auto;
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
border:1px solid red;
}


回复讨论(解决方案)

问题1
top: 0;
left: 0;
为何不可以代替
top: 0;
left: 0;
right: 0
bottom: 0;

问题2
margin:auto为何不可以代替
margin: auto;
top: 0;
left: 0;
right: 0
bottom: 0;


 	 		 		div {			margin: auto;			position: absolute;			right: 0;			bottom: 0;			top: 0;			left: 0;			width: 100px;			height: 100px;			border:1px solid red;			}		 	 	 		

查看更多关于div居中的问题_html/css_WEB-ITnose的详细内容...

  阅读:28次