What is the best way to position the form options to appear on the left side of a radio button's label?

Take a look at the following code:

.reveal-if-active {
  opacity: 0;
  max-height: 0;
  overflow: hidden;
}

input[type="radio"]:checked~.reveal-if-active,
input[type="checkbox"]:checked~.reveal-if-active {
  opacity: 1;
  max-height: 100px;
  /* little bit of a magic number :( */
  overflow: visible;
}
<div>
  <input type="radio" name="choice-animals" id="choice-animals-dogs">
  <label for="choice-animals-dogs">I like dogs more</label>
  <div class="reveal-if-active">
    <input type="text" name="dog" placeholder="why?">
  </div>
</div>
<div>
  <input type="radio" name="choice-animals" id="choice-animals-cats">
  <label for="choice-animals-cats">I like cats more</label>
  <div class="reveal-if-active">
    <input type="text" name="cat" placeholder="why?">
  </div>
</div>

Upon running this code, you will notice that text boxes are revealed by clicking on radio buttons situated to the left side of the labels attached to those buttons.

I attempted using tables to organize the radio buttons and display the hidden text boxes next to the labels, but unfortunately, it did not work as expected. Using a table seems to have disabled the popups.

If anyone has any suggestions or guidance on how to tackle this issue, I would greatly appreciate it!

Answer №1

In response to @FabioCalderan's comment, we have discovered a simple solution. By adding the CSS property display:inline-block to the class .reveal-if-active, we can align the options with the radio button and label on the same line.

.reveal-if-active {
  display: inline-block;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
}

input[type="radio"]:checked~.reveal-if-active,
input[type="checkbox"]:checked~.reveal-if-active {
  display: inline-block;
  opacity: 1;
  max-height: 100px;
  /* slightly arbitrary number :( */
  overflow: visible;
}
<div>
  <input type="radio" name="choice-animals" id="choice-animals-dogs">
  <label for="choice-animals-dogs">I prefer dogs</label>
  <div class="reveal-if-active">
    <input type="text" name="dog" placeholder="why?">
  </div>
</div>
<div>
  <input type="radio" name="choice-animals" id="choice-animals-cats">
  <label for="choice-animals-cats">I adore cats</label>
  <div class="reveal-if-active">
    <input type="text" name="cat" placeholder="why?">
  </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

The left side of the page is anchored with text content while an engaging carousel occupies the right half

Looking to create a section on the website that remains fixed while a carousel scrolls vertically. Once you reach the final slide, scrolling will continue on the page rather than changing the carousel slide. Want it to function similarly to the Creative s ...

Retrieving Text following an HTML Element with a Parsing Tool

I'm currently utilizing PHP Simple HTML DOM for the development of a web scraper application. Here is the HTML structure from which we need to extract the City/State name, such as "Daviston, AL" in the example below. Can anyone assist me wi ...

Elements positioned next to each other with no margin when spread across multiple lines

I have a color picker with a right margin of 6px. https://i.sstatic.net/OHqQK.png I need the white square (with the black check marker) to not have a right margin so it doesn't wrap to the next line and can use the full width. Instead of applyin ...

Creating a personalized directive in Angular 2 that restricts input to only characters that adhere to a specified regular expression

I have successfully developed a directive that restricts any character from being typed in an input field if it does not match a specified pattern. import { Directive, Input, Output, HostListener, EventEmitter } from "@angular/core" @Directive({ select ...

Can a border be created without using any straight lines for a custom design?

Is it possible to create borders similar to the ones shown in the attached image? I'm looking for an accordion with a heading hover effect. Here is the image link: https://i.sstatic.net/NuSKW.png ...

inserting information into the database using the $_GET method

url - addreview.php?name=mercury This is what the form looks like <form action="addreviewaction.php" method="post" name="addReview"> <textarea name="content" cols="45" rows="7"></textarea> <input type="hidden" name="clubname" value=" ...

Developing HTML functionalities within the OneNote Add-in API

I have developed my own OneNote Add-in using Nodejs, but I am encountering two issues that I have been unable to resolve despite extensive research. The add-in I created adds a new outline to a OneNote page, which includes an HTML table with one column an ...

What is the best way to slide a Bootstrap 4 modal dialog to the right when closing, utilizing CSS or JavaScript

I have successfully added a CSS animation to my Bootstrap modal that slides in from the right when opening, which looks great. However, I am looking for a way to slide it back to the right when a custom close button is clicked, instead of just hiding it wi ...

Is there a way to ensure my chat view functions properly without relying on partial views?

I am currently working on integrating a private chat feature using SignalR in my project, and I have encountered an issue while creating a View with accessible model values to pass to the server. Specifically, I have a list of doctors, and when a user clic ...

JavaScript Error: Unable to determine the value of a null property

Is there a way to validate the user's input in real-time on an HTML form? Take a look at the following HTML code: <div class="col-md-2"> <input class="form-control" name="nbequipement" id="nbequipement" placeholder="" type="text"> ...

Issue with the alignment of the signup form next to the slider

form{ max-width: 30%; background-color: white; padding: 2%; position: relative; left: 50%; color: black; font-family: fantasy; } .form-control{ padding: 2%; margin: 1%; } label{ border-radius: ...

Is it possible to place a list/accordion above a button in Semantic UI?

Check out this rough code sandbox here There seems to be an issue with the accordion overflowing behind the button on the left side. I attempted to add style={{position: 'absolute', bottom:'2%', overflow: 'scroll'}} to the A ...

Animate the leftward disappearance of a div to make it vanish

My goal is to create a user interface where users can navigate through different divs. Here is the HTML code: <article id="realize" class="realizeBox"> <div class="shown"> <div class="heading"> <h2>Realisati ...

How can I adjust the padding and width attributes of the mat-menu in Angular 5

Today, I am struggling with a piece of code. Whenever I click on the Details button, it is supposed to open a mat-menu. However, for some reason, I cannot seem to adjust the padding or width of the menu: <div id="box-upload" [hidden]="hiddenBoxUpload" ...

Maintain the structure of the slick slider during transitions

I am working with the slick slider and aiming to achieve a specific layout for the slider itself. What I require is a structure that looks like this: div div div div div I have managed to implement this design successfully, bu ...

Display a preview image at the conclusion of a YouTube video

I am currently working on an iOS device and have a Youtube video thumbnail that, when clicked, disappears and the video automatically plays in fullscreen mode using an iframe. It's working perfectly. Now, I would like to know how I can make the thumb ...

What is the best way to remove quotation marks from a string?

I am struggling to remove any quotes (") within <a href> and </a> tags when manipulating a string. I have tried various methods without success. The string resembles HTML but is actually in string form, and I need to eliminate quotes from eleme ...

How to transform an image into a base64 string using Vue

I am having trouble converting a local image to base64. The function reader.readAsDataURL is not working for me. Instead of the image data, I always get 'undefined' assigned to the rawImg variable. The file variable contains metadata from the upl ...

Static page with a search box

I am in the process of creating a page with frequently asked questions (FAQ). My goal is to incorporate a search box that resembles the one featured on Font Awesome Icons. After seeking assistance online, I have managed to generate the following code: & ...

What is the best way to invoke a method on a component's prop in VueJS?

Is it possible to format a prop using a custom method that I've created? I was hoping for something similar to this: Here is an example of how I want to define my component: props:{ title: String, min: String, formatedDate: this.fo ...