margin的百分比
当图片的margin值设置为10%时,
那么图片img的上外边距margin-top等于蓝色背景宽度(width)*10%,
同样img的左外边距margin-left也等于蓝色背景宽度(width)*10%.
当图片margin设置为10% ,此时margin的值只与盒子的宽度有关,与高度无关
图片的margin-top与margin-left都等于盒子的宽度*10%
![](https://images2015.cnblogs.com/blog/1018520/201609/1018520-20160906110522723-1820294809.png)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> #box{ width: 600px; height: 200px; background: deepskyblue; } img{ margin: 10%; } </style> </head> <body> <div id="box"> <img src="img/logo.jpg"/> </div> </div> </body> </html>