0

到目前为止,我有这个代码:

function changeGeoLoc($a,$b,$c){
echo "<ul style='list-style-type: none; display:inline;'>";

while(list(,$geoloc) = each($a) AND list(,$Details) = each($b)) {
echo "<li style='list-style-type: none; display:inline; padding-right:5px;'>$Details {$c->$geoloc} </li>";
}
echo "</ul>";

}

产生这个:

上述代码的产物

有谁知道如何使上述居中,使其在中间?

任何想法表示赞赏。

谢谢

更新:我尝试将样式设置为块并使用固定的边距进行设置:0 auto 但这是一个问题,我需要它沿着 100% 的宽度延伸,因为字段“IP、城市、地区、国家名称和国家代码将通过 GeoLoc 服务自动填充,因此固定宽度为 500px 不够大,因此它需要是整个宽度,我希望它居中,因为如果有人查看我的网页,则信息不会使用整个宽度它看起来会更好地居中。我希望这是有道理的

4

3 回答 3

2

尝试这个:

<ul style='list-style-type: none; display:block; width:500px; margin:0 auto;'>
于 2011-03-08T21:22:59.783 回答
1

如果您想在不提供固定宽度的情况下将 UL 的内容居中,最简单的方法可能如下:

function changeGeoLoc($a,$b,$c){
echo "<ul style='list-style-type: none; text-align: center;'>";

while(list(,$geoloc) = each($a) AND list(,$Details) = each($b)) {
echo "<li style='list-style-type: none; display:inline; padding-right:5px;'>$Details {$c->$geoloc} </li>";
}
echo "</ul>";

}
于 2011-03-08T21:33:36.267 回答
0

将其包装ul在一个 div 中,然后添加这个 CSS:

.className {
    margin:0 auto;
}

HTML:

<div class="className">
<ul style='list-style-type: none; display:inline;'>
<li style='list-style-type: none; display:inline; padding-right:5px;'>Stuff</li>
</ul>
</div>

将 ul 样式更改为block

于 2011-03-08T21:23:15.787 回答