Struggling to position radio buttons and their corresponding labels on the same line

Here is a preview of the current page layout.

Image showing misalignment of radio buttons and labels

This snippet shows the JSP code being utilized.

<div class="leftFormComp" style="width: 100%;">
  <label class="inputLabel" for="ext-comp-1045">
   <span class="required">*</span><fmt:message key="registration.agreement"/>
  </label>

  <div id="x-form-el-ext-comp-1045" class="x-form-element" style="padding-left: 8px;">
   <div id="ext-comp-1045" class=" x-form-checklist" style="width: 344px; height: auto;">

    <div class="x-form-cb-li x-form-cb-li-h" style="padding-bottom: 5px">
      <input id="termsAgree-Y" class="x-form-field" type="radio" value="Y" name="termsAgree"> <label class="x-form-cb-label" for="termsAgree-Y"><fmt:message key="registration.yes"/></label>
    </div>

    <div class="x-form-cb-li x-form-cb-li-h">
      <input id="termsAgree-N" class="x-form-field" type="radio" value="N" name="termsAgree"> <label class="x-form-cb-label" for="termsAgree-N"><fmt:message key="registration.no"/></label>
    </div>

   </div>
  </div>

</div>

I have attempted to use inline styling such as

display: inline!important;

on both input and label tags but without success.

Upon inspecting in Chrome Developer Tools, I noticed an additional attribute affecting the radio buttons' appearance. However, I am unsure of its source.

element.style {
    display: block;
}

Could someone recommend a method to override the existing styles on this element to align the radio buttons and their labels in one line? As a newcomer to front-end development, any assistance would be greatly appreciated. Additionally, help in identifying the origin of this unexpected styling (is it possible using Chrome Developer tools?)

Answer №1

To solve this issue, a quick fix would be to include the CSS property "float: left" in the radio buttons.

<input style="float:left" id="termsAgree-N" class="x-form-field" type="radio" value="N" name="termsAgree"> 
<label class="x-form-cb-label" for="termsAgree-N"><fmt:message key="registration.no"/></label>

This eliminates the need to worry about changing to display:inline-block. The code snippet proves that it works seamlessly even when the radio buttons have display:block set.

<div>
  <input type="radio" style="display:block;" />
  <label>without float:left</label>
</div><br/>

</br>
<div>
  <input type="radio" style="display:block; float:left" />
  <label>with float:left</label>
</div>

Here is a comparison image of before and after:

https://i.sstatic.net/fRmgT.png

Answer №2

After 'fmt' write the following:

<label class="x-form-cb-label" for="termsAgree-Y">
      <fmt:message key="registration.yes" />Yes
</label>

I have a feeling that this will do the trick.

Answer №3

There was an error in your approach. The correct name was overlooked.

Alter it to display:inline-block;

In the instance presented below, I applied this to the div elements. However, this CSS can be utilized on any element you desire.

div{display:inline-block;}
<div class="leftFormComp" style="width: 100%;">
  <label class="inputLabel" for="ext-comp-1045">
   <span class="required">* Subject</span><fmt:message key="registration.agreement"/>
  </label>

  <div id="x-form-el-ext-comp-1045" class="x-form-element" style="padding-left: 8px;">
   <div id="ext-comp-1045" class=" x-form-checklist" style="width: 344px; height: auto;">

    <div class="x-form-cb-li x-form-cb-li-h" style="padding-bottom: 5px">
      <input id="termsAgree-Y" class="x-form-field" type="radio" value="Y" name="termsAgree"> <label class="x-form-cb-label" for="termsAgree-Y"><fmt:message key="registration.yes"/>Yes</label>
    </div>

    <div class="x-form-cb-li x-form-cb-li-h">
      <input id="termsAgree-N" class="x-form-field" type="radio" value="N" name="termsAgree"> <label class="x-form-cb-label" for="termsAgree-N"><fmt:message key="registration.no"/>No</label>
    </div>

   </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

Utilize the converse.js plugin to set up a secure room with password protection

I'm looking to set up a password-protected room. Currently, I can create a public room and add a password in the configuration settings. However, I have to start by creating an unsecured, public room first. Is there a way to create a room with a pas ...

Ready to customize your CSS settings?

As I continue to learn .NET Core / MVC and work on my website, I am facing a challenge with removing the white space and getting the background to cover the entire page. Despite trying different approaches, such as setting the style for the opt-in compone ...

AngularJS and ExpressJS clash in routing (Oops, Crash!)

When setting up routing in angularjs and expressjs, I have created app.all('/*'...) to enable rendering index.html. However, whenever I use /*, the page crashes with an "Aw, Snap!" message. angularjs home.config(function($routeProvider,$locatio ...

What steps do I need to take in order to create a web-based file uploader that supports simultaneous uploads of multiple files

Is there a way to create the ability for users to upload multiple files at once on a Django/Python/jquery website, similar to the Gmail file selection feature? I am looking to allow users to select multiple files from their browser file selector and uplo ...

Challenge with placing a child element in CSS on Firefox and Internet Explorer

I am having trouble aligning the toggle eye of the password field using CSS. The positioning works well in Google Chrome, but it is not working in Firefox and IE. As a beginner in web development, I have tried to find a solution but haven't been succe ...

What is the best way to modify unchanging text within a span using Jquery?

This is an example of my custom span element in HTML. <span class="k-pager-info k-label">1 - 20 of 91 records</span> I am looking to use Jquery to change "items" to "records" in the above span element. ...

Sending a request to a PHP file using Ajax in order to display information fetched from

I am attempting to display the database row that corresponds with the student's forename and surname selected from the dropdown list. I have managed to store the first name and surname in a variable called clickeditem. However, I suspect there may be ...

Customize CSS to target the first and last elements in a row using flexbox styling

I am facing a challenge in selecting the last element of the first row and the first element of the last row within a flex container. The setup involves a flex-wrap: wrap; for my flex container where all elements have flex: auto; with different sizes. Thi ...

Customizing button appearances in the control div on Google Maps - A guide

Is there a way to manipulate elements and adjust styles by clicking buttons on the map control div? I want to achieve the same effect on the map as with the buttons in the table. Code: jsFiddle Update: Thanks to your assistance, I was able to achieve th ...

Leveraging ASP.NET MVC 5 to integrate an online document viewer from Office 365, seamlessly displaying Word documents within a sleek, compact window

We have been struggling to showcase a Word document (.docx) within an iframe on our website using the Office 365 service. The document is stored in One-Drive for business online and has been appropriately shared. After signing in, we obtained a link to the ...

jQuery is attempting to create an animation by combining three variables to determine a new height

Currently, I am facing an issue with animating a div to a new height by summing up the heights of 3 other divs. Unfortunately, the heights do not seem to add up correctly, and I could really use some guidance on how to resolve this. Any suggestions or in ...

When utilizing the jQuery function $(event.target).closest('td'), it tends to become disoriented when invoked multiple times simultaneously within the same function

I'm encountering an issue with the following code and I'm unsure of the root cause. Here's a brief overview of the scenario: I have a webpage with multiple input fields for inline editing. Whenever each field is filled and then blurred or ...

Masking text in React Fiber/Drei can be achieved through a variety

Can you use a <Text>/<Text3D> to mask another object, like shown in this image where text is masking a cube? I have looked at examples on pmndrs/drei and tried various methods with replacing other objects, but I am unable to achieve the desire ...

Why don't inline style changes implemented by JavaScript function properly on mobile browsers like Chrome, Dolphin, and Android?

View the jsFiddle here Issue on PC/Windows browser: When performing action, h1 header "gif" disappears and video starts playing. Problem on mobile devices: The gif does not disappear as expected but the video still plays indicating that JavaScript is fun ...

The value of `this` from React Store is currently returning null

I'm facing an issue where the this keyword is coming back as null in my store within a React component. I suspect that binding might be necessary, but I'm not entirely sure. Additionally, I am utilizing React Router and have the component wrapped ...

Using Javascript to prevent css from changing the display

I want to make some CSS adjustments to a single element using a single script, but I want all the changes to be displayed at once. For example: $("#someelement").css({width:"100%"}); //this change should not be displayed $("#someelement").width($("#someel ...

How can we increase the accuracy of numerical values in PHP?

When performing a math operation in JavaScript, the result is: 1913397 / 13.054 = 146575.53240386088 However, when the same operation is performed in PHP, the result is slightly different: 1913397 / 13.054 = 146575.53240386 This discrepancy may be due ...

How to apply a border to a CSS3 triangle shape

This is my unique code snippet CSS #page { width: 900px; padding: 0px; margin: 0 auto; direction: rtl; position: relative; } #box1 { position: relative; width: 500px; border: 1px solid black; box-shadow: -3px 8px 34px ...

What could be causing my Styled Components not to display the :before and :after pseudo elements?

When attempting to use the content property in a :before or :after pseudo element, I am encountering a rendering issue. Here is a simplified version of the component: import React from 'react'; import PropTypes from 'prop-types'; import ...

A step-by-step guide to extracting live data using cheerio and socketio

I am currently scraping data from a website using Cheerio. Can someone provide me with guidance on how to retrieve web data and automatically update it using socket communication when there are changes on the website? I want to make this process real-tim ...