我有一个通过调用API生成的清单-每个页面的清单限制为30个,并且每列应该有10个清单。
目前,它看起来并没有居中,尤其是在更大的屏幕上。我尝试了margin:0自动,但没有任何效果。我可以手动执行此操作,但是该解决方案适用于较大的屏幕,并确保它们响应(在移动设备上为2列,然后为1列)。如何解决此问题?
CSS:
#native {
width: 100%;
margin: auto;
padding: 0;
position: relative;
left: 2%;
}
#native ul {
list-style: none;
display: inline-block;
padding-right: 65px;
}
@media(max-width: 480px){
#native {
-moz-column-count: 1;
-webkit-column-count: 1;
column-count: 1;
}
}
@media(max-width: 768px){
#native {
left: 0;
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
}
@media (min-width: 1600px)
{
#native {
max-width: 1600px;
}
#native ul {
padding-right: 150px;
}
}
html / php:
<div id="native" class="margin-top-2x">
<ul>
<?php
$i=1;
foreach ( $model as $d ) { ?>
<?php if ( !empty ( $d['id'] ) ): ?>
<li>
<a href="<?php echo $this->createUrl ( 'frontend/detailedView' , array( 'id' => $d['id'] ) ) ?>"><?php echo ysUtil::truncate($d['title'], 45) ?></a>
<br>
</li>
<?php endif; ?>
<?php
if ( ($i % 10) == 0 ) {
echo "</ul>";
echo (end ( $model['id'] ) == $d['id']) ? "" : "<ul>";
}
$i++;
?>
<?php } ?>
</div>
最佳答案
这可以通过display flex来完成。
.wrapper {
display: flex;
}
.column {
flex: 0 0 33%; // column does not grow or shrink. but takes up 33% of the space
}
关于php - CSS-将3列布局居中<ul>,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49486939/