一、特性:
<style>
#box1{
width: 100px;
height: 60px;
background: #666600;
text-align: center;
vertical-align: middle;
}
#box2{
width: 0px;
height: 0px;
padding: 10%;
background: #660000;
}
</style>
<body>
<div id="box1">
<div id="box2"></div>
</div>
</body>
答: width:100px,因為不設定width會自動佔滿父級元素(可參考day1的分享);heigh:20px,父級寬度100*10%*2=20
二、應用-固定比例縮放圖片的配置:
<style>
.box {
padding: 10% 50%;
position: relative;
}
.box > img {
position: absolute;
width: 100%; height: 100%;
left: 0; top: 0;
}
</style>
<body>
<div class="box">
<img src="rimg.jpg">
</div>
</body>