Home > Software design >  Is it possible to add an icon besides arrow in bootstrap accordion?
Is it possible to add an icon besides arrow in bootstrap accordion?

Time:01-26

I'm using a bootstrap 4 accordion and I was trying to add an icon besides the arrow up/down icon. I've tried to add a row and both icon place inside a row but still can't figure out how to make these two inline.

Here's what I have tried so far.

<div id="accordionExample">

<div >
    <div  id="heading-1">
         <h5 > 
            <a  role="button" data-toggle="collapse" data-target="#collapse-1" aria-expanded="false" aria-controls="collapse-1"> 
              Item 3 
            </a> 
         </h5>
    </div>
    <div id="collapse-1"  data-parent="#accordionExample" aria-labelledby="heading-1">
        <div > 
            Description 1 
        </div>
    </div>
</div>

</div>

CSS:

    .card-header-title > a {`
        display: block;
        position: relative;
    }
    .card-header-title > a:hover {
        cursor: pointer;
    }
    .card-header-title > a:after {
        content: "\f078"; /* fa-chevron-down */
        font-family: "Font Awesome 5 Free";
        font-weight: 900;
        position: absolute;
        right: 0;
    }
    .card-header-title > a[aria-expanded="true"]:after {
        content: "\f077"; /* fa-chevron-up */
    }

Result: enter image description here

And this is what I expected: expected

CodePudding user response:

Do you mean something like this?

.card-header-title > a {
  display: block;
  position: relative;
}

.card-header-title > a:hover {
  cursor: pointer;
}

.card-header-title i.fa-chevron-up {
  display: none;
}

.card-header-title > a[aria-expanded="true"] i.fa-chevron-down {
  display: none;
}

.card-header-title > a[aria-expanded="true"] i.fa-chevron-up {
  display: inline;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA 058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div  id="accordionExample">
  <div >
    <div  id="heading-1">
      <h5 >
        <a  role="button" data-toggle="collapse" data-target="#collapse-1" aria-expanded="false" aria-controls="collapse-1">
          Item 3
          <span >
            <i ></i>
            <i ></i>
          </span>
        </a>
        <span><i ></i></span>
      </h5>
    </div>
    <div id="collapse-1"  data-parent="#accordionExample" aria-labelledby="heading-1">
      <div >
        Description 1
      </div>
    </div>
  </div>
  
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5 76PVCmYl" crossorigin="anonymous"></script>

  • Related