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

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:179日期: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.

下面是關于高度的:

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:

因為規范就是這么規定的算法,瀏覽器就是這么實現的。

CSS規范

回答2:

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

回答3:

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

回答4:

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

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 午夜精品一区二区三区视频 | 视频一区在线观看 | 色91视频 | 久久精品波多野结衣 | 亚洲一区精品在线 | 国产又粗又猛又黄又爽 | 日本中文字幕不卡 | 毛片在线观看视频 | 亚洲图片在线视频 | 久视频在线 | 波多野吉衣一区二区三区 | 五月天丁香久久 | 热99在线 | 日韩成人在线免费视频 | 成人国产一区二区 | 日韩欧美国产高清 | 亚洲综合在线观看视频 | av一道本| 一级免费黄色 | 亚洲无遮挡 | 在线免费精品 | 日韩簧片| 综合黄色 | 日韩免费久久 | 国产精品成人在线视频 | 天天看天天色 | 天堂网中文 | 国产精品美女久久久久av爽 | 欧美日韩操 | 国产不卡免费视频 | 一区二区三区视频 | 91在线网站 | 婷婷丁香在线 | 久久久久久久福利 | 一二三不卡视频 | 成人亚洲国产 | 95看片淫黄大片一级 | 成人深夜网站 | 国产一区二区三区精品在线观看 | 成人黄色免费在线观看 | 亚洲一区二区三区在线观看视频 |