简体   繁体   English

如何使用 Bulma 在 css 中创建一系列按钮右对齐的行?

[英]How do I create a series of rows where a button is right aligned in css using Bulma?

I'm using Bulma (and Buefy with Vue) and I've got a panel with a series of items defined like this:我正在使用 Bulma(以及带有 Vue 的 Buefy)并且我有一个面板,其中包含如下定义的一系列项目:

<template>
  <div v-if="user">
    <nav class="panel">
      <p class="panel-heading">
        Cities
      </p>
      <div class="panel-block" v-for="c in user.cities">
        <div class="is-pulled-left">{{c}}</div>
        <div class="is-pulled-right"><fai class="has-text-danger" icon="minus-circle"></fai></div>
      </div>
    </nav>
  </div>
</template>

That looks like this:看起来像这样:

截屏

How do I get it so the buttons are aligned on the right, not the left?如何让按钮在右侧而不是左侧对齐?

2021 Update: Newer versions of bluma have their flex box helpers. 2021 年更新:较新版本的 bluma 有其 flex box 助手。 You can just add a single class to our panel-block to achieve this effect.您只需向我们的panel-block添加一个类即可实现此效果。 Use is-justify-content-space-between like so:像这样使用is-justify-content-space-between

<div class="panel-block is-justify-content-space-between" v-for="c in user.cities">
  <div class="is-pulled-left">{{c}}</div>
  <div class="is-pulled-right"><fai class="has-text-danger" icon="minus-circle"></fai></div>
</div>

Use justify-content: flex-end使用justify-content: flex-end

Just by inspecting the html, we can see that the Bulma class panel-block applies a justify-content: flex-start to all it's child elements.只需检查 html,我们就可以看到 Bulma 类panel-blockjustify-content: flex-start应用于它的所有子元素。 This means that even if you apply is-pulled-right to the inner divs, everything will always be positioned left.这意味着即使您将is-pulled-right应用于内部 div,所有内容也将始终位于左侧。 Applying justify-content: flex-end to the outer parent container will force everything to the right.justify-content: flex-end应用于外部父容器将强制所有内容向右。 So, in short, you can override some of Bulma's default styling to get what you want.因此,简而言之,您可以覆盖一些 Bulma 的默认样式来获得您想要的。

 .end { justify-content: flex-end !important; }
 <link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.css" rel="stylesheet" /> <div> <nav class="panel"> <p class="panel-heading"> Cities </p> <div class="panel-block end"> <div class="">New York</div> </div> <div class="panel-block end"> <div class="">London</div> </div> <div class="panel-block end"> <div class="">Paris</div> </div> </nav> </div>

Try wrapping them in a column class.尝试将它们包装在列类中。
For example:例如:

<div class="panel-block" v-for="c in user.cities">
  <div class="column is-6">
    <div class="is-pulled-left">{{c}}</div>
    <div class="is-pulled-right"><fai class="has-text-danger" icon="minus-circle"></fai></div>
  </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM