How to center input radio - css

I'm using jquery mobile for my project. It automatically converts all radio buttons in its inputs with its styles. The major problem is that in different situations i have different number of buttons (it depends on user) with its different width and i need it every time center.
<div data-role="fieldcontain" id="inline" >
<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
{section name=i loop=$data['input'] start=0}
<input name="position" id="radio{$smarty.section.i.index}" value="{$data['input'][i]}" type="radio" />
<label for="radio{$smarty.section.i.index}">
{$data['input'][i]}
</label>
{/section}
</fieldset>
</div>
As you see each button has his size (for example Up and Zoom In are different). As i said before - i don't know what buttons will be for each users - it depends on their own settings, so i need somehow automatize process of centering it - is some ideas?

You could try it with <a> instead of <input> as done in the documentation, if at all possible in your situation.

Related

USWDS - How to align form labels to the left of inputs?

I'm using the
U.S. Web Design System (USWDS)
in a project I'm working on, and I'm struggling with something that seems superficially like it should be quite simple: How can I align form labels so they appear to the left of their corresponding inputs, instead of above them?
Some other CSS libraries call this a horizontal form but I've also seen it referred to as "inline" fields.
According to this answer it's possible to achieve the result I want using modern CSS Grid layout, but so far I haven't figured out how to make that play nicely with the USWDS styling, which does not use CSS Grid.
Can anyone help me to either:
Create a horizontal form using some combination of USWDS components and utility classes, or if that's impractical...
Produce a horizontal form by overriding the USWDS styling with custom CSS, but without causing too much conflict or breaking with the standard?
Below is a simplified snippet of my HTML:
<link href="https://cdn.jsdelivr.net/npm/uswds#2.8.0/dist/css/uswds.min.css" rel="stylesheet" />
<form class="usa-form">
<div class="usa-form-group">
<label class="usa-label" for="somefield1">Sample label</label>
<input class="usa-input" type="number" name="somefield1" value=0 />
</div>
<div class="usa-form-group">
<label class="usa-label" for="somefield2">Another label</label>
<input class="usa-input" type="number" name="somefield2" value=0 />
</div>
</form>
You can use flex on the usa-form-group to get them positioned next to each other as shown in this Code Sandbox, with some other minor touchups to the element margins https://codesandbox.io/s/nostalgic-moon-q7i7f?file=/styles.css

<legend> tag is not read by Windows Narrator

Windows Narrator doesn't read legend tag inside fieldset. At the same time legend is read by NVDA and JAWS properly. Markup is the following:
<fieldset>
<legend>Description</legend>
<label>
<input id="option1"type="radio" value="1">
Option 1
</label>
<label>
<input id="option1" type="radio" value="2">
Option 2
</label>
</fieldset>
Is there a way to make Narrator read legend?
Screen reader support for <legend> has always been spotty, and it's very difficult if not impossible to target one piece of assistive technology (e.g. Narrator) while not affecting other applications (e.g. NVDA and JAWS).
However, you can attempt to more explicitly convey the context of the legend element by inserting visually hidden text inside the label elements. This will supplement additional information for non-sighted users that isn't visible. Techniques include positioning content off-screen or using CSS clip-path.
<fieldset>
<legend>Billing Address:</legend>
<div>
<label for="billing_name">
<span class="visuallyhidden">Billing </span>Name:
</label><br>
<input type="text" name="billing_name" id="billing_name">
</div>
<div>
<label for="billing_street">Street:</label><br>
<input type="text" name="billing_street" id="billing_street">
</div>
[…]
</fieldset>
Also note that different screen readers behave in sometimes incongruous ways. It's not impossible to get them to behave all the same, so we have to "split the difference" and attempt to make a reasonable accommodation for all, even if it's not perfect in every instance.
Depending on the configuration, some screen readers read out the legend either with every form element, once, or, rarely, not at all. To accommodate this consider the following:
Make the legend as short as possible for situations in which it is read together with the label each time.
Make the individual labels sufficiently self-explanatory for situations in which legends are not read aloud, without repeating the legend in every label.
https://www.w3.org/WAI/tutorials/forms/grouping/

CSS Change color based on attribute of closest class

This process has been driving me nuts. I am trying to make foundations abide system look nicer. I have created a system that replaces the error class with a success and error system. Everything works well except I am having an issue displaying the success once the field is checked.
HTML
<form data-abide="ajax" id="addNewUser" novalidate="novalidate">
<div>
<label class="label" for="fname"><span class="requiredRed">*</span> First Name</label>
<input type="text" id="fname" name="fname" required="" value="Douglas" aria-invalid="false">
<div class="fa fa-info-circle errspan fail" style=""><div><p>You must enter a First Name</p></div></div>
<div class="fa fa-check-circle errspan success"></div>
</div>
</form>
I have been trying to find if there is a easy way through css to display success based on the 'aria-invalid' attribute such as.
[data-abide] input[aria-invalid='false'] + div.success{ display:block; }
Very hard to figure out what you mean. If some JavaScript handler is triggered only once, but no longer afterwards, the handler often needs to be reattached. For example if there is a button in an ajax panel the click event handler must be added to the button any time the panel is reloaded. Is it such a kind of problem?
I solved my own issue. I was missing a + div
[data-abide] input[aria-invalid='false'] + div + div.success{ display:block; }

Is it possible to change jquery mobile form elements , increase sizes by JS in %

I want to resize jquery mobile form elements that I am using Phonegap in mobile App. Now I want to resize and give more height to form elements based on some number or percentage which will depend upon screen size. I know jquery Mobile handle width by itself but I want to give height via JS so that all form elements' height increase by that specific ratio/percentage.
I know that JQuery Mobile CSS can be changed but I want to change height using JS on runtime not setting CSS once. So what is best way to do this?
I actually want to get screen size and give size to all elements according to some percentage. While if I see at jQuery Mobile CSS then there are a lot of thing that I need to set, and still not sure if it will be set. So is there some way to do that without modifying or rewrite whole CSS? Or I just need to write custom CSS and form elements ?
Any suggestion and effort will be appreciated.
Here is a fiddle demonstrating this with input elements: http://jsfiddle.net/ezanker/akgEa/
In this example I have 3 inputs of type text and a button which doubles their height each time you click it. The button iterates through each input, gets its current height and then sets the height to 2 times current.
<div data-role="fieldcontain">
<label for="textinput-fc1">Text Input:</label>
<input type="text" name="textinput-fc1" id="textinput-fc1" placeholder="Text input" value="" />
</div>
<div data-role="fieldcontain">
<label for="textinput-fc2">Text Input:</label>
<input type="text" name="textinput-fc2" id="textinput-fc2" placeholder="Text input" value="" />
</div>
<div data-role="fieldcontain">
<label for="textinput-fc3">Text Input:</label>
<input type="text" name="textinput-fc3" id="textinput-fc3" placeholder="Text input" value="" />
</div>
<input id="btnSet" type="button" value="Set Heights" data-theme="a" />
$('#btnSet').on("click", function(e){
$("[type='text']").each(function( index ) {
var curH = $(this).height();
$(this).height(curH * 2);
});
});
NOTE: depending what type of form elements you are using, setting height will not work for all of them. I suggest you look in the inspector at the generated code for your form and see what is the best way o set the height for each element type.

Radio Button not working in webkit browsers

the problem is simple to explain, i have done a form, but the radio buttons are not showing in safari, and in chrome they are showing but they're not clickable.Is it a problem of css? The radio buttons are just as normal as they should:
<input type="radio" name="message" value="x" checked> Option
What am I doing wrong?
Agnese
Check if there are any elements overlapping, maybe you used floating without a clearfix which means your browser does not get the height of your form?
<input type="radio" name="message" value="x" checked="true"> Option
Try this. The checked needs to be set and not left empty.
Refer to the image below to see it in action. Tested on W3Shools itself.

Resources