Twitter Share Button not appearing within Bootstrap Accordion

Looking to incorporate a Twitter 'share' button within each accordion item in Bootstrap 4 when expanded.

Currently, I can get the button to show up outside of the accordion but not inside.

I suspect that the issue lies with the class=="collapse" on the accordion <div>. When I remove it, the button displays correctly. You can see this demonstrated in my code where I removed class="collapse" from one accordion item and it worked.

Here is my code snippet below, along with a link to a demonstration.

I have annotated the code to indicate where the button functions properly and where it doesn't.

<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

<div class="row">
  <div class="col-md-12">
    <div id="accordion" role="tablist">

      <!-- Button works here outside accordion -->
      <a href="https://twitter.com/intent/tweet?button_hashtag=share&ref_src=twsrc%5Etfw" class="twitter-hashtag-button" data-show-count="false">Tweet #share</a>

      <div class="card list-view-brand">
        <div class="card-header" role="tab">
          <p title="Click to expand">
            <a data-toggle="collapse" id="#4367" href="#4367" aria-expanded="false" aria-controls="4367" class="collapsed">
               item 1
            </a>
          </p>
        </div>

        <div id="4367" class="" role="tabpanel" data-parent="#accordion" style="">
          <div class="card-body">

            <ul class="list-group mb-3">
              <li class="list-group-item d-flex justify-content-between lh-condensed">
                <div>
                  <small class="text-muted">ID</small>
                  <p class="my-0">4367</p>
                </div>
              </li>
              <li class="list-group-item d-flex justify-content-between lh-condensed">
                <div>
                  <small class="text-muted">Language</small>
                  <p class="my-0">fre</p>
                </div>
              </li>

              <li class="list-group-item d-flex justify-content-between lh-condensed">
                <!-- Button works here when class="collapse" removed from parent div -->
                <a href="https://twitter.com/intent/tweet?button_hashtag=share&ref_src=twsrc%5Etfw" class="twitter-hashtag-button" data-show-count="false">Tweet #share</a>
              </li>

            </ul>
          </div>
        </div>
      </div>

      <div class="card list-view-brand">
        <div class="card-header" role="tab">
          <p title="Click to expand">
            <a data-toggle="collapse" id="#4368" href="#4368" aria-expanded="false" aria-controls="4368" class="collapsed">
              item 2
            </a>
          </p>
        </div>

        <div id="4368" class="collapse" role="tabpanel" data-parent="#accordion" style="">
          <div class="card-body">
            <ul class="list-group mb-3">
              <li class="list-group-item d-flex justify-content-between lh-condensed">
                <div>
                  <small class="text-muted">ID</small>
                  <p class="my-0">4368</p>
                </div>
              </li>
              <li class="list-group-item d-flex justify-content-between lh-condensed">
                <div>
                  <small class="text-muted">Language</small>
                  <p class="my-0">ita</p>
                </div>
              </li>

              <li class="list-group-item d-flex justify-content-between lh-condensed">
                <!-- Button does not work here -->
                <a href="https://twitter.com/intent/tweet?button_hashtag=share&ref_src=twsrc%5Etfw" class="twitter-hashtag-button" data-show-count="false">Tweet #share</a>
              </li>

            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>

Would appreciate any guidance or suggestions. Thank you!

Answer №1

If you want to customize the appearance of your share link, you can change the class it uses.

Instead of using class="twitter-hashtag-button", you can change it to class="fa fa-twitter".

Your code will then look something like this :

<!-- doesn't work here -->
        <a href="https://twitter.com/intent/tweet?button_hashtag=share&ref_src=twsrc%5Etfw" class="fa fa-twitter" data-show-count="false">Tweet #share</a>

After making this change, you can style the .fa class as desired:

.fa {
    padding: 20px;
    font-size: 30px;
    width: 50px;
    text-align: center;
    text-decoration: none;
}

.fa-twitter {
    background: #55ACEE;
    color: white;
}

Check out the updated Fiddle here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Customize Bootstrap 4 to Adjust Element Positioning Depending on Screen Size

At the bottom of my contact page, I have included a Google Maps iframe, a vertical line, and a list of contact information all displayed on the same line. To create the vertical line, I added a right border to the column containing the Google Map and set ...

Adding data from PHP into a designated div element

update: After some trial and error, I managed to find a solution using jQuery and append() methods. From my PHP code, I created an array containing all the necessary information that I wanted to insert into the tab divs. I then encoded this array into JSON ...

Steps for creating an attention-grabbing text heading

Is there a way to insert an H1 header within an image header, similar to this example? Or how can I incorporate the text "Hello World" into the image header? View Image Here ...

I am having trouble with my 'SELECT DISTINCT' command, it's not functioning correctly

When I attempted to populate my drop down menu with values from the database using 'Select DISTINCT', it only retrieved some of the data instead of all of it. Below is my PHP code: <? $sqlretrive = mysql_query("Select DISTINCT type from ...

Skewed top-left border surrounds the element with a dashed design

I'm looking to achieve a border effect similar to the one shown in the image linked below: https://i.sstatic.net/a4hCQ.jpg Here is the code I have tried so far: <p>Some Text</p> p{ -webkit-transform: perspective(158px) rotateX(338deg ...

Obtaining the source code from a different domain website with the help of jQuery

Is there a way to extract part of the source code from a YouTube page without using server-side programming? I've tried cross-domain AJAX techniques like Yahoo YQL and JsonP. While Yahoo YQL allows me to grab part of the source code, I'm facing ...

List that scrolls with a stationary button

I am working on an interface that includes a button with a dropdown list. Here is an example: <a href="https://jsfiddle.net/DTcHh/16589/" rel="nofollow">jsfiddle</a> While the list is scrollable, I am looking to add a fixed button at the botto ...

Utilizing PHP to create a loop that processes two submitted forms

Is my code handling two submit forms in a loop correctly? I am facing an issue with the second form where it redirects to selectedSold.php but does not display any details or retrieve the name="nganga" of the selected row. The first form works fine, so I c ...

How can I determine the specific quantity of XPATH links with unique identifiers in Selenium?

Seeking automation with Python3 and selenium to streamline searches on a public information site. The process involves entering a person's name, selecting the desired spelling (with or without accents), navigating through a list of lawsuits, and acces ...

Angular 6 CSS spacing dilemmas

We recently made the switch from Angular 5 to Angular 6 and noticed that there is no spacing between the buttons/icons, etc. We are looking to bring back the spaces between the buttons and icons. I have recreated the issue below. As you can see in the Ang ...

Is the container in semantic ui being breached by a segment overflow?

I've recently started learning Semantic UI. One issue I'm facing is that the width of the "segment" overflows the "container." Check this JSFiddle for more clarity. Are there any alternative solutions? In addition to the grid system, I'm ...

How to activate a function or event upon closing a browser tab with JavaScript

How can a function be triggered when a user closes the browser tab, preventing it from closing immediately and instead displaying a popup prompting the user to either proceed to another page or close the tab? Scenario: In the event that a user attempts t ...

Update the image source when hovering over the parent element

Check out this snippet of HTML code: <div class="custom text-center threeBox ofsted"> <a class="ofsted" title="ofsted report" href="http://reports.ofsted.gov.uk/"> <img class="text-center ofstedLogo" src="images/ofsted_good_transparen ...

The variable "require" has not been declared in npm.js file at line

Apologies if this is a simple issue, but I have not been able to find a solution in my research. I am using the latest release of Bootstrap and have noticed a new file called npm.js compared to previous versions. All Bootstrap files are hosted locally on m ...

I'm currently working with Bootstrap 5. Is there a technique available to reposition the elements within a div without relying on padding or margin properties?

Developing a Website: <!DOCTYPE html> <html lang="en" class="h-100"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" ...

How can I dynamically bind the count value in an ng-repeat loop?

I'm working with HTML code that involves looping through layers, but the values in the columns change with each loop iteration. I have concatenated the index value to the table column, but it's not working as expected. Any suggestions? <div c ...

`How can I use JavaScript to display a modal?`

I am currently a student immersing myself in the world of coding, particularly focusing on learning javascript/jquery. In my recent project, I have developed a chess game using RoR and now I am tackling the promotion move. The idea is that when a Pawn piec ...

Issue encountered while attempting to establish a website on GITHUB PAGES

https://i.sstatic.net/p83ut.png My project was created using Bootstrap, HTML, and CSS. However, when I try to view it on Github pages, only the readme file is displayed and I receive an error message via email. This project holds significant importance fo ...

"Failure to Update: Ajax Auto-Refresh Table Failing to Refresh

I'm facing a tricky issue with my code that I just can't seem to resolve. Currently, I am using Ajax and setTimeout to retrieve data. The problem arises when the data doesn't refresh automatically (if I manually navigate to the page getdata. ...

Manipulating values in JavaScript using an onclick event in PHP

I am looking to remove the "http" from the URL part of an input link before sending the data. This is my input code that looks like this when clicked: <input style="outline: none;" type="button" onclick="formatText ('link:url');" class="btn ...