Bootstrap 4 Flexbox水平滚动卡片不适用于少于8张卡片。

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

Bootstrap 4 Flexbox Horizontal Scrolling Cards NOT working with less then 8 cards

问题

以下是您要翻译的内容:

Issue # 1: Unless there are a minimum of 8 cards, the cards are not filling the horizontal flexbox 'visible' window properly.
问题1:除非至少有8张卡片,否则卡片不会正确地填充水平伸缩框的“可见”窗口。

Issue 2: if the content in the card pushes the Button, how can I fill it with space, so that the buttons are in line?
问题2:如果卡片中的内容推动按钮,如何填充它以使按钮在一行中?

@CBroe you gave the cue, i added .row { width:100%; max-width:100vw; }
@CBroe,您给了提示,我添加了.row { width:100%; max-width:100vw; }

英文:

Having an issue with Bootstrap 4 flexbox in creating horizontally scrollable cards on Desktop Screens ( works okay on mobile responsive mode):

Issue # 1: Unless there are a minimum of 8 cards, the cards are not filling the horizontal flexbox 'visible' window properly
<br>Case A: 3 cards, the flexbox window is totally skewed and the 'badge' from below bills in there.
<br> Case B: 7 cards, flexbox is almost filled, but there is a gap on left side. <br> Case C: 8 cards, all perfect , visible & scrolling perfectly.

Issue 2: if the content in the card pushes the Button, how can I fill it with space, so that the buttons are in line?

@CBroe you gave the cue, i added .row { width:100%; max-width:100vw; }

and now it is working as expected , updating the

Bootstrap 4 Flexbox水平滚动卡片不适用于少于8张卡片。

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

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

body {
  padding: 5px;
}

img {
  border-radius: 50%;
  -webkit-filter: grayscale(100%);
  /* Safari 6.0 - 9.0 */
  filter: grayscale(100%);
  margin-top: 5px;
}

.forlabel {
  margin-top: -14px;
}

.forlabeldiv {
  border: solid;
  border-width: 1px;
  border-radius: 5px;
  &lt;!-- margin-left: 5px;
  margin-right: 5px;
  margin-bottom: 15px;
  --&gt;margin: 0, auto;
  width: 100%;
  text-align: center;
}

.forlabelspan {
  color: #0275d8;
  background: white;
  font-size: 14px;
  font-weight: 800;
}

.btn {
  width: 30%;
  text-align: center margin-bottom:5px
}

.card-block {
  min-height: 20vh;
  min-width: 25vw;
  margin-bottom: 15px;
}

.profile,
.card {
  background: #ced7df!important;
  text-align: center;
}

.master {
  text-align: center;
  margin: 0, auto;
  font-size: 0.75em;
}

.card {
  height: 100%;
}

.row {
  width: 100%;
  max-width: 100vw;
}

.badge {
  width: 10rem;
  flex: 1 0 auto;
  font-size: 1em;
  font-weight: 300;
}

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

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;title&gt;Single Row Horizontal Scrolling Cards&lt;/title&gt;
&lt;meta charset=&quot;utf-8&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;!----------------------xxxxxxx----------------------------&gt;
&lt;h2&gt;Case A: Horizontal Scrolling Cards with 3 cards&lt;/h2&gt;
&lt;div class=&quot;container-fluid p-3 m-3 master&quot;&gt;
&lt;div class=&quot;container forlabeldiv row  max-auto&quot;&gt;
&lt;label for=&quot;input1&quot; class=&quot;col-sm-12 forlabel&quot;&gt;
&lt;span class=&quot; forlabelspan&quot;&gt;Expert Panel&lt;/span&gt; 
&lt;/label&gt;
&lt;div class=&quot;row flex-nowrap overflow-auto &quot;&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/100/09f/fff.png&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt; 1 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;2 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt; First Name Last Name&lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;3 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!--*** end of row flex  *** --&gt;
&lt;div class=&quot;badge badge-secondary text-wrap text-center&quot;&gt;
&lt;i class=&quot;fa-solid fa-arrow-left&quot;&gt;&lt;/i&gt; Swipe for More &lt;i class=&quot;fa-solid fa-arrow-right&quot;&gt;&lt;/i&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!--*** end of label div  *** --&gt;
&lt;/div&gt;
&lt;!--*** end of container-flex --&gt;
&lt;!----------------------xxxxxxx----------------------------&gt;
&lt;!----------------------xxxxxxx----------------------------&gt;
&lt;h2&gt;Case B: Horizontal Scrolling Cards with 7 cards &lt;/h2&gt;
&lt;div class=&quot;container-fluid p-3 m-3 master&quot;&gt;
&lt;div class=&quot;container forlabeldiv row  max-auto&quot;&gt;
&lt;label for=&quot;input1&quot; class=&quot;col-sm-12 forlabel&quot;&gt;
&lt;span class=&quot; forlabelspan&quot;&gt;Expert Panel&lt;/span&gt; 
&lt;/label&gt;
&lt;div class=&quot;row flex-nowrap overflow-auto&quot;&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/100/09f/fff.png&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt; 1 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;2 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt; First Name Last Name&lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;3 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;4 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;5 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;6 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;7 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!--*** end of row flex  *** --&gt;
&lt;div class=&quot;badge badge-secondary text-wrap text-center&quot;&gt;
&lt;i class=&quot;fa-solid fa-arrow-left&quot;&gt;&lt;/i&gt; Swipe for More &lt;i class=&quot;fa-solid fa-arrow-right&quot;&gt;&lt;/i&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!--*** end of label div  *** --&gt;
&lt;/div&gt;
&lt;!--*** end of container-flex --&gt;
&lt;!----------------------xxxxxxx----------------------------&gt;
&lt;!----------------------xxxxxxx----------------------------&gt;
&lt;h2&gt; Case C: Horizontal Scrolling Cards with 8 cards&lt;/h2&gt;
&lt;div class=&quot;container-fluid p-3 m-3 master&quot;&gt;
&lt;div class=&quot;container forlabeldiv row  max-auto&quot;&gt;
&lt;label for=&quot;input1&quot; class=&quot;col-sm-12 forlabel&quot;&gt;
&lt;span class=&quot; forlabelspan&quot;&gt;Expert Panel&lt;/span&gt; 
&lt;/label&gt;
&lt;div class=&quot;row flex-nowrap overflow-auto&quot;&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/100/09f/fff.png&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt; 1 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;2 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt; First Name Last Name&lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;3 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;4 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;5 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;6 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;7 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-12 col-lg-3 mb-3&quot;&gt;
&lt;div class=&quot;card card-block profile h-100 d-flex flex-auto&quot;&gt;
&lt;img class=&quot;mx-auto&quot; src=&quot;https://via.placeholder.com/150&quot; width=&quot;100&quot; height=&quot;100&quot;&gt; First Name Last Name&lt;br&gt;8 &lt;br&gt; Title of Person&lt;br&gt; Credentials of Person&lt;br&gt;
&lt;a href=&quot;#&quot; class=&quot;btn btn-danger mx-auto mt-auto&quot;&gt;BOOK&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!--*** end of row flex  *** --&gt;
&lt;div class=&quot;badge badge-secondary text-wrap text-center&quot;&gt;
&lt;i class=&quot;fa-solid fa-arrow-left&quot;&gt;&lt;/i&gt; Swipe for More &lt;i class=&quot;fa-solid fa-arrow-right&quot;&gt;&lt;/i&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!--*** end of label div  *** --&gt;
&lt;/div&gt;
&lt;!--*** end of container-flex --&gt;
&lt;!----------------------xxxxxxx----------------------------&gt;
&lt;/body&gt;
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js&quot; integrity=&quot;sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ==&quot; crossorigin=&quot;anonymous&quot; referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js&quot;&gt;&lt;/script&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css&quot;&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js&quot;&gt;&lt;/script&gt;

<!-- end snippet -->

答案1

得分: 1

使用专家的建议,解决了以下问题:

  1. 添加了.row { width:100%; max-width:100vw; }以确保即使有3张卡片,flex-box的宽度也不会缩小。
  2. 添加了d-flex flex-auto到卡片和mt-auto以确保按钮出现在同一行。

谢谢。

英文:

Using cues from experts here, resolved the issues:

  1. Added .row { width:100%; max-width:100vw; } to ensure even with 3 cards the width of the flex-box doesn't shrink.
  2. Added d-flex flex-auto to card & mt-auto to ensure buttons appear in same line

Thank you

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

发表评论

匿名网友

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

确定