显示边界过流和可折叠,直到单击隐藏

时间:2019-07-16 16:18:02

标签: javascript html css twitter-bootstrap-3

我有3个彼此相关的问题:

  1. 流到第二个边框的边框的背景色,如何使第一个和第二个边框之间的空间变白。
  2. 当我最小化页面时,背景颜色不会扩展到覆盖所有文本框以及带有边框的同一事物,如何使边框和底色最小化后覆盖所有内容。我尝试了溢出:隐藏并滚动。滚动可以实现我想要的功能,但是滚动条应该由浏览器而不是在border类内部进行。
  3. 如何设置折叠以显示直到单击,然后隐藏而不是隐藏直到单击即可。 感谢您的帮助。您可以运行代码以了解我的意思。

.wrapper {
  margin: 0 auto;
  width: 100%;
}

/* Change 960 to desired width */
.border {
  border-style: double;
  border-width: 10px;
  background-color: silver;
  overflow: expand;
}

.collapsible {
  background-color: sliver;
  color: black;
  cursor: pointer;
  width: 100%;
  border: none;
  text-align: left;
  outline: none;
  font-size: 15px;
}

.active,
.collapsible:hover {
  background-color: lightgray;
}

.collapsible:after {
  content: "\002B";
  background-color: sliver;
  font-weight: bold;
  float: right;
  margin-left: 5px;
}

.active:after {
  content: "\2212";
}

.content {
  background-color: sliver;
  padding: 0 18px;
  max-height: 0;
  transition: max-height 0.2s ease-out;
}
<link
  rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap  /3.4.0/css/bootstrap.min.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

<div class="container">
  <div class="border">
    <button class="collapsible" data-toggle="collapse" data-target="#demo">
      Simple collapsible
    </button>
    <div id="demo" class="collapse">
      <div class="row" style="white-space:nowrap;">
        <br />
        <label style="margin-right:78px; margin-left:15px">Assign Date</label>
        <label style="margin-right:78px;">Task Subject</label>
        <label style="margin-right:78px;">Assigner</label>
        <label style="margin-right:78px;">Pirorty</label>
        <label style="margin-right:78px;">Status</label>
        <label style="margin-right:78px;">Category</label>
        <label style="margin-right:78px;">Due Date</label>
        <label style="margin-right:78px;">Complete</label>
      </div>
      <div class="row" style="white-space:nowrap;">
        <input
          type="text"
          name="AssignDate"
          style="width:80px; margin-right:78px; margin-left:15px"
        />

        <input
          type="text"
          name="TaskSubject"
          style="margin-right:78px; width:85px"
        />
        <input
          type="text"
          name="Assigner"
          style="margin-right:50px; width:85px"
        />

        <select name="Pirorty" style="width: 60px; margin-right:70px">
          <option>High </option>
          <option>Low</option>
          <option>Normal</option>
        </select>

        <select name="Status" style="width: 100px; margin-right:20px">
          <option>I</option>
          <option>N</option>
          <option>R</option>
          <option>Re</option>
          <option>Cancelled</option>
          <option>Closed</option>
        </select>

        <select name="Category" style="width: 100px; margin-right:40px">
          <option>A</option>
          <option>D</option>
          <option>E</option>
          <option>INFO</option>
          <option>I</option>
          <option>M</option>
          <option>N</option>
          <option>R</option>
          <option>S</option>
        </select>

        <input
          type="date"
          name="DueDate"
          style="width: 80px; margin-right:60px"
        />

        <select name="Category" style="width: 50px">
          <option>10</option>
          <option>20</option>
          <option>30</option>
          <option>40</option>
          <option>50</option>
          <option>60</option>
          <option>70</option>
          <option>80</option>
          <option>90</option>
          <option>100</option>
        </select>

        <br />
        <br />
        <input
          type="checkbox"
          name="IncludeTasksIWasCcedOn"
          style="margin-left:15px"
        />&nbsp;Include Tasks I was CC'd On&nbsp;
        <button type="submit" style="float :right; margin-right:15px">
          Filter
        </button>
        <button type="reset" style="float :right; margin-right:15px">
          Clear
        </button>
        <br />
        <br />
        <br />
      </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:1)

jsfiddle of collapse

4)条子不是CSS的有效颜色。

3)您需要将类'in'添加到元素#demo中,以使其开始展开

2)您需要添加

#demo {
    overflow: hidden;
}

到您的样式区域。这将隐藏任何会在元素高度小于其子元素高度时溢出的子元素

1)bg颜色介于两者之间的原因是因为您设置了父元素的背景色。除非覆盖,否则其bg颜色将流入子级。 我将父bg设置为白色,子bg颜色设置为银色。

<!DOCTYPE html>
<html>

<head>
<meta
    name="viewport"
    content="width=device-width, initial-scale=1"
>
<link
    rel="stylesheet"
    href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"
>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> 
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"> 
 </script>
     <style>
        .wrapper {
        margin: 0 auto;
        width: 100%;
        }

    /* Change 960 to desired width */
    .border {
        border-style: double;
        border-width: 10px;
        /* changed bg color */
        background-color: white;
        /* expand is not a valid value
        overflow: expand; */

    }

    .collapsible {
        /* sliver is not a valid color */
        background-color: sliver;
        color: black;
        cursor: pointer;
        width: 100%;
        border: none;
        text-align: left;
        outline: none;
        font-size: 15px;
    }

    .active,
    .collapsible:hover {
        background-color: lightgray;
    }

    .collapsible:after {
        content: '\002B';
        background-color: sliver;
        font-weight: bold;
        float: right;
        margin-left: 5px;
    }

    .active:after {
        content: "\2212";
    }

    .content {
        background-color: sliver;
        padding: 0 18px;
        max-height: 0;
        transition: max-height 0.2s ease-out;
    }

    #demo {
        overflow: hidden;
    }

    /* added bg color here for inner area */
    #demo .row {
        background-color: silver;
    }
    </style>
    </head>

    <body>

<div class="container">
    <div class="border">
        <button
            class="collapsible"
            data-toggle="collapse"
            data-target="#demo"
        >Simple collapsible</button>
        <div
            id="demo"
            class="collapse in"
        >
            <div style="clear:both;">
                <div
                    class="row"
                    style="white-space:nowrap;"
                >
                    <br />
                    <label style="margin-right:78px; margin-left:15px">Assign Date</label>
                    <label style="margin-right:78px;">Task Subject</label>
                    <label style="margin-right:78px;">Assigner</label>
                    <label style="margin-right:78px;">Pirorty</label>
                    <label style="margin-right:78px;">Status</label>
                    <label style="margin-right:78px;">Category</label>
                    <label style="margin-right:78px;">Due Date</label>
                    <label style="margin-right:78px;">Complete</label>
                </div>
                <div
                    class="row"
                    style="white-space:nowrap;"
                >
                    <input
                        type="text"
                        name="AssignDate"
                        style="width:80px; margin-right:78px; margin-left:15px"
                    />

                    <input
                        type="text"
                        name="TaskSubject"
                        style="margin-right:78px; width:85px"
                    />
                    <input
                        type="text"
                        name="Assigner"
                        style="margin-right:50px; width:85px"
                    />

                    <select
                        name="Pirorty"
                        style="width: 60px; margin-right:70px"
                    >
                        <option>High </option>
                        <option>Low</option>
                        <option>Normal</option>
                    </select>

                    <select
                        name="Status"
                        style="width: 100px; margin-right:20px"
                    >
                        <option>I</option>
                        <option>N</option>
                        <option>R</option>
                        <option>Re</option>
                        <option>Cancelled</option>
                        <option>Closed</option>
                    </select>

                    <select
                        name="Category"
                        style="width: 100px; margin-right:40px"
                    >
                        <option>A</option>
                        <option>D</option>
                        <option>E</option>
                        <option>INFO</option>
                        <option>I</option>
                        <option>M</option>
                        <option>N</option>
                        <option>R</option>
                        <option>S</option>
                    </select>

                    <input
                        type="date"
                        name="DueDate"
                        style="width: 80px; margin-right:60px"
                    />

                    <select
                        name="Category"
                        style="width: 50px"
                    >
                        <option>10</option>
                        <option>20</option>
                        <option>30</option>
                        <option>40</option>
                        <option>50</option>
                        <option>60</option>
                        <option>70</option>
                        <option>80</option>
                        <option>90</option>
                        <option>100</option>
                    </select>

                    <br />
                    <br />
                    <input
                        type="checkbox"
                        name="IncludeTasksIWasCcedOn"
                        style="margin-left:15px"
                    >&nbsp;Include Tasks I was CC'd On&nbsp;
                    <button
                        type="submit"
                        style="float :right; margin-right:15px"
                    >Filter</button>
                    <button
                        type="reset"
                        style="float :right; margin-right:15px"
                    >Clear</button>
                    <br />
                    <br />
                    <br />
                </div>
            </div>
        </div>
    </div>
</body>

</html>