CSS Calc Viewport Units Workaround?

前端 未结 4 986
慢半拍i
慢半拍i 2020-12-02 15:22

From what I\'ve seen in other answers, CSS viewport units can\'t be used in calc() statements yet. What I would like to achieve is the following statement:

4条回答
  •  误落风尘
    2020-12-02 15:54

    As a workaround you can use the fact percent vertical padding and margin are computed from the container width. It's quite a ugly solution and I don't know if you'll be able to use it but well, it works: http://jsfiddle.net/bFWT9/

    
    
        
            
        
        
            
    It works!

    html, body, div {
        height: 100%;
    }
    body {
        margin: 0;
    }
    div {
        box-sizing: border-box;
        margin-top: -75%;
        padding-top: 75%;
        background: #d35400;
        color: #fff;
    }
    

提交回复
热议问题