css設置高度為寬度的百分之多少


html

    <div class="banner">
        <div>

        </div>
    </div>

css

.banner{
    width: 100%;
    padding-bottom: 100%;
    position: relative;
}

.banner div{
    background: red;
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
}

巧妙的實現了高度百分之百。更改padding-bottom的值即可實現高度為寬度的百分之多少。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM