将页面高度设置为滚动-当外部div隐藏时-内部div滚动

时间:2018-11-22 08:50:42

标签: html css

我有一个div,其中包含选项卡窗格。第一个选项卡窗格包含两个内部div。 第一个内部div有一个搜索文本框,我想将其保留在固定位置,而我希望第二个内部div启用滚动。可行的代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
    <!-- View meta tag -->
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>

    <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
    <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>    
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/themes/default/style.min.css" />

<style type="text/css">

body, html {
  height: 100%;
  min-height: 100%;
  font-size: 100%
  }

html, body {overflow:hidden;}

body {
  padding-bottom: 16%;
}

.navbar {
  margin-bottom: 0;

}
.container {
  width:100%;
  height:100%;
}

.sidebar {
  width:25%;
  float:left;
  height:100%;
  border-right: solid 0.150em #f1ded9;
  overflow-x: auto; 
}

.center {
  background-color: white;
  float:left;
  border-right: solid 0.150em #f1ded9;
  width:55%;
  height:100%;
}

.rhsbar {
  background-color: white;
  float:left;
  margin:0 0 0 0;
  position:relative;
  width:20%;
  height:100%;
  border-left: solid 0.278em #f1ded9;
  overflow: auto;
}

#loaded_img_panel {
  border-top: solid 0.278em #f1ded9;
  display:flex;
  flex-wrap: nowrap;
  overflow-x:auto;
  padding: 0.556em 0 0 0;

}

.rhsbar .tab {
    overflow-y: auto;
    border: 0.056em solid #ccc;
    background-color: #f1f1f1;
}

</style>

</head>

<body>
 <nav class="navbar navbar-default">
  <div class="container-fluid">
  </div>
</nav>

<div class="container">
  <div class="sidebar">
  </div>

<div id="center" class="center">
  <canvas id="imagecanvas" style="position:absolute;margin:0 0 0 0;z-index:1"></canvas>
  <canvas id="regncanvas" tabindex='1' style="position:absolute;margin:0 0 0 0;z-index:2"></canvas>
</div>

<div class="rhsbar" style="overflow:hidden;display:flex;flex-direction:column;">
  <div class="row" >
            <div class="col-md-12">
            <div class="card">
            <ul class="nav nav-tabs" role="tablist" id="annTabs">
                <li role="presentation"  style="font-size:80%" class="active"><a href="#annTree" aria-controls="annTree" role="tab" data-toggle="tab" >Ann</a></li>
                <li role="presentation" style="font-size:80%"><a href="#batchProcess"  aria-controls="batchProcess" role="tab" data-toggle="tab">Bat</a></li>
            </ul>
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active"  id="annTree">
                  <input id="annDirSearch" type="text" placeholder="Search">
                  <div id="annotateDirectories" style="flex:1;overflow-y:scroll; max-height:520px;" >
                    <ul>
                      <li>Test1</li>
                      <li>Test2</li>
                      <li>Test3</li>
                      <li>Test4</li>
                      <li>Test5</li>
                      <li>Test6</li>
                      <li>Test7</li>
                      <li>Test8</li>
                      <li>Test9</li>
                      <li>Test1</li>
                      <li>Test2</li>
                      <li>Test3</li>
                      <li>Test4</li>
                      <li>Test5</li>
                      <li>Test6</li>
                      <li>Test7</li>
                      <li>Test8</li>
                      <li>Test9</li>
                      <li>Test1</li>
                      <li>Test2</li>
                      <li>Test3</li>
                      <li>Test4</li>
                      <li>Test5</li>
                      <li>Test6</li>
                      <li>Test7</li>
                      <li>Test8</li>
                      <li>Test9</li>
                      <li>Test1</li>
                      <li>Test2</li>
                      <li>Test3</li>
                      <li>Test4</li>
                      <li>Test5</li>
                      <li>Test6</li>
                      <li>Test7</li>
                      <li>Test8</li>
                      <li>Test9</li>

                    </ul>
                  </div>
                </div>
                <div role="tabpanel" class="tab-pane" id="batchProcess" style="overflow-y:scroll; max-height:540px;">
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>

<div id="loaded_img_panel" name="loaded_img_panel" class="loaded_img_panel">             
</div>

</body>
</html>

这有效。但是,由于第二个内部div设置为520px(适用于我的笔记本电脑),所以当我在较大的屏幕上打开页面时,滚动窗口的高度在较小的屏幕上看起来很小,因此无法滚动。

我尝试使用100%将第二个内部div的高度设置为100vhflexdirection as column。他们都没有帮助。

2 个答案:

答案 0 :(得分:0)

要设置尺寸以适合不同的屏幕尺寸,必须使用@media规则。 请参阅此页面以了解它们是什么:https://www.w3schools.com/cssref/css3_pr_mediaquery.asp

答案 1 :(得分:0)

也尝试在元标记中指定设备高度:

此:

<meta name="viewport" content="width=device-width, initial-scale=1">

成为这个:

<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1">

.sidebar {
  /* height:100%; - remove */
     min-height:100vh; /* - add */
}