首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >css -居中显示3列布局<ul>

css -居中显示3列布局<ul>
EN

Stack Overflow用户
提问于 2018-03-26 16:21:28
回答 2查看 519关注 0票数 0

我有一个通过调用API生成的清单--每个页面的清单限制为30个,每个列应该有10个清单。

目前,它看起来并没有居中,尤其是在更大的屏幕上。我尝试了空余:0自动,但没有任何工作。我可以手动完成,但该解决方案对于较大的屏幕是可行的,并确保它们具有响应性(在移动设备上变为2列,然后是1列)。我该如何纠正这个问题?

css:

代码语言:javascript
复制
#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:

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

发布于 2018-03-26 16:33:58

这可以使用display flex来完成。

代码语言:javascript
复制
.wrapper {
    display: flex;
}
.column {
    flex: 0 0 33%; // column does not grow or shrink. but takes up 33% of the space
}
票数 0
EN

Stack Overflow用户

发布于 2018-03-26 16:47:20

代码语言:javascript
复制
#native {
 display: flex;
 justify-content: center;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49486939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档