Attempting to create a div
while maintaining a 16:9 aspect ratio using CSS led me to conduct a Google search. Fortunately, I stumbled upon a helpful resource on Stack Overflow that detailed how to achieve this: How to maintain the aspect ratio. Excited to implement this myself, I encountered an issue when inserting text within the div
, resulting in a change in the aspect ratio from 16:9.
The problem arises when adding li
elements as children; this distorts the desired aspect ratio. How can we ensure the aspect ratio remains intact even with text content?
Code Snippet:
div {
width: 70%;
}
ul {
padding-bottom: 56.25%;
background: green;
}
<div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>