午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

javascript - 為何margin:auto auto 不能上下左右對齊?

瀏覽:169日期:2023-06-16 08:40:44

問題描述

一個html中只有一個p。

<p class='test'></p>css1:.test{ width:200px; height:200px; border:1px solid red; margin:0 auto; }

css1可以使p.test左右居中。

css2:

.test{ width:200px; height:200px; border:1px solid red; margin:auto auto; } 為何css2不可以使p.test上下左右居中?? 請不要回答如何使他p.test上下左右居中,請回答為何margin:auto auto;不能上下左右居中??

問題解答

回答1:

The following constraints must hold among the used values of the other properties:

’margin-left’ + ’border-left-width’ + ’padding-left’ + ’width’ + ’padding-right’ + ’border-right-width’ + ’margin-right’ = width of containing block

If both ’margin-left’ and ’margin-right’ are ’auto’, their used values are equal. This horizontally centers the element with respect to the edges of the containing block.

下面是關(guān)于高度的:

If ’margin-top’, or ’margin-bottom’ are ’auto’, their used value is 0. If ’height’ is ’auto’, the height depends on whether the element has any block-level children and whether it has padding or borders:

因為規(guī)范就是這么規(guī)定的算法,瀏覽器就是這么實現(xiàn)的。

CSS規(guī)范

回答2:

這是個好問題,那我問你,當(dāng)一行存在兩個元素的時候,你可以左右居中嗎?同理當(dāng)你的上下都可能有元素存在的情況下你要瀏覽器怎么去計算對應(yīng)元素應(yīng)該存在的位置?

回答3:

不能吧,上下對齊如果不用flex布局,沒啥太好的辦法。virtical–align也不太好用!

回答4:

不能,如果想上下左右對居中的話,推薦使用flex布局,其次是table,table-cell或者定位

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 色在线视频 | 精品国产乱码久久久久久久 | 成人亚洲天堂 | 成人午夜免费在线观看 | 成人夜间视频 | 欧美黄色一区二区三区 | 亚洲视频二 | 蜜臀久久99精品久久一区二区 | 欧美日韩中文字幕视频 | 色偷偷免费视频 | 日本美女一区二区 | 午夜激情在线观看 | 日韩av手机在线观看 | 亚洲爱爱图 | 性xxxx搡xxxxx搡欧美 | 亚洲成人影院在线观看 | 久久精品8 | 国产女女调教女同 | 国产精品www色诱视频 | 少妇婷婷 | 欧美91在线| 九九热国产精品视频 | 久久久久在线视频 | av在线播放国产 | 激情综合婷婷 | 国产黄色网址在线观看 | 波多野吉衣一区 | 亚洲欧洲日韩av | 日韩精品综合 | 98久久| 日本成人综合 | 久久精品久 | a在线视频| 夜夜爽天天干 | 中文日韩字幕 | 9l视频自拍蝌蚪9l成人开放 | 一区二区在线免费观看 | 午夜综合网 | 污污视频在线观看免费 | 久久久久久久福利 | 黄a在线观看 |