目标宽度÷上下文宽度=结果(比例宽度)
<wbr><div> <strong>当前元素的像素宽度÷当前元素的父元素的像素宽度=当前元素的百分比宽度</strong><wbr><div><br></div> <div>例如:</div> <div><pre name="code" class="html"><div id=wrapper> <header><header> <section></section> <aside></aside> </div></pre></div> <div><br></div> <div> <div><code></code></div> 原CSS:<wbr><div><pre name="code" class="css">#wrapper {width:1000px;} header {width:1000px;} aside {width:220px;float:left;} section {width:770px;float:right;} </pre></div> <div><br></div> <div>百分比宽度CSS:<wbr></wbr> </div> <div> <pre name="code" class="css">#wrapper {width:98%;}//指定外围宽度,数值随意 header{width:100%;}//套公式1000÷1000(这个1000是wrapper的宽度)=1=100% aside{width:22%;float:left;}//套公式220÷1000=0.22=22% section{width:77%;float:right;}//套公式 770÷1000=0.77=77%</pre> <br> </div> </wbr> </div> </wbr> </div> </wbr>