Bootstrap折叠在折叠时显示子元素

时间:2018-09-10 20:43:01

标签: html css twitter-bootstrap-3

我正在尝试创建一个可折叠的面板,其中包含多个控件-文本框,标签,下拉菜单等,但是每当我使用以下代码时,都会显示折叠动画,但是这些项目仍然可见。

这是我正在尝试做的一个示例:

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Collapsible List Group</h2>
  <p>Click on the collapsible panel to open and close it.</p>
  <div class="panel-group">
    <div class="panel panel-default" data-toggle="collapse" data-target="#collapse1">
      <div class="panel-heading">
        <h4 class="panel-title">
          Collapsible list group
        </h4>
      </div>
      <div class="panel-collapse collapse show" id="collapse1">
        <div class="container-fluid">
          <div class="row">
            <div class="col">
            <span>
              <label for="#txtbox">Text Here</label>
              <input id="txtbox" type="text"/>
            </span>
            </div>
            <div class="col">
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

</body>
</html>

一些截图显示了我在说什么:

未折叠:

enter image description here

崩溃:

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试从您要折叠的字段中删除“显示”类:
编辑:默认情况下要显示未折叠时,包括“ in”类。

<div class="container">
      <h2>Collapsible List Group</h2>
      <p>Click on the collapsible panel to open and close it.</p>
      <div class="panel-group">
        <div class="panel panel-default" data-toggle="collapse" data-target="#collapse1">
          <div class="panel-heading">
            <h4 class="panel-title">
              Collapsible list group
            </h4>
          </div>
          <div class="collapse in" id="collapse1">
            <div class="container-fluid">
              <div class="row">
                <div class="col">
                <span>
                  <label for="#txtbox">Text Here</label>
                  <input id="txtbox" type="text"/>
                </span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
  </div>