【问题标题】:How to make collapse button inside div properly in bootstrap?如何在引导程序中正确制作 div 内的折叠按钮?
【发布时间】:2016-09-11 15:32:11
【问题描述】:

我想为我的报价容器制作一个折叠按钮,但是当我单击它时,在第一次单击时,什么也没有发生,但是当我再次单击时,整个 div 消失了?我想我在这里正确地遵循了示例? getbootstrap

在我的小提琴中,我的折叠按钮也不起作用。但是在我的 google chrome 浏览器中可以吗?是否也有可能当我崩溃时,当它崩溃时我可以更改为另一个 fontawesome 图标?折叠/隐藏时减号变为加号? 这是我的代码和 js 小提琴: JSFIDDLE

HTML

<div class="quote-box" id="collapse-quote">
  <div class="text">
    asdasd
  </div>

  <div class="buttons">

    <button class="button" id="twitter-button"><a title="Tweet this quote!" target="_blank"> tweet
      <i class="fa fa-twitter"></i>
    </a></button>

    <button class="button" id="facebook-button"><a title="Share this quote!" target="_blank">share
      <i class="fa fa-facebook"></i>
    </a></button>

    <button class="button" id="close-open" type="button" data-toggle="collapse" data-target="#collapse-quote" aria-expanded="false" aria-controls="collapse-quote">
      <i class="fa fa-minus"></i>
    </button>
  </div>

</div>

css

.quote-box {
  text-align: center;
  position: relative;
  border-radius: 4.5px;
  border: solid black 1px;
  display: table;
  width: 50%;
  height: 500px;
  padding: 10%;
  margin: 10% auto auto auto;
  /* center the box */
}

.quote-box .buttons {
  top: 0;
  /* align to top */
  left: 0;
  width: 100%;
  position: absolute;
  /* out of the document flow and you can move*/
  height: 100%;
  text-align: left;
  padding: 1%;
  box-sizing: border-box;
}


/* sample: uncomment if you want to align on right 
#twitter-button{
  float: right;
} 
*/

#close-open {
  /* float the collapse button to the right */
  float: right;
}

.fa-minus {
  color: #11A5D6;
  /* color for the button */
}

我做错了什么?我已经修复了几个小时的按钮。

【问题讨论】:

  • 为什么你有两次jQuery?检查控制台是否有任何错误/冲突。

标签: html css twitter-bootstrap-3 collapse


【解决方案1】:

它对我有用。我所做的只是删除您的jquery-2.2.3.min.js 引用并将您的bootstrap.min.js 更改为使用https

您还有其他问题,请查看此Fiddle

css

.quote-box {
  text-align: center;
  position: relative;
  border-radius: 4.5px;
  border: solid black 1px;
  width: 50%;
  padding: 10%;
  margin: 10% auto auto auto; /* center the box */
}

html,您错过了 div 上的折叠类,如果您折叠所有按钮,您应该如何返回它们?

<div class="quote-box">
    <div class="text collapse" id="collapse-quote">
       asdasd
    </div>

    <div class="buttons">

        <button class="button" id="twitter-button"><a   title="Tweet this quote!" target="_blank"> tweet
            <i class="fa fa-twitter"></i>
        </a></button>

        <button class="button" id="facebook-button"><a   title="Share this quote!" target="_blank">share
            <i class="fa fa-facebook"></i>
        </a></button>

        <button class="button" id="close-open" type="button" data-toggle="collapse" data-target="#collapse-quote" aria-expanded="false" aria-controls="collapse-quote">
            <i class="fa fa-minus"></i>
        </button>
    </div>

</div>

【讨论】:

  • 我听从了您的指示,但仍然对我不起作用,第一次单击时没有任何反应,第二次单击时,一切都消失了,当我将折叠放在引号框容器上时,容器没有显示结果或倒塌了吗?
  • 因为当我放置崩溃时,什么都没有显示给我,我按照您的指示进行操作,但是隐藏内容但按钮仍然存在。这可能吗?当我点击隐藏按钮更改图标时?
  • @GlendonPhilippBaculio 看看我贴的代码,它只隐藏了内容,按钮仍然存在。是的,您可以使用jquery toggle 更改按钮图标。
猜你喜欢
  • 2017-10-11
  • 2021-11-04
  • 2013-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-26
相关资源
最近更新 更多