and with Pure CSS?-CSS Tutorial-php.cn">
Home > Article > Web Front-end > How to Achieve a Consistent \"Background-Size: Cover\" Effect for
and and with Pure CSS?" > with Pure CSS? " /> and and with Pure CSS?" > with Pure CSS? " />
Cover Background Simulation for
Achieving a consistent "background-size: cover" effect for elements like
CSS Solution without Edge Cases:
Instead of relying on scripts, a CSS solution with no edge cases can be implemented using the following steps:
Example:
<code class="css">.parent-element-to-video { overflow: hidden; } video { height: 100%; width: 177.77777778vh; /* 100 * 16 / 9 */ min-width: 100%; min-height: 56.25vw; /* 100 * 9 / 16 */ }</code>
Centered Video:
To center the video, use the following CSS:
<code class="css">.parent-element-to-video { position: relative; } video { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }</code>
The above is the detailed content of How to Achieve a Consistent \"Background-Size: Cover\" Effect for