My page is roughly:
Nested div elements under ul do not comply with XHTML specifications. ul is a block-level element. After setting a fixed width value, it can be centered through the margin:0 auto; style. If you also need to "group" list items to set different styles, you can do this by adding different style classes, such as:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><style type="text/css">ul { margin:0 auto; width:200px; }li.listGroup1 { color:red; }</style><ul> <li class="listGroup1">1</li> <li class="listGroup1">2</li> <li class="listGroup2">3</li></ul></body></html>
Set the ul inside Style: text-align:center can also see the effect. . . .
But text-align seems to only work on text
In the end, the problem was solved. I requested four columns in one row, so I created four divs in each row and set the widths to 25%. , then put