简体   繁体   English

Bootstrap 3:如何制作手风琴面板,只要输入其中的文字?

[英]Bootstrap 3: How to make accordion panels as long as the text in it?

This is my code 这是我的代码

<div class="row"> <!-- start faq -->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

              <?php
              $counter = 1;
            foreach ($faqs as  $faq):
            $subcounter = 2;

           ?>

    <div class="panel-heading heading-bkg" role="tab" id="heading-1">
      <h4>
        <a class="subheading" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-<?php echo $counter;?>" aria-expanded="false" aria-controls="collapse-<?php echo $counter;?>">
             <b> <?php echo $faq['subheading'];?> </b> 

        </a>
      </h4>

    </div>


    <div id="collapse-<?php echo $counter;?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-<?php echo $counter;?>">
      <div class="panel-body">

        <?php foreach ($faq['subheadingcontent'] as  $subFaq):?>


            <div class="panel-heading" role="tab" id="heading-<?php echo $counter . '-' .  $subcounter;?>">
              <h1 class="panel-title">
                <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion-<?php echo $counter;?>" href="#collapse-<?php echo $counter . '-' .  $subcounter;?>" aria-expanded="false" aria-controls="collapse-<?php echo $counter . '-' .  $subcounter;?>">
          <?php echo $subFaq['question']; ?>
                </a>
              </h1>
            </div>

            <div id="collapse-<?php echo $counter . '-' .  $subcounter;?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-<?php echo $counter . '-' .  $subcounter;?>">
              <div class="panel-body">
          <?php echo $subFaq['answer']; ?>
              </div>
              </div>
              <?php
      $subcounter++;
     endforeach;?>
        </div>
        </div>



<?php
$counter++;
 endforeach;?>
</div>
</div> <!-- end faq -->

I would like to make the header takes as much space as the text within it. 我想让标题占用与其内部文本一样多的空间。

<div class="panel-heading heading-bkg" role="tab" id="heading-1">
      <h4>
        <a class="subheading" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-<?php echo $counter;?>" aria-expanded="false" aria-controls="collapse-<?php echo $counter;?>">
             <b> <?php echo $faq['subheading'];?> </b> 

        </a>
      </h4>

    </div>

currently the panel, or the panel-group, I don't know which, takes the full width of the page. 目前,我不知道哪个面板或面板组占用了页面的整个宽度。

I don't want to change the width of panel-group since the collapsed paragraphs need the full width of the page, I just want the panel-heading size to decrease, be as long as the text, as if someone highlighted the text. 我不想更改panel-group的宽度,因为折叠的段落需要页面的整个宽度,我只希望面板标题的大小减小,只要与文本一样长,就好像有人突出显示了文本一样。

If I want to highlight the text, why not apply background-color to the text? 如果要突出显示文本,为什么不将背景色应用于文本? Why would I want to change the panel width? 为什么要更改面板宽度?

Because if I highlight the text, and if the sentence does not fit on 1 line, the highlight would be wrong, I want the panel to act as a containter that highlights everything. 因为如果我突出显示文本,并且如果句子不适合1行,则突出显示将是错误的,因此我希望面板充当包含所有内容突出显示的容器。

So as not to mess with the existing css, you can create a new css class with the single property display: table !important; 为了避免与现有CSS混淆,您可以使用单个属性display: table !important;创建一个新的CSS类display: table !important; and apply that class to the panel-headings you want affected. 并将该类应用于您想要影响的面板标题。

 .heading-short { display: table !important; } 
 <div class="panel-heading heading-bkg heading-short" role="tab" id="heading-1"> <h4> <a class="subheading" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-<?php echo $counter;?>" aria-expanded="false" aria-controls="collapse-<?php echo $counter;?>"> <b> <?php echo $faq['subheading'];?> </b> </a> </h4> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM