How to display HTML <FORM> as inline element next to images? - html

I have some images, with one of them being able to submit a hidden form.
My problem is that I need all the images to display inline with each other. The image with the form submit refuses to do this.
The code, basically, is this:
<img class="inline" src="image.png" />
<img class="inline" src="image2.png" />
<img class="inline" src="image3.png" />
<form action="/forms/important-form.php" method="POST">
<INPUT TYPE="hidden" NAME="infoForForm" VALUE="Information">
<INPUT TYPE="hidden" NAME="URL" VALUE="/employee-xyz76r3-headshot.png">
<INPUT TYPE="hidden" NAME="employeeTitle" VALUE="Salesperson" >
<input type="image" class="inline" src="email.png" alt="Submit Form" />
</form>
CSS like this:
.inline {
display: inline!important;
float: right;
}
Definitely not working though. The image that functions to submit the hidden form (the email icon) refuses to stay inline.
Thank you for all of your help! Any ideas/solutions are appreciated.
P.S. Just try to ignore that Chief Marketing Officer is misspelled haha.

The issue here is that a form element is a block element by default. To change this, making the images appear on the same line, only the following CSS rule is needed:
form { display: inline }
Well, you also need to change href attributes in img elements to src attributes, but without this fix, the first three images do not display at all.
You don’t need anything else, since img elements are inline by default.
You don’t need even that single CSS rule if you move the img elements inside the form element.

Wrap the images around a div floated right.

You have to float images too. And display: inline do nothing there, all floating elements are blocked.

Related

Align a checkbox input and a <p> tag in the same line

I've seen most of the other solutions to this problem using a label. Unfortunately, I can't use label on this particular case, because that will mess things up. What I have is the following:
<div className="terms-checkbox">
<input type="checkbox" required />
<p>I accept the Terms and Conditions</p>
</div>
And I'm setting display to be inline-block for terms-checkbox like so:
.terms-checkbox {
display: inline-block;
}
However, this does not align the items horizontally/in the same line. Without wrapping the input tag with label, how can I make the checkbox and p tag align horizontally?
Here's the fiddle link: https://jsfiddle.net/eu5rso2a/1/
edit: fixed indentation.
You must set the terms-checkbox class to input or p tag. Not their parent.
Means your input and p tag must be inline-block
<p><input type="checkbox" required/>I accept the Terms and Conditions</p>

HTML center input buttons

Here is my code:
<p align="center">Do you want to play the game?</p><br>
<Input type = 'Submit' Name ='StartQuiz' value="Yes" align="center">
<Input type = 'Submit' Name ='LogOut' value="No" align="center">
The buttons are not in the center. Do I have to use CSS for this? I read on the net to just use the simple align tag.
How should I go about aligning these buttons to the center?
Align is deprecated on HTML5, so considered use CSS3 instead. The align attributte is to center the content and not the element itself.
The input element is inline-block by default, so, to center you need to put them inside a div as here:
<div style="text-align:center;">
<input type="text" />
</div>
This is cause the inline-block elements share the same line with other elements and you need to center all elements that share the same line. The div element is a block element that display alone in one line.
So you have another option to center an input, and you can set to "display:block;" as here:
<input type="text" style="margin:0px auto; display:block;" />
See: http://jsfiddle.net/T4f3W/
You should be using CSS for such styling. Rid of the HTML align attributes, add a wrapper, and center the text. Also note that the <center> tag and certain uses of align=center are deprecated as of HTML5.
<div>
<p>Do you want to play the game?</p><br>
<input type="submit" name="StartQuiz" value="Yes">
<input type="submit" name="LogOut" value="No">
</div>
And for your CSS:
div
{
text-align: center;
}​
<p align="center">Do you want to play the game?</p><br>
<div style="text-align: center">
<Input type = 'Submit' Name ='StartQuiz' value="Yes" align="center">
<Input type = 'Submit' Name ='LogOut' value="No" align="center">
</div>
Define one div parent and give to text-align center in your css .
Hi Check to live demo http://jsfiddle.net/vdUEZ/
Remove p tag align center and give to one div
Updated Live demo http://jsfiddle.net/vdUEZ/1/
chuck the inputs inside a <center> tag. check out the live demo http://jsfiddle.net/xA2kS/
Your strategy should work if you move the <input> tags inside the the <p> tag and remove the deprecated align attributes in the <input> tags. Even if you were to use the align attribute in an <input> tag, the correct value would be "middle", not "center". Try this code:
<p align="center">Do you want to play the game?<br>
<Input type = 'Submit' Name ='StartQuiz' value="Yes">
<Input type = 'Submit' Name ='LogOut' value="No">
</p>
It's also possible (preferred, actually) to use CSS for centering.

Differents way to structure html inputs and labels in a form

I'm wondering what are the best solutions to structure a html form with labels and inputs.
I used to do this with float: left to the label and float: right for the inputs. And each line is surround with a block clear: both.
But i don't think these CSS property were made for something like that..
So what are the others solutions ? Tables ?
Well it really depends on what you want the form to look like. For example, if you want a clear grid with borders I recommend using a table.
To duplicate what you have, you can do this:
<label for='textbox'>Label</label><input type='text' id='textbox' />
And then this css:
label { display: inline-block; width: 100px; }
This will make the label stay on the same line as in input element but will push it the appropriate distance.
Personally, I try to avoid using floats to align elements. I would rather use position absolute and set left or right and top or bottom. To me floating is like asking the browser to do it for you, and maybe some browsers (cough ie cough) will decide to draw it a little differently.
Form markup and CSS will always be a personal choice. Sure, there are some rights and wrongs semantically and technically from a CSS point of view, but there certainly isn't one (or even a few) "right" techniques.
My personal preference is to float the label left and contain my inputs inside lists, which I personally consider more semantic than a div or p tag.
HTML:
<form>
<fieldset>
<ol>
<li>
<label for="input1">Label 1</label>
<input type="text" name="input1" id="input1">
</li>
<li>
<label for="input2">Label 2</label>
<input type="text" name="input2" id="input2">
</li>
<li>
<label for="input3">Label 3</label>
<input type="text" name="input3" id="input3">
</li>
</ol>
<button type="submit">Submit</button>
</fieldset>
</form>
CSS:
li {
clear: left;
margin-bottom: 10px;
}
label {
float: left; /* You could use "display: inline-block;" instead. */
margin-right: 10px;
width: 80px;
}
tables is also a solution.
also , Div with 2 inner divs( left and right)
or 1 div with both elements with float:left with margin-left.

Break line after input without html markup

I am trying to display a number of inputs and their corresponding labels. They are both inline elements, and I have a working solution with adding a br tag at the end like so
<label for="hello"></label>
<input id="hello" type="text" />
<br>
<label for="stackoverflow"></label>
<input id="stackoverflow" />
Id like to solve this without extraneous HTML markup, i.e with CSS. What is the easiest way to do this?
I have viewed other questions similar to this, but aligning by row instead of by column.
You can wrap the labels around your inputs and display them as blocks:
<style>
label { display: block; }
</style>
<label>
Hello: <input name="hello">
</label>
<label>
StackOverflow: <input name="stackoverflow">
</label>
Note that when you do this you don't need to use the for="name" attribute.
The other way (if you don't want the labels wrapped around your inputs) is to float the labels to the left:
<style>
label { float: left; clear: left; }
</style>
However, I generally prefer a little more markup, something that connects the label and the input into one logical element, called a field:
<div class="field">
<label for="hello">Hello</label>
<input name="hello">
</div>
<div class="field">
<label for="stackoverflow">Stackoverflow</label>
<input name="stackoverflow">
</div>
Because each field is a div, it will display as a block automatically, but you can control it for individual fields as well.
Try to set display:inline-block for your input and label elements. So you can add all block element specific css like witdh or margin-bottom.
You can also set your input and label to display:block and add margin-bottom only to the the input. Or you can reverse it and add a margin-top to your labels ;)
If you want to remove the margin on the last element you can use input:last-child {margin-bottom:0;}
input, label {display:block;}
input {margin-bottom:18px;}
input:last-child {margin-bottom:0;}
/* Or to be specific you can use the attribut-selector
which only works on inputs with type="text"
*/
input[type="text"]:last-child {margin-bottom:0;}

Styled HTML Submit button fails to respond to Return Key

I have a simple HTML form, thus:
<form>
<p>
<input type="text" name="text" />
</p>
<p class="buttonPara">
<input type="submit" name="submit" />
</p>
</form>
and a simple stylesheet, thus:
p.buttonPara
{
position: relative;
}
p.buttonPara input
{
position: absolute;
left: 50px;
}
The submit button fails to respond to the return key unless I remove the class from the
<p class="buttonPara">
Any ideas anyone?
I'm not sure what you want to accomplish and why you take this approach. Do you want to align the button in the middle of the textfield above?
You could do this without positioning the button element. But that would mean wrapping everything in a container element and setting the width of that element along with the text-align property. Or you could set the width and align properties of the form of course.
I worked it out.
My form is contained in a div that has its class set programatically by the body onload event. Until the class is set, the div has an underlying style of display:none. In IE, the result is that hitting the return key does not submit the form.