将Bootstrap 5卡片延伸至屏幕底部会超出屏幕。

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

Extending Bootstrap 5 card to bottom of screen goes off screen

问题

I'm using BS 5 (latest) and have set up a two column page. In the right column, I added a card which I want to extend to the bottom of the page.

There is padding at the top and bottom of the card.

I added vh-100 to the card but the issue is that the card goes past the bottom of the screen, causing the scrollbar to appear. If the padding is removed, it works, but the top and bottom borders of the card are not visible.

<div class="container-fluid mt-2">
  <div class="row">
    <div class="col-2">
      Menu system
    </div>
    <div class="col-10">
      <div class="card vh-100 mb-3">
        <div class="card-body">
          main content area
        </div>
      </div>
    </div>
  </div>
</div>

JSFiddle

How can I make the card take up the entire space minus the padding constraints?

英文:

I'm using BS 5 (latest) and have set up a two column page. In the right column, I added a card which I want to extend to the bottom of page.

There is padding at the top and bottom of the card.

I added vh-100 to the card but the issue is that the card goes past the bottom of the screen, causing the scrollbar to appear. If the padding is removed, it works, but the top and bottom borders of the card are not visible.

&lt;div class=&quot;container-fluid mt-2&quot;&gt;
  &lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;col-2&quot;&gt;
      Menu system
    &lt;/div&gt;
    &lt;div class=&quot;col-10&quot;&gt;
      &lt;div class=&quot;card vh-100 mb-3&quot;&gt;
        &lt;div class=&quot;card-body&quot;&gt;
          main content area
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

JSFiddle

How can I make the card take up the entire space minus the padding constraints?

答案1

得分: 0

以下是翻译好的内容:

.card {
  height: calc(100vh - 1rem - 0.5rem) !important;
}

height 设置为全屏高度,减去所有内边距和/或外边距。

在下面的片段中查看示例。

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

<!-- language: lang-css -->
.card {
  height: calc(100vh - 1rem - 0.5rem) !important;
}

<!-- language: lang-html -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous">

<div class="container-fluid mt-2">
  <div class="row">
    <div class="col-2">
      菜单系统
    </div>
    <div class="col-10">
      <div class="card mb-3">
        <div class="card-body">
          主内容区域
        </div>
      </div>
    </div>
  </div>
</div>

<!-- end snippet -->

编辑

将Bootstrap 5卡片延伸至屏幕底部会超出屏幕。

将Bootstrap 5卡片延伸至屏幕底部会超出屏幕。

英文:

Add the following CSS:

.card {
  height: calc(100vh - 1rem - 0.5rem) !important;
}

Set height to full-screen height, minus all the paddings and/or margins.

See the snippet below.

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

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

.card {
  height: calc(100vh - 1rem - 0.5rem) !important;
}

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

&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD&quot; crossorigin=&quot;anonymous&quot;&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js&quot; integrity=&quot;sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;

&lt;div class=&quot;container-fluid mt-2&quot;&gt;
  &lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;col-2&quot;&gt;
      Menu system
    &lt;/div&gt;
    &lt;div class=&quot;col-10&quot;&gt;
      &lt;div class=&quot;card mb-3&quot;&gt;
        &lt;div class=&quot;card-body&quot;&gt;
          main content area
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->


EDIT

将Bootstrap 5卡片延伸至屏幕底部会超出屏幕。

将Bootstrap 5卡片延伸至屏幕底部会超出屏幕。

huangapple
  • 本文由 发表于 2023年2月24日 05:46:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75550645.html
匿名

发表评论

匿名网友

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

确定