av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:116日期: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麻豆精品一区二区三区 | 欧美日韩大片 | 成人免费在线 | 九月丁香婷婷 | 91理论片午午伦夜理片久久 | 日日干夜夜爽 | 成人爽a毛片一区二区免费 亚洲午夜在线观看 | 黄色激情视频在线观看 | av不卡在线播放 | 免费一级黄色录像 | 综合色av | 黄色一级录像 | 免费看黄色的视频 | 欧美在线一区二区 | 日韩欧美三区 | 九色视频丨porny丨丝袜 | 在线观看欧美日韩视频 | 天堂中文资源在线 | 中文字幕在线免费观看 | www.日本在线| 极品尤物一区二区三区 | 欧美色综合 | 亚洲二区视频 | 狠狠躁夜夜躁人爽 | 女同一区二区三区 | 日韩不卡av| 色网站在线观看 | 成人影片在线 | 黄在线观看 | 国产免费a | 四川一级毛毛片 | av少妇 | 午夜精品视频在线 | 成人在线视频免费 | 久草青青草 | 成人免费视频国产免费 | 天天综合av | 国产精品乱码一区二区视频 |