How To Properly Space A Contact Form In A Table? - html

I'm trying to properly add spacing between the s in my table contact form here: http://jsfiddle.net/k6XSp/1/.
I would like to have the fields on the right to line up with the width of the message box on the right side, thus meaning I need space added in between the s in each of the two s.
It is looking good, but I can't figure out how to space the right sides of the fields. Adding a margin-right seems to do the trick, but not very well, as it is very glitchy.
In addition, the form moves around when you click on the filed because the border shows up.
The CSS for the text fields looks like this:
#contact-area input, #contact-area textarea {
padding: 5px;
width: 451px;
font-family: Helvetica, sans-serif;
font-size: 1.4em;
margin: 0px 0px 10px 0px;
border: none;
background-color: #dedede;
height: 40px;
}

Take a look at this fiddle http://jsfiddle.net/k6XSp/6/. As suggested, try not to use tables to position elements. Use css instead.
<div class="control-group">
<label for="FirstName" class="text">First Name:</label>
<div class="control">
<input type="text" name="FirstName" id="FirstName" />
</div>
</div>
.control-group {width: auto; float: left; margin: 0 10px 0 0}
.control {display: block; clear: both;}

Forms use fieldset, legend and label tags, not tables, unless you need to code HTML from the 90's. The idea is to be semantically correct e.g. your HTML should reflect it's meaning/purpose.
<form action="contactengine.php" method="POST">
<fieldset>
<legend>personal data</legend>
<label for="firstname">First name</label>
<input id="firstname" placeholder="First name" />
</fieldset>
<input type="submit" value="submit my form" />
</form>
Spacing these fields is part of your markup => CSS.
See fiddle for a responsive/liquid (desktop, tablet, mobile) approach.
Note:
I see you use the 62.5% font base approach. We've tested with this on a big project and noticed IE has a floating point issue ending up with a different font-base than 10px. In my opinion just put it to 10px and be done with it => rem values can now be used in modern browsers.

Related

Searchable placeholders in the input elements on Chrome for iOS

Is there a way to allow user to search placeholder text using the "find in page" browser function?
I understand I can just add elements with zero height that contain placeholder text, but that seems like a hacky solution.
Perhaps something using CSS pseudoclasses?
edit: I should mention, so far this is only an issue on Chrome for iOS(10.0.2)
the code is very simple:
<input type="text" placeholder="First Name">
Here's the screenshot of Chrome:
This is what I get when I search for 'first'
input {
font-size: 1.5rem;
margin: 10px;
padding: 10px;
width: 65%;
}
input:placeholder-shown {
border: 5px solid red;
}
<form>
<input type="text" placeholder="Placeholder text" value="Currently has a value (not showing placeholder).">
<input type="text" placeholder="Currently has no value (showing placeholder).">
</form>

Center-justifying Elements in a Form

I'm trying to get my form, specifically the field and text elements within the form, to be center justified, similar to this:
Form example
How would I go about doing that? I've tried doing
table > tbody {
text-align: justify;
text-align: center;
background-color: #e8e8e8;
}
Which just ends up centering everything(except the fieldset, oddly) and doesnt justify anything. Any help would be appreciated.
My Code
While this is arguably a reasonable case for a table, you could eliminate all the extra markup that tables bring by using the label element set to display:block which kind of acts like a table column. I often lay out my forms in the following way. This has the added advantage that at smallscreen views, you can have the label above the input by taking away the float.
If you want the input elements on the right side (text, email, textarea, etc) to all look the same, you'll have to style them with specific widths, paddings, font-sizes, etc to override the default browser styles. Otherwise they'll all have different default widths.
label, input[type="text"] {
display: block;
float: left;
}
label {
width: 30%;
text-align: right;
margin: 8px;
clear: left;
}
input[type="text"] {
margin: 8px 0;
}
<form>
<label for="name">Name</label>
<input type="text" name="name">
<label for="phone">Phone</label>
<input type="text" name="phone" placeholder="555-5555">
<label for="email">Email</label>
<input type="text" name="email">
...
</form>

How to get search bar to align up with search input?

I am trying to create a search bar like Google's after the user begins to type in a keywords. I usually try to align the search bar with the submit button. If I can get it to line up correctly in Firefox, it usually won't line up correctly in Chrome. Is Google actually lining up the two inputs, or is there a way to put the actual button inside of the search bar and position it to the very right?
Edit: Well, I guess it is more of a conceptual question. I do not actually have any code. I just remember my last attempts to try to align the search bar and button failed horribly. How does Google align up their search box and submit button so well?
Edit 2:
Here is my HTML:
<form method="get" action="">
<div id="search-outer">
<input id="search-input" type="text" name="search" /><input id="search-submit" type="submit" value="Search" />
</div></form>
Here is my CSS:
#search-outer {
width: 600px;
margin: 0 0 10px 0;
}
#search-input {
margin: 0;
width: 400px;
font-size: 20px;
padding: 5px;
border: 1px solid #EEEEEE;
}
#search-submit {
margin: 0;
font-size: 20px;
padding: 5px;
border: 1px solid #EEEEEE;
}
They are still off a little bit. If I give them specific heights, then the button's position begins to be above the input's position.
If you want pixel-perfect control of two elements next to eachother, one approach I often find crossbrowser successful is to absolute position the right element, but use margins instead of top/left, like so:
<html>
<body>
<input/>
<input type="submit" style="position:absolute;margin:42px 0 0 10px;"/>
</body>
</html>
Using margins will position it relative to its position of orgin, which is on the right of the input field in this case. Using top/left would position it relative to its offset parent, which could be an ancestor element.
<form method="post" action="">
<div id="div">
<input type="text" />
<input type="submit" value="send" />
</div>
</form>
#div { width: 100px; margin: 0 auto; text-align: center;}
You'd generally surround both with a container and align to one edge of that. Remove (reset) margins to 0 to avoid browser-specific alignment issues.

Difficulties in styling CSS form

With all the controversy surrounding tables as a layout option for forms, I've decided to go with an unordered list. I finally have the labels and elements displaying as I intend, however the 'note' div I've added refuses to line up with the inputs above it.
I've included the code below, please excuse the garish background colours I've chosen to help me judge placement! Does anyone have any suggestions as to why this the 'note' div refuses to play along? I'm sure there's a simple solution but I'm completely stumped. Thank you very much in advance.
form.contact label
{
float: left;
position: absolute;
background: red;
}
form.contact input
{
width: 200px;
margin-left: 15em;
}
form.contact .note
{
margin-left: 15em;
width: 176px;
background: yellow;
}
form.contact ul
{
list-style: none;
position: absolute;
padding: 0;
}
form.contact ul li
{
float: left;
clear: left;
width: 100%;
padding-bottom: 1em;
margin-bottom: 10px;
background: pink;
left: 0;
}
<ul>
<li>
<label for="address1">Address Line 1:</label>
<input name="address1" type="text" id="address1" />
</li>
<li>
<label for="address2">Address Line 2:</label>
<input name="address2" type="text" id="address2" />
</li>
<li>
<label for="address3">Address Line 3:</label>
<input name="address3" type="text" id="address3" />
</li>
<li>
<label for="address4">Address Line 4:</label>
<input name="address4" type="text" id="address4" />
<div class="note">This is a note</div>
</li>
<li>
<input type="submit" name="btnSubmit" value="Submit" id="btnSubmit" />
</li>
</ul>
Because the input and the div have a different font size by default, and using elastic layout with em measurements is affected by the size of the font.
This fixes it:
* {font-size: 12px;}
input is inline element and div.note is block element. Browsers' default css has different settings for inline elements and div.notes. I suggest you try to adjust magin-left and/or padding-left values of input and .note. You may also need to sepeficy font-size as Finbarr points out.
A couple of answers spring to mind.
First, have you considered the defualt padding? I see you specify the margin, but if you haven't included a fixed padding level, the different elements might inherit it differently.
It would also be helpful if you could post a screenshot - the sample code you provided works perfectly for me when I test it in konqueror & firefox - so maybe its a browser issue?
...ok, I see weakish has already said pretty much the same thing while I was typing this. But, my screenshot comment stands; it would be helpful to see exactly what the error is, as you see it.

How to center the <legend> element - what to use instead of align:center attribute?

What am I missing here?
Edit, because this doesn't work in a comment:
The below solution results in this:
----------------------------------------------------
| |
| Legend text |
but what I'm going for is:
----------------------Legend text-------------------
| |
| |
Edit #2:
Based on the feedback so far, it is sounding like this whole <legend> tag is a losing proposition. Does anyone have an example of what they use in lieu of this--something that has a similar appearance that is more reliable?
Assuming your markup looks something similar to this:
<form>
<fieldset>
<legend>Person:</legend>
Name: <input type="text" size="30" /><br />
Email: <input type="text" size="30" /><br />
Date of birth: <input type="text" size="10" />
</fieldset>
</form>
Your CSS should look something like this:
legend {
margin:0 auto;
}
that's easiest
Oh Dear... You have chosen probably the most difficult thing in CSS when it comes to cross-browser compatibility. Cameron Adams said it best
Probably the only difficulty in
styling semantic forms is the legend
tag. It is insufferably variable
across browsers. In Mozilla, the
legend tag is not left-indented from
the body of the fieldset, in IE and
Opera it is. In Mozilla, the legend
tag is positioned in between the
fieldset's border and its content, in
IE and Opera it is positioned inside
the content. This makes it very hard
to move the legend inside the fieldset
border, or position it flush to the
left of the fieldset, as you get
varying effects across browsers
You can read more about what he said at Fancy Form Design Using CSS on how to style forms.
My solution to the problem would be to remove the fieldset border completely and absolutely position the legend element. The problem with what you want to do is that it is different in every browser.
The legend can be styled by html attribute quite easily. I've found by searching..
<legend align="center">Legend</legend>
finally got it without the align="center" hack. using only legal css margins
legend{
width: 70px;
padding: 2px;
margin-left: calc(50% - 35px - 2px);
}
Legends are notoriously resistant to styling.
One thing you can do is use a heading element instead of legend as that will be much easier to style. This does what you want in FF3 and Safari at least.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
h3{
background-color:#FFF;
margin: -1em auto 0;
text-align:center;
width:10%;}
</style>
</head>
<body>
<form>
<fieldset>
<h3>Person:</h3>
Name: <input type="text" size="30" /><br />
Email: <input type="text" size="30" /><br />
Date of birth: <input type="text" size="10" />
</fieldset>
</form>
</body>
</html>
legend
{
margin-left: calc(50%);
transform: translateX(-50%);
}
(Answerer then drops his keyboard on the floor, like a microphone)
Here is with what I came just a few minutes ago. This is working in Firefox and Chromium/Opera. Haven't tested in Edge and earlier IE-crap, but according to my experience, should work there as well.
Assuming that form element inside is displayed as block.
fieldset {
border: 1px solid Olive;
padding: 0.1%;
margin: 1px auto;
width: auto;
}
legend {
font-size: 10px;
text-align: center;
padding: 0.2% 0.4%;
width: 30%;
margin: 0 34.6%;
border: 1px solid DarkOrange;
border-radius: 5px;
}
The trickery is with legend margin and percentages. margin: 0 34.6%;
Now, if You increase or decrease padding left/right or width, You'll need to recalculate percentage for legend's left/right margin, apparently. Don't bother with 0 auto. It simply won't work.
You can also replicate whatever semantic_form_for outputs as HTML, using the very basic rails form helper. Since you know what you expect, you can write it out without the use of semantic_form_for. We are doing this in one of our projects.
Little late to throw out an alternative for this? Anyway, I wanted to use a fieldset and found the lack of positioning of the legend and the variable display by browser annoying so I replicated with a couple divs:
<div style="border:solid 1px #AAAAAA; position:relative; padding:10px;">
<div style="position:absolute; top:-10px; left:50%; margin-left:-35px; width:70px; text-align:center; background-color:#FFFFFF;" >Legend</div>
Stuff in your fieldset
</div>
The important notes on this: the inner div width must be set, and the margin left must be set to half. You may have to make adjustments to the width depending on the length of your text. The left:50% starts it at the halfway point of the parent and the negative margin left positions it back half it's own width.
You can use it like
<legend align="center"> your text here </legend>
Use "margin-left" to legend to move the text to right.
<fieldset>
<legend style="margin-left:3%;">Summary</legend>
<div>
The novella The Metamorphosis was written by Franz Kafka in 1912. It tells the story of the tragedy of a salesman, Gregor Samsa, who turned into a gigantic insect, but still possessed a human mind.</div>
</fieldset>