我有一个.showGuess块,它的最大高度设置为100px.当它的高度超过其最大值时,我希望出现一个垂直滚动条.但是,不幸的是,由于某种原因,我从来没有得到滚动条.

How to make the scrollbar to appear?

以下是代码和结果:https://liveweave.com/hyo1ut

超文本标记语言

<!DOCTYPE html>
<form class="order-form" method="POST" action="insert_data.php">
                <legend>Insert your address</legend>
                
                <div class="input-area-wrap">
                    <div class="input-area">
                        <label>street/avenue</label>
                        <input type="text" name="street" required>
                    </div>
                    <div class="showGuesses">
                        <div class="showGuess">Street 1</div>
                        <div class="showGuess">Street 2</div>
                        <div class="showGuess">Street 3</div>
                        <div class="showGuess">Street 4</div>
                    </div>
                </div>
</form>

CSS

* {
  -webkit-box-sizing: border-box!important;
            box-sizing: border-box!important;
}
.order-form {
     display: -webkit-box;
     display: -ms-flexbox;
     display: flex;
     -webkit-box-orient: vertical;
     -webkit-box-direction: normal;
         -ms-flex-direction: column;
             flex-direction: column;
    width: 80%;
    max-width: 800px;
    margin: 0 auto;
    border: 1px solid #222;
    border-radius: 15px;
    padding: 20px;
    margin-top: 25px;
    position: unset!important;
    overflow: hidden;
}
legend {
    text-align: center;
    margin-bottom: 25px!important;
}
.input-area-wrap {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
        -ms-flex-direction: column;
            flex-direction: column;
}
.input-area {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: baseline;
        -ms-flex-align: baseline;
            align-items: baseline;
    position: relative;
}
.input-area label {
    width: 150px;
}
input[type="text"] {
    width: 250px!important;
    outline: none;
}
input[type="text"]:focus {
    border: 2px solid darkred!important;
    outline: none;
}
input[type="submit"] {
    width: 100px;
    margin: 25px auto 0;
    border-radius: 25px;
    background: rgb(255, 74, 74);
    color: #fff;
    border: none;
    padding: 10px;
    font-size: 16px;
}
.showGuesses {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
        -ms-flex-direction: column;
            flex-direction: column;
    z-index: 3;
    /* top: 25px; */
    margin-left: 150px;
    font-size: 14px;
    width: 100%;
    max-height: 100px;
    overflow: -moz-scrollbars-vertical; 
    overflow-y: scroll;
}
.showGuess {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: center;
        -ms-flex-pack: center;
            justify-content: center;
    -webkit-box-align: center;
        -ms-flex-align: center;
            align-items: center;
    border: 1px solid #222;
    padding: 5px;
    width: 250px;
    min-height: 45px;
    text-align: center;
    background: #fff;
    border-bottom: none;
}

UPD 0:

由于@EssXTee的帮助,我现在得到了滚动条,但如果showGuess块的内容不溢出它,它不会消失.出于某种原因,它一直都在那里.

How to fix that?

推荐答案

只是张贴这个答案,这样就有了官方的解决方案.

滚动条确实出现了,但似乎在屏幕上太靠右了,看不到.这是因为.showGuesses类的宽度为.showGuesses%,但左边距为150像素.这使得.showGuessesdiv的大小与父级相同,但向右移动了150像素.这是滚动条所在的位置.

因此,简单地减少.showGuesses类的宽度就可以解决这个问题.至于将宽度设置为什么,我想这是您希望滚动条显示的首选位置.

EDIT 只要滚动条始终可见,请使用overflow-y: auto;,而不是将其设置为scroll,后者将始终显示滚动条.使用auto仅在需要时显示滚动条.

Html相关问答推荐

角|将动态html属性添加到子组件

值更新时旋转数字动画

如何将值从Google Sheets侧边栏中的表单中的输入传递到Google Sheets单元格中使用Textile()

在Apps Script中连接CSS与HTML

如何找到FontAwese图标的Unicode值?

当在双引号|Angular .html文件中使用时,Pretier会将单引号字符替换为&;Quot;

如何使用css为动态用户输入矩阵添加背景色?

如何设置弹性盒子容器的具体大小?

你将如何为手机制作导航栏

浏览器是否可以呈现存储在代码点0x09处的字形?

使用bash从html表格中提取表格

如何设计缠绕锚点元素的样式?

在屏幕上每行 css 中的特定列居中

伪元素:after和溢出隐藏

并排放置两个 div,同时 div2 环绕 div1

图像如何能达到 HTML 表格的全宽?

发送带有图像的Google文档作为HTML格式的邮件正文不再起作用

有没有办法在 Flutter 中创建这个浮动标签表单?

flex-box 中的图像在 Chrome 和 Firefox 中看起来不同 - 如何使它们在 Firefox 中看起来像?

在中心而不是边界处填充 svg 的背景