Home >Web Front-end >CSS Tutorial >How Do I Center an Unordered List Inside a Fixed-Width Div Using CSS?
When working with HTML elements, it's common to require specific alignment and sizing. A typical scenario involves centering an unordered list (
Solution:
To center the
.wrapper { text-align: center; } .wrapper ul { display: inline-block; margin: 0; padding: 0; /* Ensure compatibility with older versions of Internet Explorer */ zoom: 1; *display: inline; } .wrapper li { float: left; padding: 2px 5px; border: 1px solid black; }
Explanation:
Implementation:
<div class="wrapper"> <ul> <li>Three</li> <li>Blind</li> <li>Mice</li> </ul> </div>
Note: This solution provides maximum width flexibility for the
Update:
For a hands-on demonstration, visit the jsFiddle link provided in the reference material.
The above is the detailed content of How Do I Center an Unordered List Inside a Fixed-Width Div Using CSS?. For more information, please follow other related articles on the PHP Chinese website!