【问题标题】:Split elements equally inside div在 div 内平均分割元素
【发布时间】:2018-03-15 01:33:03
【问题描述】:

我完全被困住了。我基本上想做什么: 我想平均分割 div 内的元素,并证明行上的第一个元素将在左侧旁边,而行上的最后一个元素将在右侧旁边。如果有更多元素,它应该转到下一行并重复该过程。下面是一个例子 ->

{A | B | C | D}
{E | K

我的代码:HTML:

<div class="webso-products">
    <div [ngClass]="'ui card webso-card'" *ngFor="let product of allProducts">
        <app-product></app-product>
    </div>
</div>

我的代码 CSS:

.webso-products {
    display: block;
    width: 100%;
    height: auto;
    text-align: justify;
}

.webso-products .webso-card {
    display: inline-block;
    background-color: #1b2a47;
    border: none;
    box-shadow: none; 
    padding: 1rem 1rem 0rem 1rem; 
}

我尝试过使用伪元素:after(宽度:100% 和显示:inline-block),但不知何故在使用 Angular 迭代时它不起作用。 .

非常感谢您的帮助。

【问题讨论】:

    标签: angular center justify


    【解决方案1】:

    你可以不做吗?

    <div class="webso-products">
        <div [ngClass]="'ui card webso-card'" *ngFor="let product of allProducts">
            <div class="webso-card-product">
                <app-product></app-product>
            </div>
        </div>
    </div>
    

    .webso-card{display:flex; flex-direction:row}
    .webso-card-product{width=25%}
    @media #{...} {
        .webso-card-product{width=...}
    }
    

    【讨论】:

    • 实际上并不是设计应该是响应式的,在某些情况下它会适合 4 个元素,有时是 3 或 2 个。我希望你明白这一点。
    • @user2149578 我已将答案更新为响应式。一个问题:您想要每行 4 个元素还是想要动态项目编号?
    • 嗯,这可能是最有可能的一种方式,但如果这种情况没有更简单的解决方法(我认为这很常见),我会感到惊讶......
    猜你喜欢
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    • 2011-03-16
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    相关资源
    最近更新 更多