Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

position 绝对定位的居中问题。

我在表格td里面放了一个DIV。给TD设置的relative;然后这个div absolute; 我设置了。left0 right:0 maigin o auto 但是还是没有居中。。--是什么原因呢。我觉得可能是因为这个div比td的宽度还要宽。所以失效了。。
怎么解决么。图片描述

长宽高这个框应该在委3/400 这个td里面。。。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

方法一:
div{

position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin:auto;

}
方法2:
div{

position: absolute;
left: 50%;
top: 50%;
transform:translate(-50%,-50%);

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...