Styling radio buttons with CSS

I've been struggling to align my radio buttons next to their labels. Despite numerous changes to the CSS, I can't seem to get my text boxes, radio buttons, and comment box to line up properly. Specifically, the second radio button is causing alignment issues.

Any suggestions would be greatly appreciated!

See the code in action: http://jsfiddle.net/NpJ55/

Below is my HTML and CSS:

<fieldset>
    <label for="name" class="formlabel">Name:</label>
    <input id="fName" name="name" type="text" class="forminput" />

    <label for="co" class="formlabel">Company:</label>
    <input id="fCo" name="co" type="text" class="forminput" />

    <label for="email" class="formlabel">Email:</label>
    <input id="fEmail" name="email" type="text" class="forminput" />

    <label for="phone" class="formlabel">Phone:</label>
    <input id="fPhone" name="phone" type="text" class="forminput" />

    <label for="contact" class="formlabel">Contact:</label>
    <div id="radio_form">
        <input id="radio_form_1" name="Sales" type="radio" value="Sales" />
        <label for="radio_form_1">Sales</label>
        <input id="radio_form_2" name="Technical" type="radio" value="Technical" />
        <label for="radio_form_2">Technical</label>
    </div>

    <label for="name" class="formlabel">Comments:</label>
    <textarea name="comments" rows="5" cols="50" class="forminput"></textarea>
    <input id="submit" name="submit" type="submit" class="forminput" value="Submit" />
</fieldset>

.formlabel {
    clear:left;
    display:block;
    float:left;
    margin:0 0 1em 0;
    padding:0 0.5em 0 0;
    text-align:right;
    width:8em;
}

.forminput {
    float:left;
    margin:0 0.5em 0.5em 0;
}

fieldset {
    -webkit-border-radius:8px;
    -moz-border-radius:8px;
    border-radius:8px;
}

input, textarea {
    -moz-border-radius:5px;
    border-radius:5px;
    border:solid 1px #999;
    padding:2px;
}

#submit {
    background:grey;
    height:30px;
    width:100px;
    border:1px;
    color:white;
    font:family:Arial;
    font-weight:bold;
    font-size:15px;
    cursor:pointer;
}

#submit:hover {
    background:#4498e1;
}

#radio_form input {
    float: left;
}
#radio_form label {
    float: left;
}
#radio_form label + input {
    clear: both;
}

Answer №3

Check out this awesome Fiddle

#radio_form {
  float: left;
  margin-bottom: 13px;
}

input[type="radio"] {
  display: block;
  margin: 3px 7px 0 0;
}

Answer №4

One way to avoid dealing with floats is to use inline-block instead

http://jsfiddle.net/NpJ55/8/

.fieldwrap {
    margin: 15px 0;
}

.formlabel {
    display: inline-block;
    vertical-align: middle;
    text-align:right;
    width:8em;    
    font-size: 24px;
}

.radiolabel {
    display: inline-block;
    vertical-align: middle;
    font-size: 20px;
    margin-right: 15px;
}

.radio {
    display: inline-block;
    vertical-align: middle;
}

.forminput {
    display: inline-block;
    vertical-align: middle;
}

Answer №5

On the other hand, you could also include the following guideline:

#radio_form {
    float: left;
}

Check out this demo

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

Ways to troubleshoot the logic issue in the loop for my simple login interface

I have been able to successfully implement code that detects when a user enters an incorrect username or password, as well as granting access when the correct credentials are provided initially. However, there seems to be a logic error in my loop that prev ...

When using jQuery to focus on an input element, the cursor fails to show up

Looking to enhance user experience by focusing on an input element upon clicking a specific div. The HTML structure being used is as follows: <div class="placeholder_input"> <input type="text" id="username" maxlength="100" /> <div ...

The div "tags" cannot be positioned beneath the photo as it is automatically located alongside the image inside the div

Is there a way to place the "Tags" div beneath an image, creating a bar of tags below it? I've been struggling to position it properly without disrupting the flow of the page. Using absolute positioning is not an option as it would break the layout. A ...

Unexpected results with mix-blend-mode difference

I am struggling with making a black text element overlap a black div while ensuring that the overlapping part of the text appears white. I attempted to use the mix-blend-mode property, but it does not seem to be working as expected. Why is this happening? ...

Utilizing AngularJs to differentiate between arrays and strings within an HTML template

I'm currently facing a challenge with creating a dynamic HTML template. In order to present data in a table, I need to distinguish between a regular String and an Array. Firstly, the HTML template is embedded within another template using the data-ng- ...

Exploring the Power of Websharper with Sitelets and Forms

I have been working on developing a form using Websharper to gather user input. Currently, I have identified three actions for my website: type MyAction = | [<CompiledName "">] Index | [<Method "POST">] GetUser of username : string ...

Background Image Division (Twitter Bootstrap)

I am facing a challenge while creating a module with a span8 width and varying height. The div contains an image that dictates its height, with text overlaid on the image. My issue lies in preventing part of the image from getting cropped when Bootstrap re ...

Displaying image titles when the source image cannot be located with the help of JavaScript or jQuery

I am currently facing an issue where I need to display the image title when the image is broken or cannot be found in the specified path. At the moment, I only have the options to either hide the image completely or replace it with a default image. $(&apo ...

Display a division upon choosing an option

I am working on a project that involves a selection menu in the form of a drop-down list. <select> <option id="one" value="something">Car</option> <option id="two" value="anything">Plane</option> </select> Also, I ...

What is the best way to design a bookmarklet that can overlay an HTML/div layer and apply CSS styles from an

Is there a way to incorporate a bookmarklet that can bring in a new layer/div with additional HTML and CSS from an external file, overlaying it on the current page? If anyone has an example of a bookmarklet that achieves this, would you be willing to shar ...

Tips for aligning an element to the bottom of its container

Can you please make some major edits and then re-open? I am currently developing a page using Bootstrap 2.3.2, which will eventually serve as a template for Joomla 3.x. Within the header section, I have successfully positioned 6 elements as per the desi ...

The tabbing feature in bxslider disrupts the alignment of slides, making it

After encountering accessibility issues, I upgraded the bxslider library to version 4.2.3 for better support. Check out this example of bxslider where you can easily tab through the controls: http://jsfiddle.net/qax7w8vt/2/embedded/result/ The problem a ...

simultaneous image hover effect for all images

I am experiencing an issue with my CSS and Bootstrap hover effect. The overlay tags are enclosed within a div class, but they all hover simultaneously. Each overlay belongs to a different Bootstrap grid, yet the effect extends even to the empty spaces betw ...

The sliding div unites with the bottom button, rather than the top one

When hovering over the upper left button, a div with sample description slides down. However, I am facing two challenges that I cannot seem to resolve. The description is supposed to merge with the second button but instead merges with the first one. I a ...

Unable to conduct this search with Python using Selenium on a website

I have written a script to search for books on a webpage using Selenium: from selenium import webdriver from selenium.webdriver.common.keys import Keys import time PATH = "C:\Program Files (x86)\chromedriver.exe" driver = webdriver.Chrome(PATH) ...

Issues with creating modal images using only JavaScript

I am facing an issue with modal popup images. I have a collection of images and attempted to implement this code (with some modifications): https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal_img However, it seems to only work for the initi ...

PHP table not displaying data

I am brand new to this and currently enrolled in a class with an unhelpful professor. I am attempting to read data from a file into a table, but for some reason the data is not displaying. I have tried multiple approaches, but I am feeling quite lost. Any ...

Utilizing nested createHtmlOutputFromFile in Google Apps Script HtmlService to generate jQuery code

Embarking on a new journey, I am diving headfirst into the world of JQuery WebApp with Google Apps Script. Every day is filled with new discoveries and excitement as I immerse myself in learning to piece things together. Starting off with some examples an ...

Adding an Icon to a Tab in Ant Design - A Step-by-Step Guide

Is there a way to include an icon before the title of each open tab? I am currently using the antd library for tab creation, which doesn't provide a direct option for adding icons. Here is my code snippet along with a link to the jsfiddle https://jsfi ...

Issues arising from the event target

What is the reason behind this code functioning successfully only when the alert function is called? The color changes after closing the alert box, but if the line with the alert command is commented out, nothing happens. function setLinkColor(el) ...