![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Make container shrink-to-fit child elements as they wrap in HTML
We can easily make container shrink-to-fit child elements as they wrap. First, we will set the flex container flexible −
display: flex;
We will set the flex items to wrap −
flex-wrap: wrap;
Set the text center aligned using the text-align property −
text-align: center;
The list-style-type property is set to None to display no marker −
list-style-type: none;
Example
Let us now see the complete example −
<!DOCTYPE html> <html> <title>Flex Example</title> <head> <style> ul { display: flex; flex-wrap: wrap; margin: 0; padding: 0; border: 2px solid red; } li { border: 2px solid orange; margin: 10px; padding: 10px; width: 200px; text-align: center; list-style-type: none; } </style> </head> <body> <div id="container"> <ul> <li>A</li> <li>B</li> <li>C</li> <li>D</li> <li>E</li> <li>F</li> <li>G</li> <li>H</li> </ul> </div> </body> </html>
Advertisements