- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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>
- Related Articles
- Flex container width when flex-flow is set to column wrap in HTML
- How to make the web page height to fit screen height with HTML?
- How to wrap each input line to fit in specified width in Linux?
- HTML wrap Attribute
- How an or should be resized to fit its container with CSS
- How to auto-resize an image to fit a div container using CSS?
- How to make a GridLayout fit screen size in Android?
- How to make your child mentally strong?
- How to use jQuery.wrapAll() to wrap multiple elements?
- HTML DOM Textarea wrap Property
- How to make a GridLayout fit screen size in Android using Kotlin?
- Selecting Child Elements with CSS
- Make HTML text input field grow as I type in JavaScript?
- Set the text wrap in a form in HTML
- Insert a node as a child before an existing child in JavaScript?

Advertisements