国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

javascript - Warum kann margin:auto auto nicht nach oben, unten, links und rechts ausgerichtet werden?
過(guò)去多啦不再A夢(mèng)
過(guò)去多啦不再A夢(mèng) 2017-06-24 09:42:38
0
4
1270

Es gibt nur ein p in einem HTML.

<p class="test">
</p>

css1:

.test{
    width:200px;
    height:200px;
    border:1px solid red;
    margin:0 auto;
    }

css1 kann p.test links und rechts zentrieren.

css2:

.test{
    width:200px;
    height:200px;
    border:1px solid red;
    margin:auto auto;
    } 

為何css2不可以使p.test上下左右居中?? 
請(qǐng)不要回答如何使他p.test上下左右居中,請(qǐng)回答為何margin:auto auto;不能上下左右居中?? 
過(guò)去多啦不再A夢(mèng)
過(guò)去多啦不再A夢(mèng)

Antworte allen(4)
大家講道理

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:

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

  • CSS規(guī)范

阿神

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

某草草

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

洪濤

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

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage