亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:101日期: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小说 | 日韩精品一区在线 | 国产成人精品久久综合 | 婷婷sese| 亚洲欧美日本综合一区二区三区 | 日韩高清在线亚洲专区vr | 国产毛片网站 | 久久国内精品自在自线软件 | 成年黄网站免费大全毛片 | 污视频在线观看网址 | 国产一级爱c片免费播放 | 欧美成人免费草草影院 | 国产精亚洲视频 | 国产a三级三级三级 | 欧美一级久久久久久久大 | 色在线视频免费 | 亚洲综合网在线观看 | 婷婷色吧 | 成年女人视频在线观看免费 | 亚洲欧美久久婷婷爱综合一区天堂 | sese在线| 宅男噜噜噜一区二区三区 | 美女免费毛片 | 欧美精品在线免费观看 | 97色伦色在线综合视频 | 亚洲精品视频在线观看免费 | 在线日韩国产 | 久久最新免费视频 | 久久久久久久久免费视频 | 69成人做爰视频69 | 欧美一区二区三区大片 | 国产在线精品一区二区三区不卡 | 国产成人综合亚洲一区 | 91香蕉小视频 | 欧美一级性 |