How to align radio button to the left of my text? - html

So for my raid buttons, I want them to align to the right of my text, like other elements above, but I cant figure out how.
Here is the fiddle and code I have for my buttons.
<label>What kind of Ice Cream you like?</label>
<label><input type="radio" name="icecream" value="choco" id="radio"> Chocolate</label><br>
<label><input type="radio" name="icecream" value="vanil" id="radio">Vanilla</label><br>
<label><input type="radio" style="vertical-align: middle" name="icecream" value="rocky" id="radio">Rocky Road</label><br>
https://jsfiddle.net/russiandobby/gfj1nper/4/
I tried many ways but my radio buttons either end up under the text or messed up order like that.

Try using an id for each radio, like this:
<div>
<label for="chocolate">Chocolate</label>
<input type="radio" name="icecream" value="choco" id="chocolate">
</div>
*edited

<input type="radio" name="icecream" value="choco" id="chocolate">
<label for="chocolate">Chocolate</label>
<input type="radio" name="icecream" value="choco" id="vanila">
<label for="vanila">Vanila</label>
the name attribute should have same value rather than the id's having same value

You'll need to mess with the styling more to align everything exactly how you want it, but to get the radio inputs to the right of the text simply put the <input> element after the <label> element.
At the moment your <label> is wrapping the input. Place it wholly before the <input> element.
Additionally: for usability and accessibility, clicking the label should trigger your radio input. To enable this set a for="" attribute on each label that matches a unique id="" attribute for each input.
<label for="choco">Chocolate</label><input type="radio" name="icecream" value="choco" id="choco">
<label for="vanil">Vanilla</label><input type="radio" name="icecream" value="vanil" id="vanil">
<label for="rocky">Rocky Road</label><input type="radio" style="vertical-align: middle" name="icecream" value="rocky" id="rocky">

Try These Solutions
body{
background-color:#42f4e2;
}
#title{
text-align:center;
font-family: 'Lobster', cursive;
font-size: 50px;
}
#mainform{
background-color:#e8ecf2;
margin-top: 20px;
margin-right: 20px;
margin-bottom: 20px;
margin-left: 20px;
border-radius: 10px;
}
label{
display: inline-block;
width: 140px;
text-align: right;
margin-right: 40px;
margin-top: 20px;
}
#survey-form{
display: block;
margin-left: auto;
margin-right: auto;
width: 95%;
text-align:center;
}
select{
display: inline-block;
height:30px;
text-align: right;
margin-right: 40px;
margin-top: 20px;
}
.redio-wrap label{
display: inline-block;
margin-right: 10px;
width: auto;
}
.redio-wrap label:first-child{
width: 140px;
margin-right: 40px;
}
<h1 id="title">Survey Form</h1>
<div id="mainform">
<form action="/action_page.php" method="get" id="survey-form">
<label>*First name:</label> <input type="text" name="fname" placeholder="Enter your name"><br>
<label>*Email:</label> <input type="text" name="email" placeholder="Enter your Email"><br>
<label>*Age:</label> <input type="text" name="age" placeholder="Enter your Age"><br>
<!--For the Drop Down menu-->
<label>Describe your mood:</label>
<select>
<option value="" disabled selected>Select your option</option>
<option value="happy">Happy</option>
<option value="sad">Sad</option>
<option value="angry">Angry</option>
<option value="neutral">Neutral</option>
</select><br>
<!--For the Drop Down menu end-->
<!--Radio buttons start-->
<div class="redio-wrap">
<label>What kind of Ice Cream you like?</label>
<label><input type="radio" name="icecream" value="choco" id="radio"> Chocolate</label>
<label><input type="radio" name="icecream" value="vanil" id="radio">Vanilla</label>
<label><input type="radio" style="vertical-align: middle" name="icecream" value="rocky" id="radio">Rocky Road</label>
</div>
</form>
</div>

I had the same problem, and upon reviewing I found the following to solve the problem, which I applied to your ice cream variables:
First, in the HTML window, apply the following:
<div class="rowTab">
<div class="labels">
<label for="ice cream Type"> What kind of Ice Cream you like?</label>
<div/>
<div class="rightTab">
<ul style="list-style: none;">
<li class="radio">
<label>Chocolate<input name="radio-buttons"
value="1" type="radio" class="ice cream Type"></label></li>
<li class="radio">
<label>Vanilla<input name="radio-buttons"
value="2" type="radio" class="ice cream Type"></label></li>
<li class="radio">
<label>Rocky Road<input name="radio-buttons"
value="3" type="radio" class="ice cream Type"></label></li>
THEN, in the CSS window apply the following:
.ice cream type,
input[type="checkbox"] {
float: right;
margin-right:??px;
}
In this case, from the HTML window you are defining the class 'ice cream type' for each flavor, then in the CSS window you are styling it with 'float: right;' which should put the radio buttons to the RIGHT of each flavor's name..

Related

How to align left my radio buttons and checkboxes like I can do it easily with paragraphs?

And I used margin-right:-9rem; in input element. But it didn't sound its good approach to me, idk why. But is there a better option how do do it? I was just trying my radio button and checkboxes near the boxes.
I have been trying to do survey form to practice my html and css knowledge. Please help me.
body {
background-color: rgb(25, 230, 161);
font-family: Arial, Helvetica, sans-serif;
text-align: center;
}
h1 {
font-weight: bold;
color: white;
margin-top: 2rem;
}
#description, #welcome {
font-style: italic;
font-size: 1.1rem;
}
main {
width: 60%;
border: 2px solid red;
margin: 0 auto;
text-align: left;
padding: 1rem 2rem; /*margin moves the border, padding changes the inside elements, not position of border.*/
}
label {
display: block; /*make labels one under the other */
padding-bottom: .3rem;
padding-top: 1rem;
}
input {
width:20rem;
margin-right: -9rem;
}
[for="dropdown"] {
margin-top: 1rem;
}
p {
margin-bottom: 0;
}
<body>
<h1 id="title">LearningHtmlCss Course Survey Form</h1>
<p id="description">This survey page is built for gathering information about people taking this course. So that we can improve our site.</p>
<p id="welcome">Thank you for taking time to help us improve the platform</p>
<main>
<form id="survey-form">
<label for="name" id="name-label">Name</label>
<input type="text" id="name" name="name" placeholder="Enter your name" required>
<label for="email" id="email-label">Email</label>
<input type="email" id="email" name="email" placeholder="username#gmail.com" pattern=".+#gmail.com" title="Please provide only gmail address" placeholder="Enter your email" required> <!--email validation-->
<label for="age" id="number-label">Age</label>
<input type="number" id="age" min="7" max="99" placeholder="between 7, and 99" required>
<label for="dropdown">Which option best describes your current role?</label>
<select name="current role" id="dropdown">
<option>Select current role</option>
<option value="student">Student</option>
<option value="job">Full time job</option>
<option value="learner">Full time learner</option>
<option value="not to say">Prefer not to say</option>
<option value="other">Other</option>
</select>
<p>Would you recommend LearningHtmlCss course to a friend?</p>
<label>
<input type="radio" name="option" value="Definitely" checked>Definitely
</label>
<label>
<input type="radio" name="option" value="Maybe">Maybe
</label>
<label>
<input type="radio" name="option" value="Not sure">Not sure
</label>
<p>What would you like to see improved?</p>
<label>
<input type="checkbox" name="front-end" value="front-end">Front-end projects
</label>
<label>
<input type="checkbox" name="back-end" value="back-end">Back-end projects
</label>
<label>
<input type="checkbox" name="forum" value="forum">Forum
</label>
<label>
<input type="checkbox" name="videos" value="videos">Videos
</label>
<label>
<input type="checkbox" name="city-meetups" value="city-meetups">City Meetups
</label>
<label>
<input type="checkbox" name="additional" value="additional">Additional courses
</label>
<label for="comments">Any comments or suggestions?</label>
<input type="textarea" name="comment" id="comments" placeholder="Enter your comment here...">
<button type="submit">Submit</button>
</form>
</main>
</body>
In order to correct the position of the radio and the checkbox of the buttons, you need to replace the css rules of this input:
input {
width: 20rem;
margin-right: -9rem;
}
Replace with this one:
input {
width: auto;
margin: 0 5px 0 0;
}

How do I horizontally align a group of radio buttons (and labels) when using display:flex to stack them side by side

I have used display:flex to style a number of radio buttons so that they appear side by side, rather than in one long column. I thought by using margin:auto in combination with this, the child elements would appear grouped but in the center of the page horizontally. Clearly this isn't the case, so any help would be appreciated please.
Here is what I have currently:
input[type="radio"] {
display: none;
}
input[type="radio"]:checked + label {
background-color: red;
display: inline-block;
line-height: 4vw;
text-align: center;
width: 18vw;
}
label {
background-color: orange;
display: inline-block;
line-height: 4vw;
color: white;
text-align: center;
width: 18vw;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<section style="display:flex; margin:auto;">
<div>
<p>Amount:</p>
</br>
<input type="radio" name="Amount" id="Amount1" value="single" / checked>
<label for="Amount1">Amount 1</label>
</br>
</br>
<input type="radio" name="Amount" id="Amount2" value="multi" />
<label for="Amount2">Amount 2</label>
</div>
<span style="width:5vw;display:inline-block"></span>
<div>
<p>Term:</p>
</br>
<input type="radio" name="Term" id="Term1" value="0" / checked>
<label for="Term1">Term 1</label>
</br>
</br>
<input type="radio" name="Term" id="Term2" value="1" />
<label for="Term2">Term 2</label>
</div>
<span style="width:5vw;display:inline-block"></span>
<div>
<p>Phone:</p>
</br>
<input type="radio" name="Phone" id="Phone1" value="0" / checked>
<label for="Phone1">Phone 1</label>
</br>
</br>
<input type="radio" name="Phone" id="Phone2" value="1" />
<label for="Phone2">Phone 2</label>
</div>
</section>
I have used viewport width throughout the project, as I have further CSS styling to change element sizes based on media queries. So I need a solution that still keeps this styling if possible.
Using the following should help:
justify-content: center
On the display:flex class.
Source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Align Radio-Buttons and its Labels

I am getting crazy right now since i try to style my radio buttons for hours now and i cant reach my goal (im completely new to the world of css).
What i want to do is simple:
I want three big radiobuttons underneath each other centered in my div with labels vertically aligned to the buttons. something similar to this:
I have the following html:
<div class="answers">
<label>
<input type="radio" name="answers" value="male" /> All
</label>
<label>
<input type="radio" name="answers" value="female" /> Name
</label>
<label>
<input type="radio" name="answers" value="male" /> Vendor No.
</label>
</div>
And the result is this:
I want much bigger buttons and much bigger text. i want the text to be to the right of the buttom with a little padding. i want all radio buttons to be centered. I tried many things but everything was just looking weird. Pls help me... i am beginning to hate css....
You can use this CSS:
.answers label {
display: block;
font-size: 20px;
line-height: 30px;
margin: 0 auto;
width: 150px;
}
.answers {
width: 100%;
}
.answers input[type="radio"] {
height: 30px;
line-height: 30px;
vertical-align: bottom;
width: 30px;
}
JSFiddle: http://jsfiddle.net/ghorg12110/uqyfbjsb/
The only reason to happen this is to have display: block somewhere in your css to radios:
input[type=radio] {
display: block;
}
<div class="answers">
<label>
<input type="radio" name="answers" value="male" />All
</label>
<label>
<input type="radio" name="answers" value="female" />Name
</label>
<label>
<input type="radio" name="answers" value="male" />Vendor No.
</label>
</div>
You can add display: block to second label using nth-child:
label:nth-child(2) {
display: block;
}
<div class="answers">
<label>
<input type="radio" name="answers" value="male" />All
</label>
<label>
<input type="radio" name="answers" value="female" />Name
</label>
<label>
<input type="radio" name="answers" value="male" />Vendor No.
</label>
</div>
References
nth-child
http://jsfiddle.net/6b888vp8/2/
Add display: block to the label in the answers div, and float left to the inputs. HTML has changed too
.answers label {
display: block
}
.answers input[type="radio"] {
float: left;
}
<div class="answers">
<input type="radio" name="answers" value="male" /><label>All</label>
<input type="radio" name="answers" value="female" /><label>Name</label>
<input type="radio" name="answers" value="male" /><label>Vendor No.</label>
</div>
This one worked for me:
input[type="radio"]{
width: 50px !important;
}
Try it out and check if it works for you as well.

Form elements out of place

I'm struggling placing my form elements where I like them to be.
I like my recurrence_interval input field below my select (recurrence) input field.
My two radio boxes for never and on. On top of each other and the input field for ends_on_date below the check box for "On".
My html is as below.
<div id="dialog" title="Create new appointment">
<form id="df">
<label class="align" for="title">Title</label>
<input type="text" name="title" id="title">
<label class="align" for="when">When</label>
<input type="text" name="when" id="when">
<input id="repeat" type="checkbox">
<label id="repeat_text" for="repeat">Repeat...</label>
<div id="repeat_properties">
<label class="align" for="recurrence">Repeats</label>
<select id="recurrence">
<option value="1">Daily</option>
<option value="7">Weekly</option>
<option value="repeat-x-days">Every x day</option>
</select>
<input id="recurrence_interval" type="text">
<label class="align" for="ends_never">Ends</label>
<input id="ends_never" name="endson" type="radio" title="Ends never" checked="checked">
<label for="ends_never" title="Ends never">Never</label>
<input id="ends_on" name="endson" type="radio" title="Ends never">
<label for="ends_never" title="Ends never">On</label>
<input class="align" id="ends_on_date" type="text">
</div>
</form>
</div>
My css is as below.
.align {
display: inline-block;
float: left;
clear: left;
width: 30%;
text-align: left;
}
input[type="text"], input[type="radio"], select {
display: inline-block;
float: left;
clear: right;
}
#repeat
{
display: inline-block;
float: left;
text-align: left;
clear: left;
}
#repeat_text
{
float: left;
}
Anyone got a clue about how I can archive the above?
Edit: As seen here, at least with chrome, the fields are clearly out of place.
change your HTML structure for radio, try using this.
<label for="ends_never" title="Ends never"><input id="ends_never" name="endson" type="radio" title="Ends never" checked="checked"> Never</label>
<label for="ends_never" title="Ends never"><input id="ends_on" name="endson" type="radio" title="Ends never"> On</label>
edited
try to add styling label { float : left; }

Inline class is not working as expected

i am beginner in css i am building a webpage in bootstrap . i want two labels Percentage and UpperLimit both to the same level i applied the inline class but unable to figure it out why there is level difference and how to correct it.
my html code is
<form class="form-horizontal">
<div class="control-group">
<label class="control-label">Promo Value</label>
<div class="controls">
<label class="radio inline" id="label1">
<input type="radio" name="optionsRadios1" id="optionsRadios4" value="option1" class="inline" checked>Percentage</label>
<label for="hello" class="inline" id="label2">Upper Limit
<input id="hello" type="text" class="inline" placeholder="Text input" disabled="true" />
</label>
<br />
<input type="radio" name="optionsRadios1" id="optionRadios6" value="option3">
<label class="radio inline" id="label3">Fixed Amount</label>
<input type="text" class="inline" placeholder="Amount Rs" disabled="true">
<hr class="hhhh"></hr>
</div>
</div>
</form>
and my main.css file is
.inline {
display:inline-block;
margin-right:20px;
}
.inline1 {
display:inline-block;
height: 50px;
vertical-align: middle;
margin-top: 2px;
}
and the screen shot is
as
as you can see the difference between label Upper Limit and Percentage is clearly visible how to resolve it help !!
The trick here is to over-ride some of the Bootstrap styles.
Here is one way of doing it. Modify your HTML slightly by keeping the labels and input fields separate (not nested). Use the "for" attribute to link the labels to the input fields.
<form class="form-horizontal">
<div class="control-group">
<label class="control-label">Promo Value</label>
<div class="controls">
<input type="radio" name="optionsRadios1" id="optionsRadios4" value="option1" checked>
<label class="radio inline" id="label1">Percentage</label>
<label for="hello" class="inline" id="label2">Upper Limit</label>
<input id="hello" class="inline" type="text" placeholder="Text input" disabled="true" />
<br />
<input type="radio" name="optionsRadios1" id="optionRadios6" value="option3">
<label class="radio inline" id="label3">Fixed Amount</label>
<input type="text" class="inline" placeholder="Amount Rs" disabled="true">
<hr class="hhhh"></hr>
</div>
</div>
</form>
I used the following CSS, making the selectors specific enough to override the Bootstrap styles.
.form-horizontal .control-group label.inline {
display: inline-block;
margin-right: 20px;
line-height: 30px;
vertical-align: baseline;
margin-top: 2px;
}
.form-horizontal .control-group input.inline {
vertical-align: baseline;
}
.form-horizontal .control-group .radio.inline {
padding-left: 10px;
}
.form-horizontal .control-group input[type="radio"] {
float: none;
display: inline-block;
vertical-align: baseline;
}
The gist of it is to make sure that the various inline elements are use vertical-align: baseline.
The styling is a bit complex, but it kind of works.
I did not try to place the .control-label element, but that should be easy enough.
The demo fiddle is: http://jsfiddle.net/audetwebdesign/PhqhS/