100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > html绝对定位怎么页面居中 html – 如何将绝对定位的元素居中?

html绝对定位怎么页面居中 html – 如何将绝对定位的元素居中?

时间:2019-01-16 18:52:59

相关推荐

html绝对定位怎么页面居中 html – 如何将绝对定位的元素居中?

使位置居中的元素:绝对;应用通过使用两个嵌套元素(

demo).

>第一个元素绝对定位于将其置于所有其他元素之上

>第二个元素就像你期望的那样:使用margin:0 auto;以中心为中心.

HTML:

This is a modal window being centered.

CSS:

.outer-div {

position: absolute;

top: 0;

right: 0;

bottom: 0;

left: 0;

z-index: 13;

/*

* Setting all four values to 0 makes the element as big

* as its next relative parent. Usually this is the viewport.

*/

}

.inner-div {

margin: 0 auto;

width: 400px;

background-color: khaki;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。