将编辑和删除按钮放在卡片的右侧。

huangapple go评论65阅读模式
英文:

Position the edit & delete button on the right of card

问题

我想将编辑和删除按钮放在与图像和场所名称相同的行上。编辑和删除按钮应该在右边,并且大小应该与卡片的大小相同。现在看起来像这样:

将编辑和删除按钮放在卡片的右侧。

应该看起来像这样:

将编辑和删除按钮放在卡片的右侧。

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.card-content {
  display: flex;
  align-items: center;
  position: relative;
}

<!-- language: lang-html -->

&lt;!-- Bootstrap-5 --&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65&quot; crossorigin=&quot;anonymous&quot;&gt;


&lt;!-- Body --&gt;
&lt;div class=&quot;px-md-5 px-4&quot;&gt;
  &lt;a class=&quot;anchor-fake&quot; onclick=&quot;MovingIn()&quot;&gt;
    &lt;div class=&quot;block block--light block--cardShadow mb-md-4 mb-2&quot;&gt;
      &lt;div class=&quot;card-content&quot;&gt;
        &lt;div class=&quot;mr-3&quot;&gt;
          &lt;img src=&quot;~/assets/img/hmo-connectmyhome-home-icon.svg&quot; /&gt;
        &lt;/div&gt;
        &lt;div class=&quot;card-text-20-14-400&quot;&gt;
          @premise.PremiseNickname
        &lt;/div&gt;
        &lt;div class=&quot;btn-group ml-auto&quot;&gt; <!-- 添加 ml-auto -->
          &lt;input class=&quot;btn btn-secondary btn-lg&quot; type=&quot;button&quot; value=&quot;Edit&quot;&gt;
          &lt;input class=&quot;btn btn-danger btn-lg&quot; type=&quot;button&quot; value=&quot;Delete&quot;&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;

<!-- end snippet -->

英文:

I want to place the edit & delete buttons on the same line as the image & premise name. The edit & delete buttons should be on the right & size should be the same size as the card. It now looks like this:

将编辑和删除按钮放在卡片的右侧。

It should look like this:

将编辑和删除按钮放在卡片的右侧。

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.card-content {
  display: flex;
  align-items: center;
  position: relative;
}

<!-- language: lang-html -->

&lt;!-- Bootstrap-5 --&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65&quot; crossorigin=&quot;anonymous&quot;&gt;


&lt;!-- Body --&gt;
&lt;div class=&quot;px-md-5 px-4&quot;&gt;
  &lt;a class=&quot;anchor-fake&quot; onclick=&quot;MovingIn()&quot;&gt;
    &lt;div class=&quot;block block--light block--cardShadow mb-md-4 mb-2&quot;&gt;
      &lt;div class=&quot;card-content&quot;&gt;
        &lt;div class=&quot;mr-3&quot;&gt;
          &lt;img src=&quot;~/assets/img/hmo-connectmyhome-home-icon.svg&quot; /&gt;
        &lt;/div&gt;
        &lt;div class=&quot;card-text-20-14-400&quot;&gt;
          @premise.PremiseNickname
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;btn-group&quot;&gt;
        &lt;input class=&quot;btn btn-secondary btn-lg&quot; type=&quot;button&quot; value=&quot;Edit&quot;&gt;
        &lt;input class=&quot;btn btn-danger btn-lg&quot; type=&quot;button&quot; value=&quot;Delete&quot;&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 1

您只需将d-flex类添加到右侧容器即可。包裹按钮容器和其余内容的容器:

<div class="d-flex gap-3 block--light block--cardShadow mb-md-4 mb-2">

这将使右侧容器具有弹性布局。

英文:

You just need to add the class d-flex to the right container. The container that wraps both the buttons container and the rest:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;!-- Bootstrap-5 --&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65&quot; crossorigin=&quot;anonymous&quot;&gt;


&lt;!-- Body --&gt;
&lt;div class=&quot;px-md-5 px-4&quot;&gt;
  &lt;a class=&quot;anchor-fake&quot; onclick=&quot;MovingIn()&quot;&gt;
    &lt;div class=&quot;d-flex gap-3 block--light block--cardShadow mb-md-4 mb-2&quot;&gt;
      &lt;div class=&quot;card-content d-flex align-items-center&quot;&gt;
        &lt;div class=&quot;mr-3&quot;&gt;
          &lt;img src=&quot;~/assets/img/hmo-connectmyhome-home-icon.svg&quot; /&gt;
        &lt;/div&gt;
        &lt;div class=&quot;card-text-20-14-400&quot;&gt;
          @premise.PremiseNickname
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;btn-group&quot;&gt;
        &lt;input class=&quot;btn btn-secondary btn-lg&quot; type=&quot;button&quot; value=&quot;Edit&quot;&gt;
        &lt;input class=&quot;btn btn-danger btn-lg&quot; type=&quot;button&quot; value=&quot;Delete&quot;&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;

<!-- end snippet -->

答案2

得分: 0

&lt;!-- 开始片段:JS 隐藏:否 控制台:是 Babel:否 --&gt;

&lt;!-- 语言: lang-css --&gt;

    .card-content {
        display: flex;
        align-items: center;
    }

&lt;!-- 语言: lang-html --&gt;

    &lt;div class=&quot;px-md-5 px-4&quot;&gt;
      &lt;a class=&quot;anchor-fake&quot; onclick=&quot;MovingIn()&quot;&gt;
        &lt;div class=&quot;block block--light block--cardShadow mb-md-4 mb-2&quot;&gt;
          &lt;div class=&quot;card-content&quot;&gt;
            &lt;div class=&quot;mr-3&quot;&gt;
              &lt;img src=&quot;~/assets/img/hmo-connectmyhome-home-icon.svg&quot; /&gt;
            &lt;/div&gt;
            &lt;div class=&quot;card-text-20-14-400&quot;&gt;
              @premise.PremiseNickname
            &lt;/div&gt;
            &lt;div class=&quot;btn-group&quot;&gt;
              &lt;input class=&quot;btn btn-secondary btn-lg&quot; type=&quot;button&quot; value=&quot;Edit&quot;&gt;
              &lt;input class=&quot;btn btn-danger btn-lg&quot; type=&quot;button&quot; value=&quot;Delete&quot;&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;
    &lt;/div&gt;

&lt;!-- 结束片段 --&gt;
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.card-content {
    display: flex;
    align-items: center;
}

<!-- language: lang-html -->

&lt;div class=&quot;px-md-5 px-4&quot;&gt;
  &lt;a class=&quot;anchor-fake&quot; onclick=&quot;MovingIn()&quot;&gt;
    &lt;div class=&quot;block block--light block--cardShadow mb-md-4 mb-2&quot;&gt;
      &lt;div class=&quot;card-content&quot;&gt;
        &lt;div class=&quot;mr-3&quot;&gt;
          &lt;img src=&quot;~/assets/img/hmo-connectmyhome-home-icon.svg&quot; /&gt;
        &lt;/div&gt;
        &lt;div class=&quot;card-text-20-14-400&quot;&gt;
          @premise.PremiseNickname
        &lt;/div&gt;
        &lt;div class=&quot;btn-group&quot;&gt;
          &lt;input class=&quot;btn btn-secondary btn-lg&quot; type=&quot;button&quot; value=&quot;Edit&quot;&gt;
          &lt;input class=&quot;btn btn-danger btn-lg&quot; type=&quot;button&quot; value=&quot;Delete&quot;&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;

<!-- end snippet -->

答案3

得分: 0

将以下CSS应用于解决您的问题。

.card-content {
  display: flex;
  position: relative;
}

.card-content .btn-group {
  display: flex;
}

.card-content .btn-group &gt; * {
  flex-shrink: 0;
}

.card-text-20-14-400 {
  background: white;
  display: flex;
  align-items: center;
}

.card-content img {
  width: 50px;
}

.btn-secondary.btn-lg {
   border-radius: 0;
}
英文:

Apply the below CSS for solving your issue.

.card-content {
  display: flex;
  position: relative;
}

.card-content .btn-group {
  display: flex;
}

.card-content .btn-group &gt; * {
  flex-shrink: 0;
}

.card-text-20-14-400 {
  background: white;
  display: flex;
  align-items: center;
}

.card-content img {
  width: 50px;
}

.btn-secondary.btn-lg {
   border-radius: 0;
}

答案4

得分: 0

float-end 添加到 <div class="btn-group">

<div class="btn-group float-end">

文档链接:https://getbootstrap.com/docs/5.0/utilities/float/

英文:

add float-end to the &lt;div class=&quot;btn-group&quot;&gt;

&lt;div class=&quot;btn-group float-end&quot;&gt;

DOCs: https://getbootstrap.com/docs/5.0/utilities/float/

huangapple
  • 本文由 发表于 2023年4月4日 13:30:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925798.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定