仅在溢出时启用滚动条

时间:2019-11-20 10:08:52

标签: php html css google-chrome mozilla

在我的代码中,我使用overflow-y: scroll启用滚动条,并且我将最大高度设置为40px。 在chrome浏览器中,它运作良好,并且只有在发生溢出时(即,文本长度超过2行),滚动条才可见。 但是在firefox Web浏览器中,垂直滚动条始终可见,我的要求是垂直滚动条仅在溢出发生或超过40px高度时才可见。

<div class="message-main-ok-text has-warning" style="max-height:40px;overflow-x:hidden;overflow-y:scroll;">

请帮助我

2 个答案:

答案 0 :(得分:0)

尝试此操作,将scroll更改为auto

overflow-y:auto

答案 1 :(得分:0)

<!DOCTYPE html>
<html>
<head>
<style>


</style>
</head>
<body>
<div class="message-main-ok-text has-warning" style="height: 110px;
  overflow: auto;">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibhLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibhLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibhLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibhLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibhLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibhLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibhLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibheuismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</div>


</body>
</html>