Accordion tabs that don't have IDs but feature radio buttons

My initial intention was to develop accordion tabs using radio buttons. The idea was that the first tab would be checked by default, and clicking on another tab would automatically close the one currently open, creating a smooth transition between tabs. However, despite my efforts, I encountered an issue with my code. While I am able to select the radio buttons, the corresponding text does not appear as intended.

I am aware that using IDs could potentially resolve this issue, but unfortunately, due to restrictions within my system, I am unable to implement IDs in my code. Additionally, both PHP and JavaScript functionalities are disabled on my webpage. Given these constraints, I am left wondering if there is any alternative workaround to make the code work without relying on IDs.

.acc_outer {
  height: auto;
  width: 550px;
  position: relative;
  display: inline-block;
  background-color: #f6f6f6;
  padding: 10px;
  border-radius: 5px;
  border: 1px solid #8da8a5;
}

.acc_label {
  cursor: pointer;
  display: block;
  text-align: left;
  padding: 10px 15px;
  font-weight: 700;
  border-radius: 5px;
  margin-bottom: 3px;
  background-color: #909f9d;
  color: #f6f6f6;
  font-size: 20px;
  text-shadow: 0px 0px 1px #595959;
}

.acc_label:hover {
  background-color: #a1b1ae;
}

.acc_input:checked+.acc_label {
  background-color: #a1b1ae;
}


/*.acc_input {
  display: none;
}*/

.acc_txt {
  color: #595959;
  text-align: justify;
  height: 0;
  overflow: hidden;
  position: relative;
  opacity: 0;
  padding: 5px 10px;
}

.acc_outer .acc_input:checked~.acc_txt {
  height: auto;
  opacity: 1;
}
<center>
  <div class="acc_outer">
    <div class="acc_div">
      <label class="acc_label">
        <input class = "acc_input" type = "radio" name = "input" checked = "checked">
        Label1</label>
      <div class="acc_txt">Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</div>
    </div>

    <div class="">
      <label class="acc_label">
        <input class = "acc_input" type = "radio" name = "input">
        Label2</label>
      <div class="acc_txt">Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</div>
    </div>

  </div>
</center>

Answer №1

The criteria for when an input is checked needs to be adjusted.

This code snippet identifies when a label contains a checked input and then reveals the text next to it (note: this is adjacent to the label, not the outer element).

.acc_outer {
  height: auto;
  width: 550px;
  position: relative;
  display: inline-block;
  background-color: #f6f6f6;
  padding: 10px;
  border-radius: 5px;
  border: 1px solid #8da8a5;
}

.acc_label {
  cursor: pointer;
  display: block;
  text-align: left;
  padding: 10px 15px;
  font-weight: 700;
  border-radius: 5px;
  margin-bottom: 3px;
  background-color: #909f9d;
  color: #f6f6f6;
  font-size: 20px;
  text-shadow: 0px 0px 1px #595959;
}

.acc_label:hover {
  background-color: #a1b1ae;
}

.acc_input:checked+.acc_label {
  background-color: #a1b1ae;
}


/*.acc_input {
  display: none;
}*/

.acc_txt {
  color: #595959;
  text-align: justify;
  height: 0;
  overflow: hidden;
  position: relative;
  opacity: 0;
  padding: 5px 10px;
}

.acc_label:has(.acc_input:checked)~.acc_txt {
  height: auto;
  opacity: 1;
}
<center>
  <div class="acc_outer">
    <div class="acc_div">
      <label class="acc_label">
        <input class = "acc_input" type = "radio" name = "input" checked = "checked">
        Label1</label>
      <div class="acc_txt">Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</div>
    </div>

    <div class="">
      <label class="acc_label">
        <input class = "acc_input" type = "radio" name = "input">
        Label2</label>
      <div class="acc_txt">Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</div>
    </div>

  </div>
</center>

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

Can you explain the functionality of a Radius Manager and how I can personalize it to suit my needs

Can you explain what a Radius Manager is and how I can customize it? My company wants me to create a website based on their radius manager, and they've given me three steps for the login page: 1- Verify username and password for authentication 2- Ch ...

Creating a pattern to match date ranges using regular expressions

Looking to extract dates from a date string, for example, how can I convert "01-Apr-2013" to "01-Apr-2016"? Any tips on creating Regex or JavaScript code for this task? ...

The content security policy directive is being violated due to the improper use of image sources, including * 'self' data, and https

I am having trouble retrieving a dynamic image from my server and encountering these errors. Initially, I received Content Security Policy directive: "default-src *". Note that 'img-src' was not explicitly set, so 'default-src' is use ...

Use the CSS class

To create tables with 3 rows and 2 columns using divs, I have utilized the ng-repeat directive. Within this setup, there are two CSS classes - red and green, that need to be applied in the following manner: - Red class for the 1st column of the 1st row - ...

BeautifulSoup: Capturing the Title and Nearby <a> Links

In my current project, I am trying to extract data from the 'Current Events' page on Wikipedia by using the code snippet below. As of now, this code generates an array of Objects, each containing the values title and url. What I want to achieve ...

When the parent container is given a specific height, the Flexbox item on iOS 9 appears to be shrunk down

Encountering a bug on iOS version 9 while using the latest Bootstrap 4 Beta. The issue involves a parent div and ul element with multiple list items. The parent div is a flexbox with set dimensions and overflow enabled for child elements. The list item sho ...

How is it possible that the form already comes with data filled in that I didn't input myself

I am currently working on a website using cakephp. Strangely, when I load the login form, both the username and password fields are already prefilled. The interesting part is that this information is not hardcoded anywhere in the form or controller files. ...

Adding a padding-left to a horizontal list within Flexbox enhances the design and structure

How can the left-padding added by Flexbox on a horizontal list be fixed even with justify-content: space-between? <div class="list-container"> <ul> <li>One</li> <li>Two</li> <li>Three</li> ...

Excessive Blank Areas

I needed to create 3 horizontal paragraphs side by side, and the only solution I found was using the position property, but it didn't turn out as expected. Despite my efforts to make it look clean, it always ends up like this. Below is the code I use ...

Rails will provide JSON responses rather than HTML

My ruby on rails web app is currently set up to return HTML, but I want it to function as a web service and return JSON instead. I would like this to apply to all CRUD methods, so that the entire page is rendered as JSON. So far, I have only been able to a ...

Python Selenium encountering the StaleElementReferenceException bug

I'm encountering an issue with Selenium in Python that reads: selenium.common.exceptions.StaleElementReferenceException: Message: u'stale element reference: element is not attached to the page document\n Interestingly, this error occurs at ...

Ways to avoid page refresh when clicking a button using jQuery, while still permitting the Flask view function to delete data from the database

I'm looking to have the post_to_delete function in python delete data without displaying the "formNewPost" div. Instead, I want the 'tablePosts' div to be refreshed. These view functions are in Flask. Thank you. How can I prevent the page fr ...

Adjusting the values within an ng-repeat directive

I am relatively new to working with angularjs and I am currently trying to modify the data in $scope.works. I have attempted using xeditable without much success. I understand that it is a simple task, but any guidance you can provide would be greatly appr ...

What is the best way to implement media queries in a column layout for a responsive webpage?

My goal is to display a picture below the navbar when the window size becomes small or in mobile mode, followed by my name and other details. However, I am having trouble understanding how to implement this using media queries. DESKTOP PREVIEW https://i. ...

All web browsers are supported by the HTML time input type for time formatting

Hello there, I'm currently dealing with an issue in my Angular / JHipster project. The problem lies with the input Forms, specifically the one with Type="TIME". While it displays correctly on my browser as (12:24), other browsers show it differently ...

Tips for adjusting CSS font sizes within a contenteditable element?

I am looking to develop a compact HTML editor using JavaScript that allows me to customize the font-size of selected text with a specific CSS value. The documentation states that the FontSize command is used like this: document.execCommand("FontSize", fal ...

When a <select> tag is included within a <div> tag, it will not be submitted as part of a <form

I'm experiencing an issue with my HTML structure. Here is the code snippet: <form> <div> <select name="selectbox"> <option>option 1</option> </select> </div> </form> After su ...

Is there a way to keep the background image stationary as I scroll?

As someone who is new to html and CSS, I recently tried to enhance my previous project by incorporating a background image that spans the entire screen size and remains fixed while scrolling up or down. Here is the code snippet: ''' body { ...

What is causing the native HTML5 date picker on Chrome for Android to suddenly slow down significantly?

Recently, I have encountered a frustrating issue with the date picker on my website. It used to work perfectly until a recent update on Chrome Android introduced a new date picker that is slow and unresponsive. Loading it takes several seconds, making it d ...

Fluid and static containers in Bootstrap offer flexible and fixed-width layout

I am experimenting with combining fluid containers and fixed containers within a single page layout using Bootstrap. For example, I want to have a large image as a hero unit that spans 100% of the width and height of the viewport, or three column images e ...