Why are the radio buttons not aligned with the text in the center?

Currently, I am in the process of building a form that includes radio buttons. However, I've encountered an issue where the text next to the radio buttons appears on a different level than the buttons themselves.

How can I go about fixing this particular problem?

Check out our website for more information

Take a look at a screenshot showcasing the issue

This is the HTML code snippet:

<div class="d5-d8 m-all"id="contactFormContainer" >
                <form name="mainForm" id="mainForm">
                    <p>Need help getting started or requesting more info?</p>
                    
                    <input type="radio"  value="Info" name="infoOrPurchase"> Request Info<br>
                    <input type="radio"  value="Purchase" name="infoOrPurchase"> Request Service<br>
                    <br /><br />
                    <label><input type="text" value="First Name" onfocus="if (this.value=='First Name') this.value='';" onblur="this.value = this.value==''?'First Name':this.value;" size="35" /></label>
                    
                </form>
            </div>

Here's the corresponding CSS:

#mainForm{
    width:500px;
    float:left;
}

input{
    height:30px;
}
label{
    margin-top:30px;
}

    #commentsLabel{
        height:80px;
    }


input[type=text], textarea {
  -webkit-transition: all 0.30s ease-in-out;
  -moz-transition: all 0.30s ease-in-out;
  -ms-transition: all 0.30s ease-in-out;
  -o-transition: all 0.30s ease-in-out;
  outline: none;
  padding: 3px 0px 3px 3px;
  margin: 5px 1px 3px 0px;
  border: 1px solid #DDDDDD;
}

input[type=text]:focus, textarea:focus {
  box-shadow: 0 0 5px rgba(238, 116, 33, 1);
  padding: 3px 0px 3px 3px;
  margin: 5px 1px 3px 0px;
  border: 1px solid rgba(238, 116, 33, 1);
}

Answer №1

Here's a suggestion that might bring you closer to your desired outcome. Simply include the code snippet below in your CSS file and feel free to adjust the margin-top value to suit your preferences.

input[type=radio] {
  vertical-align: middle;
  margin-top: 0;
}

Answer №2

The height specification is causing the problem. Implementing this CSS code can resolve the issue:

input[type=radio]
{
   height:auto;
}

Answer №3

When presenting text along with radio buttons, it's important to ensure that the button is vertically aligned within its designated height. The text typically aligns itself at the bottom of the line, while adjusting the button's height or experimenting with block elements could help in achieving the desired layout.

Answer №4

Just delete the following code:

input{
    height:30px;
}

Answer №5

It has been noted by previous answers (I particularly agree with dgp's response).. setting the height of inputs to 30px causes alignment issues because the label and input are not vertically aligned.

In addition, clicking on the radio button text should toggle the selection of the input. To achieve this, assign unique ids to your inputs (using the same value as 'name') and wrap a label tag around the radio button text. The label tag should have a 'for' property that corresponds to the input, as shown in this fiddle:

http://jsfiddle.net/z8SU9/

Notice how you can click on the text for the first radio button to select it.. while clicking on the text for the second radio button does not have the same effect (no modifications were made to the second radio for comparison).

HTML

<div class="d5-d8 m-all"id="contactFormContainer" >
            <form name="mainForm" id="mainForm">
                <p>Interested in getting started or learning more?</p>
                <input type="radio"  value="Info" name="infoOrPurchase" id="test1"><label for="test1">Request Information</label><br />
                <input type="radio"  value="Purchase" name="infoOrPurchase"> Request Service<br>
                <br /><br />
                <label><input type="text" value="First Name" onfocus="if (this.value=='First Name') this.value='';" onblur="this.value = this.value==''?'First Name':this.value;" size="35" /></label>
                <label><input type="text" value="Last Name" onfocus="if (this.value=='Last Name') this.value='';" onblur="this.value = this.value==''?'Last Name':this.value;" size="35" /></label>
                <label><input type="text" value="Email" size="35" onfocus="if (this.value=='Email') this.value='';" onblur="this.value = this.value==''?'Email':this.value;" /></label>
                <label><input type="text" value="Phone" size="35" onfocus="if (this.value=='Phone') this.value='';" onblur="this.value = this.value==''?'Phone':this.value;" /></label>
                <label><input type="text" value="Company" size="35" onfocus="if (this.value=='Company') this.value='';" onblur="this.value = this.value==''?'Company':this.value;" /></label>
                <label><input type="text" value="How did you hear about us?" size="35" onfocus="if (this.value == 'How did you hear about us?') this.value = '';" onblur="    this.value = this.value == '' ? 'How did you hear about us?' : this.value;" /></label>
                <label><input id="commentsLabel" type="text" value="Comments" size="76" onfocus="if (this.value == 'Comments') this.value = '';" onblur="    this.value = this.value == '' ? 'Comments' : this.value;" /></label>
            </form>
        </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

Styling elements with pseudo-classes when a horizontal scroll bar is activated

I have been experimenting with CSS pseudo-classes, specifically the before and after classes. While I have had no issues with the before class, I am running into a horizontal scroll problem when using the after class. I want to avoid using overflow: hidde ...

Delightful Popup for Successful Woocommerce Additions

I have created a plugin that transforms Wordpress Woocommerce variations into a table layout. I made significant changes to the code and now I'm attempting to integrate Sweet Alerts 2 in place of the current alerts displayed when a user adds a product ...

A step-by-step guide on implementing the bootstrap paginator library to paginate PHP echoed data

I'm currently working on a project that involves displaying data from a database in a table. To make the data paginated on the client side, I decided to use the bootstrap paginator library available at: Below is the code I'm using: In my header ...

Circular gradient backdrop

Looking to create a sleek and professional body background for my website that is as attractive as Twitter's. Can you help me achieve the same blue shaded background effect? I'm new to web development and would appreciate any guidance on how to m ...

Issue with Audio TAG functionality in Internet Explorer 9

I am facing an issue with my jQuery code that generates an audio tag. The code works perfectly in Firefox and Chrome, but it is not functioning properly in IE9. Here is the code snippet: $(document).ready(function () { var source = "/TTS.aspx?tts=" + ...

Positioning searchbar on the right side in bootstrap 5

How can I fix the search bar on the right side of the screen within the Bootstrap navbar, without compromising its flexibility? I want it to always stay at the rightmost side regardless of the number of links in my navigation bar. As a beginner in CSS and ...

Sending data between two elements when a jQuery event is triggered

As a JavaScript beginner, I am facing an issue where I need to push data from an h1 tag to a textarea. My website is built using WooCommerce and when a visitor clicks on a product, a chat box with the product title opens. Currently, I have successfully p ...

Load elements beforehand without displaying them using a div

In order to efficiently manipulate my Elements using jQuery and other methods, I am exploring the idea of preloading them all first. One approach I have considered is creating a div with CSS display set to none, and placing all the elements I need for my w ...

Unleashing the Power of Node.js: A Step-by-Step Guide to Crafting

I am developing a console interface that prompts the user with questions and receives input through the console. Some questions require the user to provide a limited number of inputs. I have researched ways to obtain console input in node js, but I haven&a ...

Incorrect positioning on canvas

Is there a way to adjust text alignment within a canvas? Currently, my text is centered. However, when I change the text size, the alignment gets thrown off. Here is the code snippet: <canvas id="puzzle" width="480" height="480"></canvas> ...

How can multiple arguments be passed to a function using JQuery's post method?

I can't seem to figure out how to pass multiple arguments to a function using jQuery's post method. It might sound like a silly question, but I'm struggling with it. Currently, my code looks something like this: $.post("<?php echo site_ ...

Being required to design a distinct div for every article I am extracting from the API

In the midst of developing a website for my college project, I have successfully configured my news API to pull and display data using JavaScript. Currently, I am faced with the challenge of having to create separate div elements each time I want to add n ...

Troubleshooting the issue with utilizing the ng-repeat directive to loop through images in Angular JS

Embarking on my initial website development journey with Java and Spring Boot, I've hit a stumbling block in the front-end realm. Being a newbie, I'm struggling to identify and resolve the issue at hand. Problem title: How do I ...

Troubleshooting a React JS and material-ui issue

Having an issue with material-ui integration in reactjs. Attempting to render a FlatButton, but encountering the error message: TypeError: _context$muiTheme is undefined As a newcomer to reactjs, I'm unsure of where the problem lies. Below is my code ...

Converting the stage object to JSON format and incorporating it into an HTML5 environment using

$("#show").click(function(){ var stage = Kinetic.Node.create(json, 'container2'); var ball = new Image(); var cone = new Image(); var tshirt = new Image(); ball.onload = function() { stage.get('.ball').apply ...

A method to trigger the opening of a div tag when a button is clicked using Vue.js

<div class="input-wrapper"> <div class="mobile-icon"></div> <input class="input-section label-set" type="text" v-model.trim="$v.mobile.$model" :class="{'is-invalid': ...

Customize the width of dropdown menus in Bootstrap

Using a dropdown menu, I want to display options for candidates that can be chosen. Additionally, I would like an input field to filter these options; so that when text is entered, the dropdown menu adjusts accordingly. Specifically, I am looking to set th ...

cancel the ongoing ajax request during a specific event

There seems to be an issue with the behavior of clicking on the .personalized class. When clicked, it does not display both #loading_personalized and #divPersonalized elements simultaneously. This results in the execution of an AJAX call even when the pr ...

Array containing two objects in a two-dimensional format

In the example provided, I am working with a 2D array. Link to the example: https://codesandbox.io/s/v0019po127 I am noticing different results depending on whether I use the browser console or Codesandbox's console. I have attempted using JSON.str ...

Troubleshoot your Vue.js application using Visual Studio Code. Encounter an unidentified breakpoint error

I'm encountering a problem with debugging my Vue.js project using VS Code and Chrome. I followed the official guide on the website Guide, but it's not working for me. The error I keep running into is: unverified breakpoint What am I doing wrong? ...