As shown in the picture, I want to use css to center the red div horizontally and vertically on the large div. How to achieve this? center can only achieve horizontal centering, how to replace it with css? . Thank you.
Is it possible to use margin:auto?
Try this
Horizontally and vertically centered, compatible with ie6
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css">li {float:left;text-decoration:none;padding-left:20px;text-align:center;}.bigdiv {border:1px solid;text-align:center;height:100px;width:500px;display:table;_position:relative; text-align:center;}.bigdiv .pos{display:table-cell;vertical-align:middle;_position:absolute;_top:50%;_left:50%; }.bigdiv .pos span{_position:relative;_top:-50%;_left:-50%; display:block;border:1px solid red; height:50px; width:300px; text-align:center;line-height:50px; margin:0 auto;}</style></head><body><ul style="height:36px; list-style:none;"><li>首页</li><li>新产品</li><li>服务指南</li><li>合作伙伴</li><li>联系我们</li></ul><div class="bigdiv"><!--<center>--> <div class="pos"> <span>123</span> </div><!--</center>--></div></body></html>
Use absolute layout position:absolute;top:50 %;left:50%;
Specify the width margin:auto and center the parent layer
Set the line-heigt value of the outermost frame to be consistent with its height