who can tell me why the radio button has this strange behaviour as you can see in the picture?
it's not aligned correctly.why there is that line? I didn't applied any css style.
here it is the html code:
<div class = "ui-grid-a">
<div class = "ui-block-a">
<div data-role="fieldcontain" class="ui-hide-label">
<label for"date">Birth Date</label>
<input type="datetime" name="dt" id="dt" value="" placeholder="Birth Date" style="width: 50%"/>
</div>
</div>
<div class = "ui-block-b">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<input type="radio" name="male" id="male" value="male" />
<label for="male">M</label>
<input type="radio" name="female" id="female" value="female" />
<label for="female">F</label>
</fieldset>
</div>
</div>
</div>
It appears as if the CSS controlling the fieldset surrounding your radio buttons is the culprit. I pulled the following from the default jQuery Mobile CSS.
.ui-controlgroup, fieldset.ui-controlgroup { padding: 0; margin: .5em 0 1em; }
There is a top margin of .5em and a bottom margin of 1em. Adjust those to see if it makes any difference at all.
Without seeing the css I can't say for sure, but it looks like you have a default margin set on that radio button. Try resetting it with this:
input {
padding: 0;
margin: 0;
}
JqueryMobile automatically adds margins to the constructs it creates. I'm guessing the fieldset tags or the radio buttons themselves have additional margins from the conversion. Try adding a height property to the parent div and see if that works.
Also, the line appears when you have a narrow viewport when you use the data-role="fieldcontain". If the viewport is wider, it automatically disappears. It's JqueryMobile's way of organizing stuff around. It's usually used to group a label and its control together, so you might get a better result by not using one in that particular row of controls.
Related
I am using some code from purecss.io to create some elegant looking forms. I am also using this code to have a simple rating system for my form.
However, when I combine the two together, the spacing on the rating looks very spaced out because of the CSS from purecss.io
How can I fix the spacing?
Here is the code:
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
<form action="" method="post" class="pure-form pure-form-aligned">
<fieldset>
<div class="pure-control-group">
<label for="foo">Supercalifragilistic Label</label>
<input id="foo" type="text" placeholder="Enter something here...">
</div>
<div class="pure-control-group">
<label for="foo">Rating</label>
<div class="acidjs-rating-stars">
<input type="radio" name="group-1" id="group-1-0" value="5" /><label for="group-1-0"></label><!--
--><input type="radio" name="group-1" id="group-1-1" value="4" /><label for="group-1-1"></label><!--
--><input type="radio" name="group-1" id="group-1-2" value="3" /><label for="group-1-2"></label><!--
--><input type="radio" name="group-1" id="group-1-3" value="2" /><label for="group-1-3"></label><!--
--><input type="radio" name="group-1" id="group-1-4" value="1" /><label for="group-1-4"></label>
</div>
</div>
<div class="pure-controls">
<label for="cb" class="pure-checkbox">
<input id="cb" type="checkbox"> I've read the terms and conditions
</label>
<input name="SubmitButton" type="submit" class="pure-button pure-button-primary">Submit</button>
</div>
</fieldset>
</form>
Here is what the page looks like for me:
I saw the other answers included suggestions for !important statements, so I decided to post mine. I threw the code you provided into a codepen.io and made a few quick changes to see if this is what you were looking for.
I added the class "raters" to your markup and styled it with that.
<div class="pure-control-group raters">
<label for="foo">Rating</label>
<div class="acidjs-rating-stars">
You can see why I've added these style rules in the comments supplied with them:
.raters label{
float:left; /* Corrective float for your modified code */
}
.raters input{
margin:0 0.25em; /* Spaces out the 'floated' radio inputs for presentation*/
}
.raters .acidjs-rating-stars label{ width:auto; } /* Actual Width Correction */
You can see it working live here: http://codepen.io/anon/pen/vKNGpv
(Note: I added the yahoo's external stylesheet to the CSS panel settings. You can access them with the gear in the top right-hand corner.)*
You can override margin for the inputs (which are you rating stars) of the purecss css in another css file with this very specific selector:
.pure-form.pure-form-aligned .acidjs-rating-stars input[name="group-1"] {
background: blue;
margin-right: -160px;
}
The base css is overwriting yours as you have suspected. You need to either define your padding/margin on your label elements using !important to make sure the css rules you define take precedence.
For instance if the margin for label elements is 0.5em top/bottom 0.2em on the left/right and you only want it say 0.1em on the left/right you would have to define in your css file like this
margin: {
0.5em 0.1em !important;
}
I'm trying to create an input form on a web page, and I want all of the input elements to be lined up along a certain column. My idea was to use absolute positioning to just shift all of the input elements over to a specific point on the page. It's working fine, except for one problem: the input elements are overlapping with each other a little bit, vertically.
Here's a MVCE:
<!DOCTYPE html>
<html><head>
<style>
span.right_align {
display: inline;
position: absolute;
left: 80px;
}
div.form_container {
position: relative;
}
</style>
<title>World's Best GUI</title></head>
<body type="text/css" style="background-color: #F7D879; font-family: Georgia, serif">
<div class="form_container">
<form name="guiForm" method="post" action="return false;">
Input 1: <span class="right_align"><input type="text"></span><br>
Input 2: <span class="right_align"><select autocomplete="off">
<option value="yes">Yes</option>
<option value="no">No</option></select></span><br>
Input 3: <span class="right_align"><input type="text" size="50"></span><br>
Input 4: <span class="right_align"><input type="text"></span>
</form>
</div>
</body>
</html>
As far as I can tell, the problem is because the font is smaller than the size of the input box, but it's the size of the font that determines where a new line "begins". If you comment out or remove everything in the right_align class, they stop overlapping (but they also stop lining up so nicely).
I'll also note that the reason I went for the span-class solution is because I need to 1) have some lines dynamically disappear and reappear, depending on the current state of a drop-down, and 2) dynamically create new input items that will also line themselves up nicely. This seemed like a solution that would interfere very little with the current workings of my web page.
Is there a simple way to fix this? Should I be creating these columns in an entirely different way? I'm open to totally new ideas as well.
EDIT: someone suggested I create a jsfiddle, so I did: http://jsfiddle.net/uy9comxk/
EDIT 2: there will be lines where I have multiple inputs that have to appear beside each other on the same line (for date inputs). I didn't include them because it would have increased the MCVE size by a lot.
In your css, use a line-height and it will work:
div.form_container {
position: relative;
line-height: 25px;
}
With a fiddle
Since you're using a form, you should use the label tag and set the width of each - ideally a little longer than than width of the inputs' names to account for longer ones. Using the label for the inputs will also fix the overlapping issue of the inputs.
CSS:
label {
display: inline-block;
width: 80px;
}
input {
margin-left:10px;
}
HTML:
<form name="guiForm" method="post" action="return false;">
<label for="input1">Input 1:</label> <input name="input1" type="text"><br>
<label for="input2">Input 2:</label> <input name="input2" type="text"><br>
<label for="input3">Input 3:</label> <input name="input3" type="text"><br>
<label for="input4">Input 4:</label> <input name="input4" type="text"><br>
<label for="input5">Input 5:</label> <input name="input5" type="text"><br>
</form>
http://jsfiddle.net/ub3bw1rv/
My HTML radio buttons are lining up vertically not horizontally. Also, the text for each of them is not right beside the button like I wish it would be.
<fieldset>
<legend>Payment Method</legend>
<input type="radio" name="payment_type" value="bill"/>
<label for="bill">Bill Me</label>
<input type="radio" name="payment_type" value="credit" checked/>
<label for="credit">Credit Card</label>
<input type="radio" name="payment_type" value="paypal"/>
<label for="paypal">Paypal</label>
</fieldset>
That is the code for my HTML buttons. I have an external style sheet, but I have not implemented any styling for the buttons as of now.
Checkboxes are aligned horizontally by default, as are the labels. You must be setting display:block on an element. Either remove that, or overwrite it by applying display:inline-block.
Try the following CSS:
input[type="radio"] {
display:inline-block;
}
label {
display:inline-block;
}
As I said, these are default properties. You should receive the following results. jsFiddle here It would be better just to remove display:block as opposed to merely overwriting it.
I need the following div to have a background color - simple right. But, it doesn't work correctly. I've done some testing, and figured out its the floats on the spans that are screwing it up. So, how do i fix this?
.days{
background-color:#000;
}
span {
display:block;
width:200px;
float:left;
}
<div class="days">
<span>
<input id="Field9" name="Field9" type="checkbox" value="" size="3" maxlength="4" tabindex="4" />
<label class="days" >Monday</label>
</span> <span>
<input id="Field5" name="Field10" type="checkbox" value="" size="3" maxlength="4" tabindex="4" />
<label class="days" >Tuesday</label>
</span> <span>
<input id="Field5" name="Field11" type="checkbox" value="" size="3" maxlength="4" tabindex="4" />
<label class="days" >Wednesday</label>
</span> <span>
<!-- goes till sunday --!>
</div>
When you float elements, you take them out of the normal flow of the document, and as a result, other non-floated elements do not make room for them.
What you're observing is that your div no longer takes the full height of its child elements because they're floated. All you need to do is to "clear" or undo the floating, and make days take the full height, and its background color will show. My preferred way of clearing floats is to give your containing element overflow: hidden:
.days
{
background-color:#000;
overflow: hidden;
}
For more info about clearing floats, check out the Quirksmode.org article about it, which includes an explanation of the overflow: hidden method.
You can either apply the background-color to the <span>, set a height to the <div class="days">, or put a <div> below the <span> with the CSS clear:both;.
I'm assuming you are not able to change the background color of the div. You can see the fixed version at http://jsfiddle.net/FazXG/2/
I have a form which contains several checkboxes align vertically in a div. I want to remove the space between each checkbox. But I can't find any solutions.
<div style="height:100px;width:25px;float:left;">
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
</div>
Does anyone have any solution to this problem?
I found the solution:
<input type="checkbox" style="margin: 0; padding 0; height:13px"/>
For IE, you need to set the height to remove the space between checkboxes.
After talking to Paul O'B, a CSS guru, this is a good solution that works in IE 6, 7, 8, FF 3, and Chrome:
<style type="text/css">
#aDiv input {
margin: 0;
padding: 0;
display:block;
height:12px;
overflow:hidden
}
</style>
<div id="aDiv" style="width:25px">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
</div>
This is using a doctype of HTML 4.01 strict. if you want side-by-side borders for the checkboxes, use a height of 13px.
The attribute selector won't work on IE 6 so it is taken out here. If you need to add other input element that is not a checkbox, use class instead.
Probably newlines between <input> tags are interpreted as any other whitespaces, that's why you see spaces between them. I think CSS rules has nothing to do with it.
Edit: Further investigation leads me to conclusion that whitespaces would only affect horizontal gaps. As of vertical space I believe it is impossible to assure that checkboxes will stick together without using custom graphics — web browsers are not obligated to make them perfectly square by standards, so even if you will find a way to make their bounding boxes touch each other, effect might not be satisfactory.
To make their bounding boxes as close as possible set line-height attribute for div element. With original sprites it doesn't look like you wanted it to in any browser I have tested.
Using custom graphic of some height, and identical line-height should do the trick.
Another edit: Some people here proposed using fixed height of input element of 13px. Remember! It is wrong. You can't rely on a fact, that some browsers have built-in checkbox sprite of that height.
There is white-space between each checkbox. The only way to remove it is to float them:
<style type="text/css">
.myCheckBoxDiv > input[type="checkbox"]
{
float: left;
}
.myCheckBoxDiv:after
{
clear: both;
content: "";
display: block;
}
</style>
<div class="myCheckBoxDiv">
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
</div>
This worked for me:
<style type="text/css">
body,html,input {padding:0;margin:0;}
</style>
<div style="height:100px;width:25px;float:left;">
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
</div>
Edit: It's valid css now :)
Just set:
<input type="checkbox" style="margin: 0">
But it will not work in IE.
I think different browsers renders the html elements differently. So, it becomes difficult to get a complete hold on the situation.
However, I found one solution but this time we need to apply some trick on the body element.
The CSS will be like this:
<style type="text/css">
input.mycheckbox {
height: 13px;
width: 13px
}
body {
font-size: 40%;
}
</style>
And the contents within body tag is:
Hope this helps.