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>
Related
I am front-end stupid and can't ever figure this stuff out. For some reason I'm seeing an abnormal amont of space in between my radio button and the text.
look on bottom of page
I am using bootstrap and I feel as if it is doing this. How can I get that space to go away? There's no margin or anything on it current which is why I am a little confused.
<div class="radio">
<h4>By Price</h4>
<label><input type="radio" name="optradio"> Low </label>
<br />
<label><input type="radio" name="optradio"> High </label>
You're labels are floating left which means it's being pulled to the far left of your container. I would recommend wrapping your content in columns. So something like this would work...
<div class="radio col-sm-3">
<h4>By Price</h4>
<label><input type="radio" name="optradio"> Low </label>
<br />
<label><input type="radio" name="optradio"> High </label>
</div>
If your content is then not centred, I would add this to your CSS...
.radio {
margin: 0 auto;
}
That should centre your content.
.radio{
width: 100px;
margin-left: auto;
margin-right: auto;
}
Also use a different div class.
<div class="radio col-sm-3">
I believe it's because the Div with class "radio" has a default width of 100%. When I change the css for .radio to width: 100px (or a percentage of your choice) then the radio button is much closer to the text. You will also have to center the div with the margin-left and margin-right as follows
.radio{
width: 100px;
margin-left: auto;
margin-right: auto;
}
As stated, the radio buttons are floated left in CSS.
This is a CSS rule meaning they're being taken out of the flow of the document.
The result is that they're positioned relative to the parent div, instead of according to their relationship to other block-level elements (the labels). That's pushing them all the way to the left of the form element.
In your external CSS file (not "products.css" but the one w/the gigantic hashed name) find this line:
.radio input[type="radio"], .radio-inline input[type="radio"], .checkbox input[type="checkbox"], .checkbox-inline input[type="checkbox"] {
float: left;
margin-left: -20px;
}
The offending code is float: left;
Remove the float and the inputs should rest directly next to the text.
Play with the margin settings to position it as you like.
I would recommend using:
<input type="radio" name="optradio"> Low <br />
<input type="radio" name="optradio"> High
I'm pretty sure it will work.
I had the same problem, Later i found out it was because i created a class for input like,
.input
{
width: 200px;
border: 1px solid #000;
padding: 5px;
}
Later i edited the input with some other name like,
input.a1
{
width: 200px;
border: 1px solid #000;
padding: 5px;
}
and the problem solved for me;
I'm trying to make some input boxes with text infront of it, but each time i style the text in CSS, the styling forces my input box "to a new line". In the image the first 2 text parts is unstyled, and the next 4 is. I want my styled texts not to create a new line.
Image: http://puu.sh/8kPKl.png
The html part:
<h0>Fulde navn:</h5> <input type="text" name="name"><br>
<h0>E-mail:</h5> <input type="text" name="email"><br>
<h5>Telefon nr:</h5> <input type="text" name="tlf"><br>
<h5>Antal personer:</h5> <input type="text" name="pers"><br>
<h5>Flytype:</h5> <input type="text" name="type"><br>
<h5>Betalingsform:</h5> <input type="text" name="betal"><br>
And the CSS part:
#four h5 {
font-size: 20px;
color: #ffffff;
}
Heading elements are block level elements by default. Try adding display:inline
#four h5 {
font-size: 20px;
color: #ffffff;
display: inline;
}
inline-block works as well.
fiddle: http://jsfiddle.net/5SEre/
Three things here:
1. Your first two headings are <h0>'s
Make them <h5>'s
2. That extra space below the <h5>'s is a margin:
#four h5{
margin: 0;
}
3. Block Elements
As pointed out by #DrydenLong in his answer, headings are block elements, and so they automatically render on their own line. You can fix this by setting them to be inline or inline-block elements:
#four h5{
display: inline;
//or
display: inline-block;
}
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.
Here is my code:
<div>
<label>Name</label><input type="text" id='name'/><br />
<label>Email</label><input type="text" id='email'/><br />
<label>Place</label><input type="text" id='place'/><br />
</div>
I'm new to CSS, I don't want table to get aligned, but the perfection should be like same, and don't want to apply style to individual elements.
Any help is appreciated.
I'm assuming you want to align the labels and inputs next to one another, in which case you'll be needing floats. Here's the quick css code:
form {
width: 500px;
overflow:hidden;}
label {
clear: both;
float: left;
width: 40%;}
input {
float: left;
width: 55%;}
I think that should work :)
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.