css - 使用 CSS 和 bootstrap 在 blazor 上实现具有重叠 div 的灵活宽度

标签 css bootstrap-4 blazor

我的 UI 上有一手牌,我想允许容纳比 div 上实际容纳的更多的牌,必要时让它们重叠。

我的卡片使用 blazor 链接到数组,如下所示:

<div class="PlayersHand d-flex flex-row justify-content-center">
    @foreach(var card in Client.Game.Me.CardsInHand)
    {
        <CardViewer Card=card IsHandCard=true />
    }
</div>

我的卡片排列正确。但是,当太多时,溢出就会通过隐藏、滚动条或其他设置来启动。我不希望这种事发生。我希望我的卡片尽可能多地重叠,以适应空间。

这将是预期的行为:

enter image description here

最佳答案

检查下面的代码片段

:root {
  /*Variables,remove needed*/
  --bg-one: #973999;
  --bg-two: #f8598b;
  --bg-three: #f7bf00;
  --bg-panel: #ebebeb;
  --color-text: #999;
  --distance: 4rem;
  --height: 150px; /*OR Auto*/
  --width: 100px; /*OR Auto*/
}

body {
  /*You may remove this rule*/
  background-image: linear-gradient(
    to bottom right,
    var(--bg-one),
    var(--bg-two),
    var(--bg-three)
  );
  height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  margin: 0;
}

.cards {
  display: flex; /*MAIN*/
}

.card {
  z-index: 1; /*MAIN*/
  background: var(--bg-panel); /*MAIN*/
  height: var(--height);
  max-width: var(--width);

  /*Styles(You may remove)*/
  border-radius: 1rem;
  padding: 2rem;
  box-shadow: 4px 4px 12px 2px rgba(0, 0, 0, 0.6);
}
.card p {
  /*You may remove this rule*/
  color: var(--color-text);
}

.card:not(:first-child) {
  margin-left: calc(var(--distance) * -1); /*MAIN*/
}
<div class="cards">
  <div class="card">

    <p>This is an article and this has some content.</p>
  </div>
  <div class="card">

    <p>This is an article and this has some content.</p>
  </div>
  <div class="card">

    <p>This is an article and this has some content.</p>
  </div>
  <div class="card">

    <p>This is an article and this has some content.</p>
  </div>
  <div class="card">

    <p>This is an article and this has some content.</p>
  </div>
  <div class="card">

    <p>This is an article and this has some content.</p>
  </div>
</div>

想法来自here

我已经编辑了上面链接中的代码,我不知道blazor,但我认为这会对你有所帮助,我已经评论了我的大部分代码。

关于css - 使用 CSS 和 bootstrap 在 blazor 上实现具有重叠 div 的灵活宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71857731/

相关文章:

twitter-bootstrap - 单击 Bootstrap 4 折叠时旋转 SVG 图像

html - 如何在文本区域内放置一个 float 按钮?

html - 与表单控件类相关的类在 bootstrap 4 中无法正常运行

javascript - Bootstrap 4 sticky-top 更改导航栏颜色

css - Bootstrap 3 中的左对齐按钮

javascript - 单击一个 div 使另一个 div 出现/消失

javascript - 如何更改每个表单组中的按钮

c# - 从 Blazor 基类中的应用设置获取值

c# - 如何添加 Razor 背景图片

asp.net - Blazor 性能