DEV Community

Discussion on: Quick CSS Quiz #2

Collapse
 
mredel profile image
MrEdel

I know that padding is always calculated from the width but I can't say why, there is no real reason in the specs.

I just knew the answer because I had to build a webpage with squares as page elements where I used the padding technique to get it to work without fixed widhts and heights for the squares.

Collapse
 
ismail9k profile image
Abdelrahman Ismail

This is one of the CSS behaviors that can be awkward at first, but once you learn it, you will know how it's so powerful tool.
As you said you can use it to create perfect squares, even more you can create a fixed ratio between width and height for example, this is how you can create a responsive video base on this behavior:

.videoWrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 25px;
    height: 0;
}
.videoWrapper video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}