How to stretch div to fit the container ?
A child div inside a container can be made to take the complete width and height of the parent div. There are two methods to stretch the div to fit the container using CSS tat are discussed below:
Method 1: First method is to simply assign 100% width and 100% height to the child div so that it will take all available space of the parent div.
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.
Consider this HTML for demonstration:
Method 2: We can make the display attribute of the child container to table-row and display attribute of parent container to table, that will take all the height available from the parent div element. To cover all the width, we can make the width of parent div to 100%.