Issue with Expanding Accordion Collapsible Panel Despite Schema Markup Addition

My collapsible accordion panel is functioning correctly. I have noticed that the first panel is not expanding upon click, while the second one is not working perfectly. The difference between the two panels is not significant. I have added schema markup to the first panel, but it seems to be interfering with the expand functionality. I am seeking assistance in making the panel expandable while retaining the schema markup.

.servive-info {
  padding: 10px 20px;
  background: #ebf6f5;
  border: 1px solid #dae9f3;
  border-radius: 7px;
  margin-top: 25px;
  overflow: auto;
  color: #333333d9 !important;
}

.servive-info p {
  font-family: "Lato", sans-serif;
  font-size: 16px;
  letter-spacing: 0.5px;
  line-height: 1.5em;
  color: #333;
  font-weight: 400;
}

.faqtitle {
  font-weight: 700;
  font-size: 24px;
  color: black;
  padding: 15px 15px 0;
  font-family: Sans-Serif;
  border: none;
}

.accordion>input[type="checkbox"] {
  position: absolute;
  left: -100vw;
}

.accordion .content {
  overflow-y: hidden;
  height: 0;
}

.accordion>input[type="checkbox"]:checked~.content {
  height: auto;
  overflow: visible;
}

.accordion label {
  display: block;
}

.accordion {
  border-bottom: 2px solid #fff;
  padding: 15px 0px 8px 0px;
  overflow: hidden;
  font-size: 15px;
  letter-spacing: 0.5px;
  line-height: 1.7;
}

.accordion>input[type="checkbox"]:checked~.content {
  padding: 10px 15px 0px 15px;
  border: 0px solid #e8e8e8;
  border-top: 0;
  border-top: 2px solid #004287;
  margin-top: 10px;
}

.accordion .handle {
  margin: 0;
  font-size: 18px;
  line-height: 1.5em;
  border-left: 2px solid #c82333;
  margin-right: 10px;
}

.accordion label {
  color: #000;
  cursor: pointer;
  padding: 10px 15px;
}

.accordion label:hover,
.accordion label:focus {
  background: none;
}

.accordion .handle label:before {
  content: '';
  width: 8px;
  height: 8px;
  border-style: solid;
  border-width: 2px 2px 0 0;
  border-color: #FBBC05;
  display: inline;
  margin-left: 10px;
  vertical-align: middle;
  text-align: center;
  float: right;
  transform: rotate(45deg);
  margin-top: 6px;
}

.accordion>input[type="checkbox"]:checked~.handle label:before {
  content: "";
  transform: rotate(135deg);
}

.accordion:last-child {
  margin-bottom: 1em;
}
<div class="servive-info" itemscope="" itemtype="https://schema.org/FAQPage">
  <div class="accordion">
    <input type="checkbox" name="collapse1" id="handle1" checked="checked">
    <div itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
      <h2 class="handle" itemprop="name">
        <label for="handle1">1. What is your name?</label>
      </h2>
      <div itemscope="" itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
        <div class="content" itemprop="text">
          <p>My name is Adam.</p>
        </div>
      </div>
    </div>
  </div>
  <div class="accordion">
    <input type="checkbox" name="collapse2" id="handle2">
    <div itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
      <h2 class="handle" itemprop="name">
        <label for="handle2">2. What's your hobby?</label>
      </h2>
      <div class="content" itemscope="" itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
        <p itemprop="text">Playing outdoor sports.</p>
      </div>
    </div>
  </div>
</div>

Answer №1

Integrating that schema map caused an issue with the accordion functionality because it positioned the div.content in a different scope than what was expected by the CSS selector targeting it.

Specifically, the problem lies within these two CSS selectors/definitions.

.accordion>input[type="checkbox"]:checked~.content {
    height: auto;
    overflow: visible;
}

.accordion>input[type="checkbox"]:checked~.content {
    padding: 10px 15px 0px 15px;
    border: 0px solid #e8e8e8;
    border-top: 0;
    border-top: 2px solid #004287;
    margin-top: 10px;
}

The issue arises from seeking a div.content that should be a sibling to the input checkbox but is located in the second accordion section. However, due to the difference in div elements' scopes, this association is not made correctly in the first accordion. By updating those two CSS selectors as follows:

.accordion>input[type="checkbox"]:checked~div>.content {
    height: auto;
    overflow: visible;
}

.accordion>input[type="checkbox"]:checked~div>.content {
    padding: 10px 15px 0px 15px;
    border: 0px solid #e8e8e8;
    border-top: 0;
    border-top: 2px solid #004287;
    margin-top: 10px;
}

Your issue can be resolved. The addition of div> before .content updates the selector to connect with the correct div.content structure according to the HTML modifications.

UPDATE Considering the updated HTML structure you have implemented following this guidance, simply relocate the designation of the .content class one div level higher.

Answer №2

<div class="accordion">
  <input type="checkbox" name="collapse" id="handle1" checked="checked">
  <h2 class="handle" itemprop="name">
      <label for="handle1">1. What is your name?</label>
    </h2>
    <div class="content" itemscope="" itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
      <p itemprop="text">My name is Adam.</p>
    </div>
</div>

When defining styles for the handle class in css, the selector used was .accordion .handle, but this was not effective due to an extra div between these two elements (.accordion), hindering the styling of the handle class.

Debugged code:

/* Accordion Collapsible Panel Starts */

.servive-info {
  padding: 10px 20px;
  background: #ebf6f5;
  border: 1px solid #dae9f3;
  border-radius: 7px;
  margin-top: 25px;
  overflow: auto;
  color: #333333d9 !important;
}

.servive-info p {
  font-family: "Lato", sans-serif;
  font-size: 16px;
  letter-spacing: 0.5px;
  line-height: 1.5em;
  color: #333;
  font-weight: 400;
}

.faqtitle {
  font-weight: 700;
  font-size: 24px;
  color: black;
  padding: 15px 15px 0;
  font-family: Sans-Serif;
  border: none;
}

.accordion>input[type="checkbox"] {
  position: absolute;
  left: -100vw;
}

.accordion .content {
  overflow-y: hidden;
  height: 0;
}

.accordion>input[type="checkbox"]:checked~.content {
  height: auto;
  overflow: visible;
}

.accordion label {
  display: block;
}

.accordion {
  border-bottom: 2px solid #fff;
  padding: 15px 0px 8px 0px;
  overflow: hidden;
  font-size: 15px;
  letter-spacing: 0.5px;
  line-height: 1.7;
}

.accordion>input[type="checkbox"]:checked~.content {
  padding: 10px 15px 0px 15px;
  border: 0px solid #e8e8e8;
  border-top: 0;
  border-top: 2px solid #004287;
  margin-top: 10px;
}

.accordion .handle {
  margin: 0;
  font-size: 18px;
  line-height: 1.5em;
  border-left: 2px solid #c82333;
  margin-right: 10px;
}

.accordion label {
  color: #000;
  cursor: pointer;
  padding: 10px 15px;
}

.accordion label:hover,
.accordion label:focus {
  background: none;
}

.accordion .handle label:before {
  content: '';
  width: 8px;
  height: 8px;
  border-style: solid;
  border-width: 2px 2px 0 0;
  border-color: #FBBC05;
  display: inline;
  margin-left: 10px;
  vertical-align: middle;
  text-align: center;
  float: right;
  transform: rotate(45deg);
  margin-top: 6px;
}

.accordion>input[type="checkbox"]:checked~.handle label:before {
  content: "";
  transform: rotate(135deg);
}

.accordion:last-child {
  margin-bottom: 1em;
}


/* Accordian Collapsible Panel Ends */
<div class="servive-info" itemscope="" itemtype="https://schema.org/FAQPage">
  <div class="accordion">
    <input type="checkbox" name="collapse" id="handle1">
    <h2 class="handle" itemprop="name">
      <label for="handle1">1. What is your name?</label>
    </h2>
    <div class="content" itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
      <p itemprop="text">My name is Adam.</p>
    </div>
  </div>
  <div class="accordion">
    <input type="checkbox" name="collapse2" id="handle2">
    <h2 class="handle">
      <label for="handle2">2. What's your hobby?</label>
    </h2>
    <div class="content">
      <p>Playing outdoor sports.</p>.
    </div>
  </div>
</div>

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

What is the reason border-box does not function properly on inline-block elements?

Demo: http://jsfiddle.net/L5jchnpm/ I've encountered an issue where I believed that using display: inline-block would make elements act as both inline and block elements. Additionally, I thought that setting box-sizing: border-box would adjust the w ...

Tips for executing multiple function calls within a single React component

Struggling to retrieve information from two separate API calls within the same React component. The issue seems to be with accessing the similar data in the code provided. function Info() { let params = useParams(); const [details, setDetails] = useSt ...

Extracting data from the website chartink.com

I need assistance with extracting data from the following link: link - I have been attempting web scraping, but I am unable to retrieve the specific table that I require. Can someone please provide guidance on how to achieve this? Despite using the code ...

Favicon not appearing on Jekyll website

This is my first time working with Jekyll. I'm currently working on localhost and trying to set a favicon for the website. I generated the image.ico and added the code provided to my head.html file. The image appears in my _site folder, but it's ...

creating a table with only two td's for formatting

My ultimate goal is to keep my web form code as minimal as possible for easier maintenance. I am currently working on creating a questionnaire and have been using two td elements for this purpose. Here is an example of what the current text structure looks ...

Ensuring consistent height for the initial div across separate columns (Bootstrap 4)

Here is the HTML structure that needs adjustment: <div class="container"> <div class="row"> <div class="col-12 col-sm-12 col-lg-4 col-md-4"> <div class="title">Some title</div> <ul&g ...

Exploring the world of web scraping by using Python to loop through HTML elements

Created a Python script to extract information from the website regarding its asset listings. So far, I have successfully retrieved the name of the first coin "Bitcoin," but I'm unable to get the ticker. With 27 pages on the site, each containing 40 ...

numerous inquiries regarding my CSS header navigation bars

As someone who is new to CSS, I find myself struggling to grasp the correct approach. Online examples vary and leave me confused. Specifically, I have questions about my markup but overall, am I doing things correctly? I feel like my CSS code is bloated. ...

What is the method for developing a multiple file downloader without the use of ActiveX?

I'm interested in developing a file downloader on a website without using Activex. Can anyone provide guidance on how to achieve this? ...

IE8 Image Links Not Working Without Chrome Frame Enabled

Upon visiting the website below, you'll notice a slideshow featured at the top of the homepage. Utilizing Nivo Slider, our client has brought to our attention that the links are not operational in IE8. The issue may be related to the "slide-overlay" ...

The art of perfect alignment: Mastering the positioning of Material-UI Grid

This issue has been resolved Hey there, I'm currently working on a React App with Material-UI and I'm trying to center a Grid item that includes a Card along with two additional Grid items. Below is the relevant code snippet. Although the Cards ...

Struggling with passing values to onClickHandler because of MUI

I'm looking to create a category navigation menu that includes icons and labels. I attempted to do this using Chips: {categories.map((category) => ( <Chip key={category._id} ...

Chrome does not support CSS animation rotation over 360 degrees

After researching for hours, I've encountered an issue with my animation in Chrome. It seems that while transform: rotate(1080deg); works flawlessly in Firefox, it fails to rotate in Chrome. Surprisingly, I discovered that it only rotates in Chrome wh ...

Separating the total number from my group using SQLAlchemy and Flask

I'm facing an issue with displaying a table that shows the sales amount of a particular car model. Similar to this one: https://i.sstatic.net/msTUH.png The problem is, I can't figure out how to separate the counted amount from the model. Is ther ...

Angular routing template failing to execute inline JavaScript code

I'm facing an issue with my Angular.js routing implementation. I have successfully displayed the HTML code in templates using angular.js, but now I am encountering a problem with my template structure: <div id="map_canvas" style="width:95%; heigh ...

Looking for assistance with my website's navigation bar and logo

Looking for assistance in moving my navigation buttons to each side of the logo. As a beginner in web design and CSS, I've been struggling with this task. Essentially, I want the "home" and "about" buttons on the left side of the logo, 16px apart from ...

I want to hide jqvmap when viewing on mobile devices

I'm currently working on my website at . I have a template that I'm using as a guide, but I want to make the map disappear on mobile view and replace it with a dropdown list. Can anyone suggest what code I should use for this? Appreciate any hel ...

Create a JavaScript function that can identify when a click event occurs within an li

I encountered a situation like this where I have code snippets from a website that I don't have permission to modify. <li class="History_lisitem_logout ui-last-child" data-icon="power"> <a id="History_lisitem_logout" ...

What is preventing the two spans from being centered within the div?

I'm having trouble centering the two spans within the div. How can I fix this issue? The code below is not working, but when I move the div outside of the two spans and change the display property to inline-block, it works. Why is this happening? b ...

in comparison to the base directory in ASP.NET

When using "/", it refers to the root directory. This can be seen in code like: <link href="/Styles/Order.css" rel="stylesheet" /> This specifies a file path that is relative to the root directory. However, when dealing with server controls, you m ...