Overflow: scroll not working in a specific column

2019-08-23 11:57发布

问题:

I have 3 columns in my main tag (<main role="main" class="container">). The first column has a table with many rows. I want that column to be vertically scrollable while staying stretched between the header and the footer. I added in my css :

#please-scroll{
  height: calc(100% - 110px); overflow-y: scroll
}

But it doesn't work.

Here is my code :

html {
  height: 100%;
  font-family: sans-serif;
  background: #1F1F1F !important; }

body {
  font-family: sans-serif;
  background-color: #1F1F1F;
  height: 100%; }

.container {
  min-height: calc(100% - 110px) !important;
  margin: 0 auto -33px;
  width: 100%; }

body > .container {
  padding: 60px 15px 0; }

.nav-item .nav-link span {
  border-radius: 10px;
  border: 2px solid;
  padding: 3px;
  font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;
  font-size: 12px; }

#please-scroll{
  height: calc(100% - 110px); overflow-y: scroll
}
<!DOCTYPE html>
<html lang="en">


<!-- Latest compiled and minified Bootstrap CSS -->
<head>
    <title>My Example</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
 
</head>
<body style="overflow-y:hidden;">
<header>
    <nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse fixed-top" style="border-bottom: 1px solid #353738">
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <a class="navbar-brand" href="#" data-placement="right" data-animation="false" data-toggle="tooltip" title="Aller à Mes Summaries">
            My Logo</a>


    </nav>
</header>

<!-- Begin page content -->

<main role="main" class="container" >
    <div class="row " style=" min-height: 100vh;">
        <div class="col-sm-12 col-md-3 " id="please-scroll" style="background: #292b2c; border-right: 1px solid #353738; ">
            <table style=" color: #636c72;">
                <thead>
                <tr>
                    <th>Firstname</th>
                    <th>Lastname</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>John</td>
                    <td>Doe</td>
                </tr>
                <tr>
                    <td>Mary</td>
                    <td>Moe</td>
                </tr>
                <tr>
                    <td>July</td>
                    <td>Dooley</td>
                </tr>
                <tr>
                    <td>John</td>
                    <td>Doe</td>
                </tr>
                <tr>
                    <td>Mary</td>
                    <td>Moe</td>
                </tr>
                <tr>
                    <td>July</td>
                    <td>Dooley</td>
                </tr>  <tr>
                    <td>John</td>
                    <td>Doe</td>
                </tr>
                <tr>
                    <td>Mary</td>
                    <td>Moe</td>
                </tr>
                <tr>
                    <td>July</td>
                    <td>Dooley</td>
                </tr>  <tr>
                    <td>John</td>
                    <td>Doe</td>
                </tr>
                <tr>
                    <td>Mary</td>
                    <td>Moe</td>
                </tr>
                <tr>
                    <td>July</td>
                    <td>Dooley</td>
                </tr>  <tr>
                    <td>John</td>
                    <td>Doe</td>
                </tr>
                <tr>
                    <td>Mary</td>
                    <td>Moe</td>
                </tr>
                <tr>
                    <td>July</td>
                    <td>Dooley</td>
                </tr>  <tr>
                    <td>John</td>
                    <td>Doe</td>
                </tr>
                <tr>
                    <td>Mary</td>
                    <td>Moe</td>
                </tr>
                <tr>
                    <td>July</td>
                    <td>Dooley</td>
                </tr>  <tr>
                    <td>John</td>
                    <td>Doe</td>
                </tr>
                <tr>
                    <td>Mary</td>
                    <td>Moe</td>
                </tr>
                <tr>
                    <td>July</td>
                    <td>Dooley12</td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="col-sm-12 col-md-5" style=" min-height: 100vh;">col</div>
        <div class="col-sm-12 col-md-4" style=" min-height: 100vh;">col</div>
    </div>
</main>

<footer style="">

    <nav class="navbar navbar-toggleable-md navbar-inverse fixed-bottom bg-inverse" style="height: 10%; border-top: 1px solid #353738 ">

    </nav>
</footer>


<!-- jQuery library -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script><!-- Initialize Bootstrap functionality -->
<script>
    // Initialize tooltip component
    $(function () {
        $('[data-toggle="tooltip"]').tooltip()
    })

    // Initialize popover component
    $(function () {
        $('[data-toggle="popover"]').popover()
    })
</script>
</body>
</html>

Please help!

回答1:

Try replacing CSS for #please-scroll::

#please-scroll{
  height: calc(100vh - 110px);
  overflow-y: scroll;
}