Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep two HTML forms on the same line in a paragraph tag

Tags:

html

css

forms

I have a paragraph which has two seperate forms in it. However, when the page is loaded, there is a line break where each form starts. I am using the following code:

<p style="font-size:14px;font-weight:700;color:grey;">' . $user_pic . ' <a href="profile.php?id=' . $mem_id . '" style="color:#0F39C5;">' . $knockfirst . ' ' . $knocklast . '</a> is knocking. Let him in?
<form action="messages/group/addToChat.php" method="post" name="adduser"><input type="hidden" id="newid" name="newid" value="' . $mem_id . '"><input type="hidden" id="groupid" name="groupid" value="' . $group_id . '"><a href="#" onclick="$(this).closest(\'form\').submit(); return false;" style="color:#0F39C5;font-size:15px;">Yes</a></form>
<form action="messages/group/declineKnock.php" method="post" name="declineuser"><input type="hidden" id="newid" name="newid" value="' . $mem_id . '"><input type="hidden" id="groupid" name="groupid" value="' . $group_id . '"> | 
<a href="#" onclick="$(this).closest(\'form\').submit(); return false;" style="color:#0F39C5;font-size:15px;">No</a></form></p>

Is there any way to keep this all on the same line when it's rendered onto the page?

like image 988
James Avatar asked Sep 03 '13 08:09

James


People also ask

How do I put two HTML elements on the same line?

To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.

How do you make two forms in one line?

In HTML, a tag is anything between < and > , so in your first example you had 2 form tags and 2 input tags. Attributes are the extra pieces of information in those tags, in the form key="value" , so in your first form tag you had the attributes action and method .


2 Answers

Add this to your css:

form {
    display: inline-block; //Or display: inline; 
}

Fiddle: http://jsfiddle.net/trW82/

like image 93
Flame Trap Avatar answered Oct 16 '22 06:10

Flame Trap


add float style to the first form -

style="float: left;"

better yet, create a separate CSS class -

.chatForm {
    float: left;
}

and assign this class to the first form -

<form class="chatForm" ......

You can also set display property of both form to either inline or inline-block -

.chatForm, .declineForm {
    display: inline-block; /* or inline */
}

and then -

<form class="chatForm" .....
<form class="declineForm" ....

Demo.

Check out the sitepoint reference on display and float.

like image 45
MD Sayem Ahmed Avatar answered Oct 16 '22 06:10

MD Sayem Ahmed