bootstrap - grid-system - collapse/expand only 1 item in a row

2.1k views Asked by At

Im developing on a grid-system with several collapsed items in a row. The collapse is triggered when clicking on the title or the thumbnail.

Now the problem is: When i expand 1 item of a row, every other item is automatically expanded too, but the expanded text is only shown in the current item. I want only 1 item to expand and the rest to order themself in the grid system:

This img shows how it acts currently: enter image description here

And this is how i wanted it to act: enter image description here

Here is a fiddle of my current code: Fiddle

HTML Code of 1 item (only because some code is needed for fiddle):

<div class="flex-container">
  <div id="item1" class ="item">
     <a data-toggle="collapse" href="#collapse-1" class="collapsed" aria-expanded="false">
            <div class="item-body">
              <div class="image">
                    <img src="https://www.lycatv.tv/img/web/avatar_1.png" alt="Dummy" title="Dummy">          
                </div>

                <div class="content">                                                   
          <h3>TEST</h3>
          <h4>Testmodell 0</h4>
          <div class="btn-group-vertical buttons" role="group" aria-label="...">
                  <button type="button" class="btn btn-default btn-xs"><i class="fa fa-pencil" aria-hidden="true"></i></button>
                  <button type="button" class="btn btn-default btn-xs"><i class="fa fa-info" aria-hidden="true"></i></button>
                    </div>                                  
                </div>
            </div>
      </a>

            <div class="item-footer collapse" id="collapse-1" aria-expanded="false" style="height: 11px;">
              <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 1</p>
        <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 2</p>
                <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 3</p>
            </div>
        </div>
    </div>

Thanks in advance.

EDIT: Any updates? :)

1

There are 1 answers

2
kravisingh On

You are facing this problem due to flex. To fix this issue you have to go with other option like this:

body .flex-container{
  display:block;
}
.item{  
  background-color: white;
  border:solid 1px #000;
  margin: 5px;
  cursor: pointer;
  width: 100%;
}

.item .item-body{
 display: block;
    position: relative;
    height : 50px;
}

.item .item-footer{
   border-top: 1px solid #000;
    position: relative;
    padding-top: 10px;
    padding-left: 10px;
}

.item .item-body .image {
    display: block;
    float: left;
    vertical-align: middle;
    position: relative;
}

.item .item-body .image img {
    width: 50px;
    padding-top: 3px;
}

.item .item-body .content {
    display: block;
    float: left;
    padding: 0 ;
    margin-left: 10px;
    margin-right: 15px;
}

.item .item-body .content h3{
 font-size: 1.1em;
 margin-top: 8px;
 margin-bottom: 1px;
}

.item .item-body .content h4{
 font-size: 1em;
 margin-top: 1px;
 margin-bottom: 1px;
}

.item .item-body .content .buttons{
    display: block;
    position: absolute;
    top: 3px;
    right: 5px;
}

.item a{
  text-decoration: none;
  color: black;
}

.flex-container {
 -js-display: flex;
  display: flex;
  flex-wrap: wrap;
 height: 100%;
 min-height: 100px;
}
<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.2.1/jquery.min.js"></script>    
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
  <div id="item1" class ="item">
     <a data-toggle="collapse" href="#collapse-1" class="collapsed" aria-expanded="false">
   <div class="item-body">
     <div class="image">
        <img src="https://www.lycatv.tv/img/web/avatar_1.png" alt="Dummy" title="Dummy">          
    </div>
        
    <div class="content">               
          <h3>TEST</h3>
          <h4>Testmodell 0</h4>
          <div class="btn-group-vertical buttons" role="group" aria-label="...">
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-pencil" aria-hidden="true"></i></button>
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-info" aria-hidden="true"></i></button>
     </div>         
    </div>
   </div>
      </a>
      
   <div class="item-footer collapse" id="collapse-1" aria-expanded="false" style="height: 11px;">
     <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 1</p>
        <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 2</p>
    <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 3</p>
   </div>
  </div>
    <div id="item2" class ="item">
     <a data-toggle="collapse" href="#collapse-2" class="collapsed" aria-expanded="false">
   <div class="item-body">
     <div class="image">
        <img src="https://www.lycatv.tv/img/web/avatar_1.png" alt="Dummy" title="Dummy">          
    </div>
        
    <div class="content">               
          <h3>TEST</h3>
          <h4>Testmodell 1</h4>
          <div class="btn-group-vertical buttons" role="group" aria-label="...">
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-pencil" aria-hidden="true"></i></button>
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-info" aria-hidden="true"></i></button>
     </div>         
    </div>
   </div>
      </a>
      
   <div class="item-footer collapse" id="collapse-2" aria-expanded="false" style="height: 11px;">
     <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 1</p>
        <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 2</p>
    <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 3</p>
   </div>
  </div>
    <div id="item3" class ="item">
     <a data-toggle="collapse" href="#collapse-3" class="collapsed" aria-expanded="false">
   <div class="item-body">
     <div class="image">
        <img src="https://www.lycatv.tv/img/web/avatar_1.png" alt="Dummy" title="Dummy">          
    </div>
        
    <div class="content">               
          <h3>TEST</h3>
          <h4>Testmodell 2</h4>
          <div class="btn-group-vertical buttons" role="group" aria-label="...">
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-pencil" aria-hidden="true"></i></button>
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-info" aria-hidden="true"></i></button>
     </div>         
    </div>
   </div>
      </a>
      
   <div class="item-footer collapse" id="collapse-3" aria-expanded="false" style="height: 11px;">
     <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 1</p>
        <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 2</p>
    <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 3</p>
   </div>
  </div>
     <div id="item4" class ="item">
     <a data-toggle="collapse" href="#collapse-4" class="collapsed" aria-expanded="false">
   <div class="item-body">
     <div class="image">
        <img src="https://www.lycatv.tv/img/web/avatar_1.png" alt="Dummy" title="Dummy">          
    </div>
        
    <div class="content">               
          <h3>TEST</h3>
          <h4>Testmodell 3</h4>
          <div class="btn-group-vertical buttons" role="group" aria-label="...">
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-pencil" aria-hidden="true"></i></button>
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-info" aria-hidden="true"></i></button>
     </div>         
    </div>
   </div>
      </a>
      
   <div class="item-footer collapse" id="collapse-4" aria-expanded="false" style="height: 11px;">
     <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 1</p>
        <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 2</p>
    <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 3</p>
   </div>
  </div>
     <div id="item5" class ="item">
     <a data-toggle="collapse" href="#collapse-5" class="collapsed" aria-expanded="false">
   <div class="item-body">
     <div class="image">
        <img src="https://www.lycatv.tv/img/web/avatar_1.png" alt="Dummy" title="Dummy">          
    </div>
        
    <div class="content">               
          <h3>TEST</h3>
          <h4>Testmodell 4</h4>
          <div class="btn-group-vertical buttons" role="group" aria-label="...">
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-pencil" aria-hidden="true"></i></button>
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-info" aria-hidden="true"></i></button>
     </div>         
    </div>
   </div>
      </a>
      
   <div class="item-footer collapse" id="collapse-5" aria-expanded="false" style="height: 11px;">
     <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 1</p>
        <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 2</p>
    <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 3</p>
   </div>
  </div>
     <div id="item6" class ="item">
     <a data-toggle="collapse" href="#collapse-6" class="collapsed" aria-expanded="false">
   <div class="item-body">
     <div class="image">
        <img src="https://www.lycatv.tv/img/web/avatar_1.png" alt="Dummy" title="Dummy">          
    </div>
        
    <div class="content">               
          <h3>TEST</h3>
          <h4>Testmodell 5</h4>
          <div class="btn-group-vertical buttons" role="group" aria-label="...">
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-pencil" aria-hidden="true"></i></button>
      <button type="button" class="btn btn-default btn-xs"><i class="fa fa-info" aria-hidden="true"></i></button>
     </div>         
    </div>
   </div>
      </a>
      
   <div class="item-footer collapse" id="collapse-6" aria-expanded="false" style="height: 11px;">
     <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 1</p>
        <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 2</p>
    <p><i class="fa fa-ravelry" aria-hidden="true"></i> Dummy 3</p>
   </div>
  </div>
</div>

You can also check the updated Single column fiddle

Or you can make the hidden div absolute like this Two column fiddle