亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

第三種解決方案

#parent {

width: 200px;

height: 600px;

background: #ccc;

position: absolute;

}


#child {

width: 200px;

height: 200px;

background: #c9394a;

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

margin: auto 0;


正在回答

4 回答

可以解釋一下嗎?不是很明白原理

0 回復 有任何疑惑可以回復我~
#1

ccyy_阿亮

定位元素在包含塊中的方程(垂直方向): top + margin-top + border-top-height + padding-top + height + padding-bottom + border-bottom-height + margin-bottom + bottom = the height of the containing block
2020-12-02 回復 有任何疑惑可以回復我~

測試了下,這樣就行啦,當然,思路是你們的,我只是測試了下。。。?

#parent {

width: 200px;

height: 600px;

background: #ccc;

position: relative;

}


#child {

width: 200px;

height: 200px;

background: #c9394a;

position: absolute; top: 0; bottom: 0;?

margin: auto 0;


0 回復 有任何疑惑可以回復我~

第三種解決方案

<!DOCTYPE?html>

<html?lang="en">

<head>

??<meta?charset="UTF-8">

??<meta?name="viewport"?content="width=device-width,?initial-scale=1.0">

??<meta?http-equiv="X-UA-Compatible"?content="ie=edge">

??<title>測試</title>

??<style>


????.main{

??????width:100px;

??????height:500px;

??????background:?#666;

??????display:?flex;

??????align-items:?center;

????}

????.child?{

??????width:100px;

??????height:100px;

??????background:?red;

????}

??</style>

</head>

<body>

??<div?class="main">

????<div?class="child">

??????11111

??????1111111111

??????11111111111

??????11111111

??????</div>

??</div>

</body>

</html>


http://img1.sycdn.imooc.com//5def60f6000123b601600658.jpg

0 回復 有任何疑惑可以回復我~
#parent?{width:?200px;height:?600px;background:?#ccc;position:?relative;}#child?{width:?200px;height:?200px;background:?#c9394a;position:?absolute;?left:?0;?top:?0;?right:?0;?bottom:?0;margin:?auto;

這里應該是margin:auto? ,不是 margin:auto 0;

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

第三種解決方案

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號