Home >Web Front-end >CSS Tutorial >Why Doesn\'t My Horizontal List Items Align Properly, and How Can I Fix It?
Horizontal List Formatting Solution
Horizontal item lists are a common web design element, but formatting them can be challenging. One user encountered an issue with a horizontal list not aligning properly despite attempts like setting 'float' to left.
The provided code sample demonstrates the markup and styles used for the horizontal list:
ul#menuItems { ... } ul#menuItems li { display: inline; ... } ul#menuItems li a { ... }
<ul>
The issue stemmed from the use of display: inline on the list items. While this method aligns the list items horizontally, it also removes the space between them. To resolve this, the code should be updated to use display: inline-block for the list items:
ul > li { display: inline-block; /* You can also add some margins here to make it look prettier */ }
With this modification, the list items will be displayed horizontally with the desired spacing. The following updated HTML code will also work:
<ul>
The above is the detailed content of Why Doesn\'t My Horizontal List Items Align Properly, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!