Home >Web Front-end >HTML Tutorial >[CSS Tips] Another way to arrange the list horizontally_html/css_WEB-ITnose
Lists
<!doctype html><html><head><meta charset="utf-8"><title>列表横向排列的另一种方法</title><style type="text/css">ul li{display:inline;background:#F93; padding:5px;}}</style></head><body><ul> <li>Item1</li> <li>Item2</li> <li>Item3</li> <li>Item4</li></ul></body></html>
Effect:
Wait, why is there a gap between the li's? ? ?
The solution is: write li in one line
<ul> <li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li></ul>
Yes, it is written like this (I don’t know if it is a bug)
This method has a drawback: after li is converted to an inline element, width and height are invalid, and padding can only be used to expand the width and height. There are also some inconveniences. Make your own choice based on your needs.