我有一个在Bootstrap中设计的页面,并使用滚动条处理我的元素的溢出. 我使用的按钮被设计成有圆角,但当页面上有足够多的元素溢出到滚动条中时,圆角就消失了,而我所有的其他样式元素都保留了下来,按钮变成了乏味的矩形.这只是一个overflow-y: scroll的属性,还是我可以避免?以下是我的HTML:

       <div class="container px-4 px-lg-5 d-flex h-100 align-items-center justify-content-center">
            <div class="d-flex justify-content-center">
                <div class="text-center">
                    <h6 class="text-white-50 mb-2 mx-auto">Your Ordered Playlist:</h6>
                    
                    <div class="scrol">
                    {%for i in rankings%}
                        <div class="row">
                        
                    <input autocomplete="off" value="{{i}}" class="btn btn-primary mt-3 text-wrap" name="playlist"/>
                        </div>
                    {%endfor%}
                    
                    </div>
                </div>

            </div>
        </div>

和我的相关css:

.scrol {
   height: 400px;
   overflow-y: scroll;
 }

 .align-items-center {
   align-items: center !important;
}

.justify-content-center {
  justify-content: center !important;
}

.btn {
    --bs-btn-padding-x: 0.75rem;
    --bs-btn-padding-y: 0.375rem;
    --bs-btn-font-family: ;
    --bs-btn-font-size: 1rem;
    --bs-btn-font-weight: 400;
    --bs-btn-line-height: 1.5;
    --bs-btn-color: #212529;
    --bs-btn-bg: transparent;
    --bs-btn-border-width: 1px;
    --bs-btn-border-color: transparent;
    --bs-btn-border-radius: 0.375rem;
    --bs-btn-hover-border-color: transparent;
    --bs-btn-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 1px rgba(0, 0, 0, 0.075);
    --bs-btn-disabled-opacity: 0.65;
    --bs-btn-focus-box-shadow: 0 0 0 0.25rem rgba(var(--bs-btn-focus-shadow-rgb), .5);
    display: inline-block;
    padding: var(--bs-btn-padding-y) var(--bs-btn-padding-x);
    font-family: var(--bs-btn-font-family);
    font-size: var(--bs-btn-font-size);
    font-weight: var(--bs-btn-font-weight);
    line-height: var(--bs-btn-line-height);
    color: var(--bs-btn-color);
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    -webkit-user-select: none;
      -moz-user-select: none;
            user-select: none;
    border: var(--bs-btn-border-width) solid var(--bs-btn-border-color);
    border-radius: var(--bs-btn-border-radius);
    background-color: var(--bs-btn-bg);
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  }

.btn-primary {
  --bs-btn-color: #fff;
  --bs-btn-bg: #64a19d;
  --bs-btn-border-color: #64a19d;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #558985;
  --bs-btn-hover-border-color: #50817e;
  --bs-btn-focus-shadow-rgb: 123, 175, 172;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #50817e;
  --bs-btn-active-border-color: #4b7976;
  --bs-btn-active-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: #64a19d;
  --bs-btn-disabled-border-color: #64a19d;
}

我已经调整了按钮的宽度,并try 了overflow的不同方法.我也完全取消了滚动,因为我的按钮在我这样做的时候看起来很正常,但我不喜欢它在页面上占据的空间,所以我排除了这一选项.

推荐答案

按钮半径和样式仍然存在,但不可见,因为row的负边距,所以将container类添加到scrol容器中以抵消它,因为类row必须是container的子级(也可能更好地使用overflow-y: auto).

  <div class="container scrol">
    <div class="row">

original code:

  <div class="container scrol">
    {%for i in rankings%}
        <div class="row">
            <input autocomplete="off" value="{{i}}" class="btn btn-primary mt-3 text-wrap" name="playlist"/>
        </div>
    {%endfor%}

Note: as content should then go in 100, so maybe wrap 101s into a 100 container, to make sure there are no further style side effects.

或者,根据您的布局,您可以从scrol个子容器中删除row个类,将其移动到某个父容器上,例如container后面的那个,然后您可以使用col作为断点:

<div class="container px-4 px-lg-5 d-flex h-100 align-items-center justify-content-center">
    <div class="row d-flex justify-content-center">
        <div class="text-center">
            <h6 class="text-white-50 mb-2 mx-auto">Your Ordered Playlist:</h6>
            <div class="scrol">
                <div class="">

文档:

Rows are wrappers for columns.每列有水平填充 (称为排水沟)用于控制它们之间的空间.这种填充 然后在具有负边距的行上抵消,以确保 列中的内容在视觉上是向左对齐的.

Grid system

演示(将container加到scrol):

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>


<style>
  .scrol {
    height: 400px;
    overflow-y: auto;
  }
  
  .align-items-center {
    align-items: center !important;
  }
  
  .justify-content-center {
    justify-content: center !important;
  }
  
  .btn {
    --bs-btn-padding-x: 0.75rem;
    --bs-btn-padding-y: 0.375rem;
    --bs-btn-font-family: ;
    --bs-btn-font-size: 1rem;
    --bs-btn-font-weight: 400;
    --bs-btn-line-height: 1.5;
    --bs-btn-color: #212529;
    --bs-btn-bg: transparent;
    --bs-btn-border-width: 1px;
    --bs-btn-border-color: transparent;
    --bs-btn-border-radius: 0.375rem;
    --bs-btn-hover-border-color: transparent;
    --bs-btn-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 1px rgba(0, 0, 0, 0.075);
    --bs-btn-disabled-opacity: 0.65;
    --bs-btn-focus-box-shadow: 0 0 0 0.25rem rgba(var(--bs-btn-focus-shadow-rgb), .5);
    display: inline-block;
    padding: var(--bs-btn-padding-y) var(--bs-btn-padding-x);
    font-family: var(--bs-btn-font-family);
    font-size: var(--bs-btn-font-size);
    font-weight: var(--bs-btn-font-weight);
    line-height: var(--bs-btn-line-height);
    color: var(--bs-btn-color);
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    border: var(--bs-btn-border-width) solid var(--bs-btn-border-color);
    border-radius: var(--bs-btn-border-radius);
    background-color: var(--bs-btn-bg);
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  }
  
  .btn-primary {
    --bs-btn-color: #fff;
    --bs-btn-bg: #64a19d;
    --bs-btn-border-color: #64a19d;
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: #558985;
    --bs-btn-hover-border-color: #50817e;
    --bs-btn-focus-shadow-rgb: 123, 175, 172;
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: #50817e;
    --bs-btn-active-border-color: #4b7976;
    --bs-btn-active-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: #64a19d;
    --bs-btn-disabled-border-color: #64a19d;
  }
</style>





<div class="container px-4 px-lg-5 d-flex h-100 align-items-center justify-content-center">
  <div class="d-flex justify-content-center">
    <div class="text-center">
      <h6 class="text-white-50 mb-2 mx-auto">Your Ordered Playlist:</h6>

      <div class="container scrol">

        <div class="row">

          <input autocomplete="off" value="{{i}}" class="btn btn-primary mt-3 text-wrap" name="playlist" />
        </div>

        <div class="row">

          <input autocomplete="off" value="{{i}}" class="btn btn-primary mt-3 text-wrap" name="playlist" />
        </div>

        <div class="row">

          <input autocomplete="off" value="{{i}}" class="btn btn-primary mt-3 text-wrap" name="playlist" />
        </div>

        <div class="row">

          <input autocomplete="off" value="{{i}}" class="btn btn-primary mt-3 text-wrap" name="playlist" />
        </div>
        <div class="row">

          <input autocomplete="off" value="{{i}}" class="btn btn-primary mt-3 text-wrap" name="playlist" />
        </div>

        <div class="row">

          <input autocomplete="off" value="{{i}}" class="btn btn-primary mt-3 text-wrap" name="playlist" />
        </div>

        <div class="row">

          <input autocomplete="off" value="{{i}}" class="btn btn-primary mt-3 text-wrap" name="playlist" />
        </div>

        <div class="row">

          <input autocomplete="off" value="{{i}}" class="btn btn-primary mt-3 text-wrap" name="playlist" />
        </div>
      </div>
    </div>

  </div>
</div>

Html相关问答推荐

网格容器中的定心元件

试图让三个Divs与下面的另外三个对齐

应用于文本而不是弹性容器的Flexbox属性

输入宽度在表格显示上不起作用FLEX溢出隐藏Firefox

通过POST方法提交html表单时CSV文件无法通过(在使用Django的上下文中)

如何在元素的三条边中间换行边框?

用于删除页面页眉上的超链接的CSS

如何使用html和css关键帧创建动画

未在抖动中播放的HTML音频||文本正在工作其他标记正在播放,但音频未播放

如何在页面太短时使<;img&>缩小而不发生y溢出

使用CSS和Slick Carcass使图像适合屏幕

如何 Select 表格';TMS Web Core中的body html元素?

30000ms后超时重试:期望找到元素:someElement,但从未找到它

MUI 日期 Select 器要包含的日期

如何为卡片块制作侧丝带样式

四开将一个 qmd 文档中的单词链接到另一个 qmd 文档中的单词

为 HTML5 文本字段设置最后六位正则表达式模式

如何将背景与之前的内容正确对齐

svg 内容超过元素

无法在 css 的 body 标签中正确呈现(内联显示)