盒模型的padding属性

http://img.mukewang.com/58f9b87f0001873704210284.jpg

http://img.mukewang.com/58f9b8800001c02e04940649.jpg

http://img.mukewang.com/58f9b89e0001f14405240430.jpg

问题1:

我想让这个“21”靠下,给<h2>加一个margin

h2{margin-top:50px}

http://img.mukewang.com/58f9b95100010ab303570387.jpg

http://img.mukewang.com/58f9bb170001fe8403450409.jpg

结果出现了个白边,这是为什么?

按理说,h2加上了margin-top,h2会下移,仍然在绿色背景中。



问题2:

给h2加个padding

h2{padding-top: 50px;}

http://img.mukewang.com/58f9b9f4000110ec03610330.jpg

http://img.mukewang.com/58f9babb0001f09b03260340.jpg


这样反而能达到效果。

这什么鬼,padding和margin为什么效果反了?



慕先生4543078
浏览 1595回答 1
1回答

我爱吃牛排

当两个空的块级元素嵌套时,如果内部的块设置有margin-top属性,而且父元素没有下边解决方法所述的特征,那么内部块的margin-top属性会绑架父元素(即将margin-top传递凌驾给了父元素)。同时padding也没有反 你没发现h2高度从69px变成119px了么 h2里面的字被自己的padding挤下去了而已那么正确的做法应该是.card{padding-top:50px;}如果采纳尽量今天以后再采纳 我今天满了

慕瓜9220888

HRQCMVPFRQBQLJJMFRVJLTLOERRLMRTSFOLLPXMXQSMCYEVEWBNXGVOGENYRHKUWHPBUXAAWEFNJIZSVYVTODFYHUWKYGIRQJGGFAIETWYIYMXFCENNJDTKIKZCEKTCDIKJWSICFNYDZZVVBEVNCEHDKGQEPHLBURRBVOGLDRIKRVNSEKXKFBIKCYRUUYRVRCHENKKDXCGLHXEESWBDNGTDMEFUFUPPLVGRWFBBYQWVFYQVLIRBGQFHKNNAZULVXPSSLXYQTSUTQHHJUZVDMGXUFGFQVPBVUJKDBGGJTZMQXZOHIIFEVUNLQKWWLPRTCVYROXOAYQGJGGYRQVHKDWPVYMVQQDWPUHMVDGTCICNMUCVHDZIZFDFFYLLTXFRWPMFCWXMODMCGZGBGACILEODUMRDGPZRHRXYQGNTPAHWBNTTCIKTPQPIBVRJAJOJCEOPAXMOGJCCFC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