Table styling different in Chrome - html

Have a contact form that I have some options to check for contact times and methods. I had it styled correctly on Chrome, Firefox and Safari. The labels where to the left of the radio option and they were all lined up.
I have since run into the issue where the chrome style has broken and I cannot figure out what is going on as the Firefox and Safari CSS work perfectly. The page is cbasphaltmaintenance.com
<table id="contactOptionTable">
<tr>
<td>
<h1>Prefered contact method:</h1>
</td>
<td>
<input type="radio" value="home" name="contact_Method" class="contactRadioClass"/>
<label for="home">Home</label>
</td>
<td>
<input type="radio" value="mobile" name="contact_Method" class="contactRadioClass" />
<label for="home">Mobile</label>
</td>
<td>
<input type="radio" value="email" name="contact_Method" class="contactRadioClass" />
<label for="home">Email</label>
</td>
</tr>
<tr>
<td>
<h1>Prefered contact time:</h1>
</td>
<td>
<input type="radio" value="morning" name="contact_Time" class="contactRadioClass"/>
<label for="home">Morning</label>
</td>
<td>
<input type="radio" value="afternoon" name="contact_Time" class="contactRadioClass" />
<label for="home">Afternoon</label>
</td>
<td>
<input type="radio" value="night" name="contact_Time" class="contactRadioClass" />
<label for="home">Evening</label>
</td>
</tr>
</table>
Here is the css that works in safari and firefox
#contactOptionTable{
vertical-align: middle;
float: left;
padding: 0;
margin-left: 14%;
}
.contactRadioClass{
margin-top:10px;
}
I don't know what is going on here but it is bugging me. I appreciate all of the help. As you may see I'm a little wet behind the ears.

Add the following class in your CSS.
#contactOptionTable input
{
float:right;
}

You need to reduce margin-left: 5% and add width : 100% to #contactOptionTable.
However I suggest you not to use table structure here, it would be better if you create it using div's

Related

Table causes horizontal scrollbar to appear on mobile device

My issue is this piece of code:
<form method="post" name="myform" class="donate-form">
<table class="donate-table">
<input type="hidden" name="cpp_header_image" value="logo.png">
<input type="hidden" name="on0" value="Donation Amount">
<tr>
<th>
<div class="check">
<input name="os0" type="radio" value="5.00" id="radio">
<label for="$5" id="textBlock">$5.00</label>
</div>
</th>
<th>
<div class="checkboxgroup">
<input name="os0" type="radio" value="25.00" id="radio">
<label for="$25" id="textBlock">$25.00</label>
</div>
</th>
</tr>
<tr>
<th>
<div class="checkboxgroup">
<input name="os0" type="radio" value="10.00" id="radio">
<label for="$10" id="textBlock">$10.00</label>
</div>
</th>
<th>
<div class="checkboxgroup">
<input name="os0" type="radio" value="Other" id="radio">
<label for="other" id="textBlock">Custom</label>
</div>
</th>
</tr>
</table>
The issue is within the table "donate-table" closer to the bottom. I have 4 radio buttons, 5,10,25, and other, I want these radio-buttons to be displayed in 2 rows with 2 columns. On chrome (fullscreen) everything looks perfect no horizontal scroll bar and all radio buttons are looking okay but when I shrink the window to be as small as possible or when I use my mobile device the radio buttons get cut off and on my smartphone a horizontal scrollbar appears (I know the issue is because of a smaller screen size but I can't seem to fix it) When I delete 3 radio buttons and only have 1 the problem is gone. How can I fix this so I can display 4 radio buttons without a horizontal scrollbar appearing? I have looked and tried overflow-x:hidden; and some other suggested solutions but none work.
Anyone have a fix? Thank you in advance.
Here is my CSS code if needed:
.donations{
margin-top: 15%;
overflow: hidden;
}
.checkboxgroup {
text-align: center;
display: inline-block;
min-width: 150px;
}
.checkboxgroup label {
display: inline-block;
font-size: 20px;
}
Go through the code comments. Hope this will help you.
01. Replace all <th></th> with <td></td>
02. /* use .donate-table instead of .donations */
03. /* move min-height property to parent class (means .donate-table class) */
/* use .donate-table instead of .donations */
.donate-table{
margin-top: 15%;
overflow: hidden;
width:100%;
min-width:160px;
max-width:500px;
}
/* move min-height property to parent class (means .donate-table class) */
.checkboxgroup {
display: inline-block;
}
.checkboxgroup label {
display: inline-block;
}
<form method="post" name="myform" class="donate-form">
<table class="donate-table">
<input type="hidden" name="cpp_header_image" value="logo.png">
<input type="hidden" name="on0" value="Donation Amount">
<tr>
<td> <!-- Replace all <th></th> with <td></td> -->
<div class="check">
<input name="os0" type="radio" value="5.00" id="radio">
<label for="$5" id="textBlock">$5.00</label>
</div>
</td>
<td>
<div class="checkboxgroup">
<input name="os0" type="radio" value="25.00" id="radio">
<label for="$25" id="textBlock">$25.00</label>
</div>
</td>
</tr>
<tr>
<td>
<div class="checkboxgroup">
<input name="os0" type="radio" value="10.00" id="radio">
<label for="$10" id="textBlock">$10.00</label>
</div>
</td>
<td>
<div class="checkboxgroup">
<input name="os0" type="radio" value="Other" id="radio">
<label for="other" id="textBlock">Custom</label>
</div>
</td>
</tr>
</table>

Do checkboxes need unique id's, names and labels to have their CSS background toggled?

Desired Behaviour
I have 35 tables containing 6 checkboxes each.
I am using this CSS in order to style their checked and unchecked states:
http://www.csscheckbox.com/checkbox/20695/paperclip-style-thin-css-checkbox/
When using more than 1 instance of a table, the CSS only seems to work (ie apply the correct checked and unchecked states) when each checkbox has a unique name, id and label.
I want to achieve the same effect without having to type a unique name, id and label for all of the 210 checkboxes in the 35 tables.
JSFiddle
http://jsfiddle.net/rwone/8edb0j0g
What I've Tried
In the example below I have shown 2 table instances where each checkbox has a unique name, id and label.
Giving them the same "identifiers" prevents functionality, as does removing them altogether.
table {
display: inline-block;
}
/* from:
http://www.csscheckbox.com/checkbox/20695/paperclip-style-thin-css-checkbox
*/
input[type=checkbox].css-checkbox {
position: absolute;
z-index: -1000;
left: -1000px;
overflow: hidden;
clip: rect(0 0 0 0);
height: 1px;
width: 1px;
margin: -1px;
padding: 0;
border: 0;
}
input[type=checkbox].css-checkbox + label.css-label {
padding-left: 22px;
height: 17px;
display: inline-block;
line-height: 17px;
background-repeat: no-repeat;
background-position: 0 0;
font-size: 17px;
vertical-align: middle;
cursor: pointer;
}
input[type=checkbox].css-checkbox:checked + label.css-label {
background-position: 0 -17px;
}
label.css-label {
background-image: url(http://csscheckbox.com/checkboxes/u/csscheckbox_a1e28825bac3d82a32f547300c847628.png);
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<table>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG1" id="checkboxG1" class="css-checkbox" />
<label for="checkboxG1" class="css-label">area 01</label>
</td>
</tr>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG2" id="checkboxG2" class="css-checkbox" />
<label for="checkboxG2" class="css-label">area 02</label>
</td>
</tr>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG3" id="checkboxG3" class="css-checkbox" />
<label for="checkboxG3" class="css-label">area 03</label>
</td>
</tr>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG4" id="checkboxG4" class="css-checkbox" />
<label for="checkboxG4" class="css-label">area 04</label>
</td>
</tr>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG5" id="checkboxG5" class="css-checkbox" />
<label for="checkboxG5" class="css-label">area 05</label>
</td>
</tr>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG6" id="checkboxG6" class="css-checkbox" />
<label for="checkboxG6" class="css-label">area 06</label>
</td>
</tr>
</table>
<!-- second table here -->
<table>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG7" id="checkboxG7" class="css-checkbox" />
<label for="checkboxG7" class="css-label">area 01</label>
</td>
</tr>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG8" id="checkboxG8" class="css-checkbox" />
<label for="checkboxG8" class="css-label">area 02</label>
</td>
</tr>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG9" id="checkboxG9" class="css-checkbox" />
<label for="checkboxG9" class="css-label">area 03</label>
</td>
</tr>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG10" id="checkboxG10" class="css-checkbox" />
<label for="checkboxG10" class="css-label">area 04</label>
</td>
</tr>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG11" id="checkboxG11" class="css-checkbox" />
<label for="checkboxG11" class="css-label">area 05</label>
</td>
</tr>
<tr>
<td class="area_checkbox">
<input type="checkbox" name="checkboxG12" id="checkboxG12" class="css-checkbox" />
<label for="checkboxG12" class="css-label">area 06</label>
</td>
</tr>
</table>
It might be useful for you if I briefly describe what trickery is being employed here. The unstyled checkbox is being hidden because its associated label is placed over the top of it. Checkboxes have functionality built in where if you click their associated label they become toggled on, so by clicking the label with the fake checkbox image, you're able to toggle the hidden checkbox on. There's CSS rules to change the fake checkbox image based on whether the hidden checkbox is checked or not.
So the answer to your question is ... sort of. You don't need the name field if you just want the toggle effect, but that's what's referenced when you do a form submission, so you probably will need it later.
The ID on your checkbox is necessary because the ID field is what the label's for attribute references, and you need a relationship between the label and the checkbox as I previously mentioned.
Certain fields are inherently unique; names, id's and label names. You are never supposed to have more than one element with the same name/id/label.
While you could assign more than one checkbox a duplicate of any of these fields, it would be bad practice to do so; it would be an attempt to use an identifier in a way that it is not intended to be used.
In the case that you have multiple elements requiring the same styling properties, classes are then used. Classes are meant to be used in the case that you want to reuse certain styling properties.
Imagine this scenario:
You have two identical checkboxes...
<input type="checkbox" name="checkboxG6" id="checkboxG6" class="css-checkbox" />
<label for="checkboxG6" class="css-label">area 06</label>
.......
<input type="checkbox" name="checkboxG6" id="checkboxG6" class="css-checkbox" />
<label for="checkboxG6" class="css-label">area 07</label>
In this case, the HTML and CSS are both looking for a unique name/id/label. But that truly doesn't exist. How is it supposed to know which one you are referencing? It can't make this decision and therefore neither of them is assigned the styling properties. That is why the fields must be unique.
Suggestion Going Forward
If you don't want to manually set each checkbox, I would check out AngularJS. It makes doing tasks like this extremely easy; you can define rules and use pre-existing directives in your HTML that make it extremely hassle-free.
In AngularJS, you could do something like the following: AngularJS Checklist-model

How to make CSS border show on radio button click

I want to have a border show up around the image next to the radio button, when that radio button is clicked. Currently, my CSS selector knowledge is lacking and I do not get the expected result.
My expectation is that when I click a radio button , the corresponding image should be highlighted, but it is not...
What is wrong?
label>img ~ .input:checked {
border: 2px solid #f00;
}
<table>
<tr>
<td><label>
<img src="http://bighappyface.com/Happy%20Face%2050x50.png"><br />
<input type="radio" name="page" value="original" />Original </label>
</td>
<td><label>
<img src="http://bighappyface.com/Happy%20Face%2050x50.png"><br />
<input type="radio" name="page" value="standard" checked="checked">Standard
</label></td>
</tr>
</table>
EDIT
Answers so far rearrange HTML elements, which is not desirable from design point of view. I prefer to keep the text at the bottom of the image, not above. I'll re-accept if there is an answer that keeps html elements in order ...
here is a solution who sweets your needs :
Live Demo
input:checked ~ img {
border: 2px solid #f00;
}
label, img {
position: relative;
top: -80px;
}
label, input[type=radio] {
top: 60px;
}
HTML :
<table>
<tr>
<td>
<label>
<input type="radio" name="page" value="original" /> Original<br />
<img src="http://bighappyface.com/Happy%20Face%2050x50.png">
</label>
</td>
<td>
<label>
<input type="radio" name="page" value="standard" checked="checked"> Standard<br />
<img src="http://bighappyface.com/Happy%20Face%2050x50.png">
</label>
</td>
</tr>
</table>
You need to use input instead of .input because the dot addresses a class and you have not specified a class. Additionally, the :checked pseudo-class needs to be written before the element you want to change. The sibling selector ~ should work in theory but I had to re-arrange the html elements. Tested using Chrome, Opera and Firefox.
input:checked ~ img {
border: 2px solid #f00;
}
<table>
<tr>
<td>
<label>
<input type="radio" name="page" value="original" /> Original<br />
<img src="http://bighappyface.com/Happy%20Face%2050x50.png">
</label>
</td>
<td>
<label>
<input type="radio" name="page" value="standard" checked="checked"> Standard<br />
<img src="http://bighappyface.com/Happy%20Face%2050x50.png">
</label>
</td>
</tr>
</table>
fiddle link
http://jsfiddle.net/abasnet/0535aymy/
input[type="radio"]:checked + img {
border: 2px solid #f00;
}
<table>
<tr>
<td>
<input type="radio" name="page" value="original" />Original
<img src="http://idzyanamohddahlan.files.wordpress.com/2011/02/2472566_f520.jpg">
</td>
<td>
<input type="radio" name="page" value="standard" checked="checked">Standard
<img src="http://idzyanamohddahlan.files.wordpress.com/2011/02/2472566_f520.jpg">
</td>
</tr>

How to achieve this layout?

I want to basically create this kind of layout:
What would be the best way to achieve this?
Your HTML:
<div id="login">
<div class="float_left">
Your input here <br/>
Your remember me checkbox and text
</div>
<div class="float_left">
Your second input here <br/>
And then your forget password link
</div>
<div class="float_left">
Login button here
</div>
<br style="clear:both;"/>
</div>
Your CSS:
#login {}
.float_left {float:left;}
Here's the semantically clean way to do it:
The HTML:
<form>
<fieldset>
<input id="username" placeholder="user name">
<label><input id="rememberme" type="checkbox"> Remember me</label>
</fieldset>
<fieldset>
<input id="password" type="password" placeholder="password">
Forgot your password?
</fieldset>
<input type="submit" value="Login">
</form>
The CSS:
fieldset {
display: block;
float: left;
margin-right: 8px;
}
#username, #password {
display: block;
width: 100%;
}
Or something like that. I would use labels instead of placeholders, but there weren't any labels in your mockup, so I didn't want to add extra elements.
The "best way" would be to use either flexible box model (display: box, if you have some specific sizes to give to the blocks so they'll align) or table layout (display: table). Unfortunately, Internet Explorer 6 and 7 have absolutely no support for any of them.
So I'd go with either (as this question is GWT-oriented):
a plain old <table> in an HTMLPanel (and use role=presentation for best accessibility)
FlexTable or Grid widget (which are backed by a table)
Look, I've turned Sam's answer above into UI:Binder template. (Errors are possible, I'm writing XML here by hand.)
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<ui:style>
.float_left {float:left;}
</ui:style>
<g:HTMLPanel>
<g:HTMLPanel class='{style.float_left}'>
<g:TextBox ui:field='loginTextBox'/>
<br/>
<g:CheckBox ui:field='rememberMeCheckBox'>Remember me</g:CheckBox>
</g:HTMLPanel>
<g:FlowPanel class='{style.float_left}'>
<g:PasswordTextBox ui:field='passwordTextBox'/>
<br/>
<g:Hyperlink ui:field='passwordRestorationHyperlink'>Forgot your password?</g:Hyperlink>
</g:FlowPanel>
<g:FlowPanel class='{style.float_left}'>
<g:Button ui:field='loginButton' text='Login'>Login</g:Button>
</g:FlowPanel>
<br style="clear:both;"/>
</g:HTMLPanel>
</ui:UiBinder>
And the corresponding Java class. That should go with no surprise - #UiField and uiBinder.createAndBindUi(this) are your friends there.
I know it may sound bad, but I think tables is the best way to go in this case:
<table style="border: none;" cellspacing="0" cellpadding="0">
<tr>
<td>
<input name="login" />
</td>
<td>
<input name="password" type="password" />
</td>
<td>
<input name="login" type="submit" value="Login" />
</td>
</tr>
<tr>
<td>
<input type="checkbox" id="keepMeLogged">
<label for="keepMeLogged">Keep me logged in</label>
</td>
<td>
Forgot your password?
</td>
<td>
</td>
</tr>
</table>
CSS
input[type=text] { width: 200px; }
span.keep { display: inline-block; width: 200px; }
HTML
<input type="text" /> <input type="text" /> <button>Login</button> <br />
<span class="keep"><input type="checkbox" />Keep me logged in</span>
Forgot your password?
See it live: http://jsfiddle.net/foghina/92E2a/

radio button alignment

I am using radio buttons, but I am not sure how to align them how I want. I want them to be on the same line like this :
Option 1 o Option 2 o
But they appear like this :
Option 1 o
Option 2 o
Here is my HTML, can anybody advise?
<table>
<tr>
<td>
<label for="lblMeterName" />
</td>
</tr>
<tr>
<td>
Input/Output Group :
</td>
<td>
<input type="radio" name="rdoInput" value="Yes"/> Yes
<input type="radio" name="rdoInput" value="No"/> No
</td>
</tr>
<tr>
<td>
<input type="button" id="dialogButton" name="dialogButton" value="Submit" />
</td>
</tr>
</table>
Give your radio buttons and labels a class as follows:
<input type="radio" id="radioYes" class="inline-radio" name="radioGroup" value="Yes" />
<label for="radioYes" class="inline-radio">Yes</label>
<input type="radio" id="radioNo" class="inline-radio" name="radioGroup" value="No" />
<label for="radioNo" class="inline-radio">No</label>
Then apply the following CSS:
.inline-radio {
display: inline-block;
}
This is an improvement over the float method because float often requires additional semantics to prevent undesired rendering, whereas inline-block does not.
Put them in a table like this:
<td>
<table><tr><td>
<input type="radio" name="rdoInput" value="Yes"/> Yes
</td><td>
<input type="radio" name="rdoInput" value="No"/> No
</td></tr></table>
</td>
This gives you the most flexibility concerning space in between or alignment with parent object.
You can wrap input and text into div and set float css property for div.
There are multiple solutions for this:
You could wrap another table around the radiobuttons and add each one to a table cell.
Add a <br/> after each option.
You could float the radiobuttons.
You could add a display:inline or display:inline-block to the radiobuttons.
I would prefer wrapping both the radiobutton and it's label in a <label> tag and applying float, since this would make the label clickable as well and provide you with more flexibility:
<label class="radio-label"><input type="radio" name="rdoInput" value="Yes"/> Yes</label>
<label class="radio-label"><input type="radio" name="rdoInput" value="No"/> No</label>
And the CSS:
label.radio-label {
float: left;
margin-right: 10px;
}
Add non-breaking spaces between radio buttons;
Use this:
<table>
<tr>
<td><input type="radio" name="rdoInput" value="Yes"/> Yes</td>
<td><input type="radio" name="rdoInput" value="No"/> No</td>
</tr>
<tr>
<td colspan=2><input type="button" id="dialogButton" name="dialogButton" value="Submit" />
</td>
</tr>
</table>