Trying to get radio buttons, questions and answered centered in the middle of the page any help wud be great here is my code!!
<form action='process.php?id=1' method='post' id='quizForm' id='1' onSubmit='validateForm()' name='myForm'>
<ol>
<li>
<h3>1 x 1 =</h3>
<div>
<input type='radio' name='answerOne' id='answerOne' value='A' />
<label for='answerOneA'>A)1</label>
</div>
<div>
<input type='radio' name='answerOne' id='answerOne' value='B' />
<label for='answerOneB'>B)2</label>
</div>
<div>
<input type='radio' name='answerOne' id='answerOne' value='C' />
<label for='answerOneC'>C)3</label>
</div>
</li>
<li>
<h3>1 x 6 =</h3>
<div>
<input type='radio' name='answerTwo' id='answerTwo' value='A' />
<label for='answerTwoA'>A)5</label>
</div>
<div>
<input type='radio' name='answerTwo' id='answerTwo' value='B' />
<label for='answerTwoB'>B)6</label>
</div>
<div>
<input type='radio' name='answerTwo' id='answerTwo' value='C' />
<label for='answerTwoC'>C)4</label>
</div>
</li>
<li>
<h3>2 x 8 =</h3>
<div>
<input type='radio' name='answerThree' id='answerThree' value='A' />
<label for='answerThreeA'>A)14</label>
</div>
<div>
<input type='radio' name='answerThree' id='answerThree' value='B' />
<label for='answerThreeB'>B)12</label>
</div>
<div>
<input type='radio' name='answerThree' id='answerThree' value='C' />
<label for='answerThreeC'>C)16</label>
</div>
</li>
</ol>
<input type="submit" />
</form>
I have created basic fiddle for you with an example solution, check if that is what you need.
http://jsfiddle.net/bhd2C/
I have simply put your form into a div for which I have created simple css class:
.content {
width:100%
margin:0 auto;
text-align:center;
}
<form style='text-align:center' action='process.php?id=1' method='post' id='quizForm' id='1' onSubmit='validateForm()' name='myForm'>
<ol style='list-style-position:inside;'>
Changing first two lines would work. Setting text-align property to 'center' makes what is inside centered in the container. "list-style-position:inside;" code makes list styles( 1., 2. etc.) appear in normal flow so that they are also centered.
Note: text-align centers your content in the middle of container. That's, your container should be 100% width if you want to locate your content in the middle of the page.
Also note that when using css, internal or external style would be better instead of inline style( used in the code above) if you use it in other forms and lists.
Result
Ways to insert css
How to create centered ordered list with HTML/CSS?
Related
I want to prevent irregular gaps between my inputs and my text. How should I do this with a CSS property?
For example that my input will be placed all over that red line:
My HTML:
<body>
<div>
<p class ="LabelInput">Programme/CP/Ville
<input type="text" id="cp" name="cp"
placeholder="" />
</p>
</div>
<div class = "Typologie">
<p class ="LabelInput">Typologie
<input type="checkbox" id="Studio" name="Studio" checked />
<label for="Studio">Studio</label>
<input type="checkbox" id="T2" name="T2" checked />
<label for="T2">T2</label>
<input type="checkbox" id="T3" name="T3" checked />
<label for="T3">T3</label>
<input type="checkbox" id="T4" name="T4" checked />
<label for="T4">T4</label>
<input type="checkbox" id="T5P" name="T5P" checked />
<label for="T5P">T5P</label>
</p>
</div>
<div class = "Type">
<p class ="LabelInput">Type
<input type="checkbox" id="Appartement" name="Appartement" checked />
<label for="Appartement">Appartement</label>
<input type="checkbox" id="Maison" name="Maison" checked />
<label for="Maison">Maison</label>
<input type="checkbox" id="Commerce" name="Commerce" checked />
<label for="Commerce">Commerce</label>
<input type="checkbox" id="Parking" name="Parking" checked />
<label for="Parking">Parking</label>
</p>
</div>
<div class = "Budget">
<p class ="LabelInput">Budget
<div id="slider-range"></div>
</p>
</div>
<div class = "Livraison">
<p class ="LabelInput">Livraison
<input type="text" id="cp" name="cp"
placeholder="" />
</p>
</div>
<div class = "Annexes">
<p class ="LabelInput">Annexes
<input type="text" id="cp" name="cp"
placeholder="" />
</p>
</div>
I'm sure it is something you can do but I can't remember or find the property.
You will need to make some adjustments to your HTML for the best results.
As p is not allowed to contain block-level elements, you can not put divs in it as seen in your Budget section.
Form the w3 site:
The P element represents a paragraph. It cannot contain block-level elements (including P itself).
Instead, add two div wrappers around your label and your content for a clean solution:
.LabelInput {
width: 30%;
display: inline-block;
}
.LabelContent {
width: 69%;
display: inline-block;
}
<div class = "Type">
<div class="LabelInput">Type</div>
<div class="LabelContent">
<input type="checkbox" id="Appartement" name="Appartement" checked />
<label for="Appartement">Appartement</label>
<input type="checkbox" id="Maison" name="Maison" checked />
<label for="Maison">Maison</label>
<input type="checkbox" id="Commerce" name="Commerce" checked />
<label for="Commerce">Commerce</label>
<input type="checkbox" id="Parking" name="Parking" checked />
<label for="Parking">Parking</label>
</div>
</div>
If you do not want to change your html, add a wrapper element like span around your label and set min-width on it. That is an easy, albeit dirty solution.
<div class="LabelInput"><span class="myLabel">Type</span></div>
.myLabel {
min-width: 200px //adjust as needed to size of biggest label
display: inline-block;
}
This code is expected to show 2 radio buttons group where they "the group" is shown horizontally as well as "the button to the left of the caption" but I am getting the first effect but now how can I get it so that the button icon is located to the left of their corresponding caption? Thanks
edit
I am not using bootstrap up the html chain.
.list-item {
margin: 1em 1em;
}
<div class="list-item">
{{> sub}}
</div>
<template name="sub">
<label>
<input type="radio" name="mygroup" />
My caption 1
</label>
<label>
<input type="radio" name="mygroup" />
My caption 2
</label>
</template>
Like this maybe?
.list-item {
margin: 1em 1em;
}
Vertical <br>
<div class="list-item">
<label>
<input type="radio" name="mygroup" /> My caption 1
</label>
</div>
<div class="list-item">
<label>
<input type="radio" name="mygroup" /> My caption 2
</label>
</div>
Horizontal <br>
<div class="list-item">
<label>
<input type="radio" name="mygroup" /> My caption 1
</label>
<label>
<input type="radio" name="mygroup" /> My caption 2
</label>
</div>
You can set the input to position:absolute; and set a padding-left on the label, it works wonders :)
Edit: you might have to set position relative on the labels.
I am doing some work and have a form which I want to look like a list (think <ul> format, just without the bullets).
However, right now all the inputs are inline with each other:
Item 1 Item 2 Item 3 etc
I want it to look like:
Item 1
Item 2
Item 3
etc
Code:
<form action = "display.php" method = "post">
<h1>My form</h1>
<input type="checkbox" name="movie[]" value="action" />
<label for="male">action</label>
<br><br>
<input type="checkbox" name="movie[]" value="adv" />
<label for="male">adv</label>
<br><br>
<h1>My form</h1>
<input type="checkbox" name="movie[]" value="com" />
<label for="male">com</label>
<br><br>
<input type="checkbox" name="movie[]" value="rom" />
<label for="male">rom</label>
<br><hr>
<input type="submit" id="submitbutton" name="search" value="Submit">
</form>
I was also wondering if I could move the submit button and put it at the bottom of the page, so the form was on the top half of the page and then I wanted to move the button in the middle, how that would be possible? Right now the form is in a perfect position, but I would like to move the button so it's on the bottom half of the page in the middle.
Thanks again for the help.
TL:DR; http://codepen.io/anon/pen/YqQvoE (here is the code you need)
Long(er) explanation:
I would recommend just putting <br /> tags between your lines. There are several ways to go about it, but that is the easiest way.
As for the button being centered at the bottom, just apply the following CSS to it (and make sure to set the id of the button accordingly):
#submitbutton {
display:block;
margin:auto;
}
(also, your <form> tag needs to be closed)
By the way, as a best practice issue, make sure the for="" for each <label> is different. It should correspond to the name="" of the label's associated <input>.
You need to close your form as well as your div. Also, surround the button in its own special span or div that has absolute positioning. Check out this example:
<form action = "display.php" method = "post">
<input type="checkbox" name="movie[]" value="action" />
<label for="male">action</label>
<input type="checkbox" name="movie[]" value="adv" />
<label for="male">adv</label>
<input type="checkbox" name="movie[]" value="com" />
<label for="male">com</label>
<input type="checkbox" name="movie[]" value="rom" />
<label for="male">rom</label>
<span style="position: absolute; bottom: 0px; right: 0px; left: 0px; text-align: center;">
<input type="submit" name="search" value="Submit">
</span>
</form>
I'm working on a One Pager website where I have a navigation menu. I'd want to have radio input associated to the clicked a, in order to apply some CSS to the active radio.
As you will see, the CSS is applied when I click on the radio, but not when I click on the link. I know I could do this using JavaScript, but I am trying to avoid growing my code base.
The second section of the snippet is what I'd want to achieve, but with an a tag in the label. The radio will be hidden, so clicking on the radio isn't an acceptable answer. How can I make the a tag and the input tag activate?
input[type=radio]:checked + label {
color:red;
background-color:green;
}
.working {
visibility: hidden;
width:0;
}
<html>
<body>
<div>
<h2>Not working with a tag</h2>
<div>
<input id="a" type="radio" name="menu1" value="a"/>
<label for="a">Input 1</label>
</div>
<div>
<input id="b" type="radio" name="menu1" value="b"/>
<label for="b">Input 2</label>
</div>
</div>
<div>
<h2>Expected result (without a, it doesn't work)</h2>
<div>
<input class="working" id="c" type="radio" name="menu2" value="a"/>
<label for="c">Input 1</label>
</div>
<div>
<input class="working" id="d" type="radio" name="menu2" value="b"/>
<label for="d">Input 2</label>
</div>
</div>
</body>
</html>
Right solution is here , try this.
<script type="text/javascript">
$(document).ready(function(){
$('[name=title_format]').click(function() {
$('[name=doc-title]').val('Title changed to '+$(this).val());
});
});
</script>
<style>
input[type=radio]:checked + label {
color:red;
background-color:green;
}
.working {
width:0;
}
</style>
<div>
<h2>Not working with a tag</h2>
<div>
<a href="#">
<input type="radio" name="title_format" class="title-format" id="title-format-0" value="0" checked="checked"> <label for="title-format-0">Input 1</label>
</a>
</div>
<div>
<a href="#">
<input type="radio" name="title_format" class="title-format" id="title-format-1" value="1">
<label for="title-format-1">Input 2</label>
</a>
</div>
</div>
<div>
<h2>Expected result (without a, it doesn't work)</h2>
<div>
<input class="working" id="c" type="radio" name="menu2" value="a"/>
<label for="c">Input 1</label>
</div>
<div>
<input class="working" id="d" type="radio" name="menu2" value="b"/>
<label for="d">Input 2</label>
</div>
</div>
Here's a working example of the label syntax: https://jsfiddle.net/93c3sscs/
If you're testing on IE11 or your customers use IE (not sure about Edge and other IE versions), you can't rely on labels to activate inputs. IE does not apply clickable functionality to <label><input></label>, and Microsoft put out 2 updates in the second half of 2015 that completely broke my app because of this by positioning the clickable area 5px above my widget sprites.
Browser is Firefox.
I have a list of 15 radio buttons. After displaying them like this:
<div class="abcd" style="margin-left:10px;">
<form id='some'....>
<legend>Select Item type :</legend>
<fieldset style="display:block;float:left;">
<input class="yy" id="sss" type="radio" name="group0" value="aaa"/> ABC
...
</fieldset>
<p>
<input placeholder="Enter Name/Value" name="xxx" id="xxx" size="40" style="display:block;float:left;">
<button type="button" id="xxx" style="width:100;">Process</button>
</p>
</form>
</div>
Everything is displaying in one line. I am not sure how to display the textbox under radio buttons with some space in between.?
pl help.
The problem with your style is the float: left, you have to clear the "floatness".
At the p tag, include the clear:both, it tells the browser that nothing can float at its left or right.
<div class="abcd" style="margin-left:10px;">
<form id='some'>
<fieldset style="display:block;float:left;">
<input class="yy" id="sss" type="radio" name="group0" value="aaa"/> ABC
<input class="yy" id="sss" type="radio" name="group0" value="aaa"/> ABC
<input class="yy" id="sss" type="radio" name="group0" value="aaa"/> ABC
</fieldset>
<p style="clear:both">
<input placeholder="Enter Name/Value" name="xxx" id="xxx" size="40" style="display:block;float:left;">
<button type="button" id="xxx" style="width:100;">Process</button>
</p>
</form>
</div>
paste
<div style="clear:both"></div>
after the fieldset.
When using the float attribute you have to clear it so that other elements won't appear floating next to it. try adding clear: both to the css of the input box like this:
<input placeholder="Enter Name/Value" name="Name" id="NameID" size="40"
style="clear:both; display:block;"/>
Try adding the css rule to the radio buttons themselves. Like this:
<style type="text/css">
.group0
{
display:block;
}
</style>
This assumes group0 is the group with all the radio buttons.