Avoid or prevent a line break after and before a <form> tag.

HTML <form> tag

Question:
How to avoid or prevent a line break after and before a <form> tag.

As we all know, after a <form> and </form> tag. A line break <br> is automatically created which causes a white space below the form. How can i prevent or remove the white space.
w3irdoAsked:
Who is Participating?
 
TNameCommented:
Styling the form with margin:0; padding:0;  should get rid of the white space in IE too, e.g.:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>
<div style="background-color:#ccc;">aaa</div>

<form style="border:1px solid #f00; margin:0; padding:0; "> xxx  </form>

<div style="background-color:#ccc;">bbb</div>
</body>
</html>
0
 
w3irdoAuthor Commented:
thanks alot.
It solved my problem of white space.

Question:
But it still goes to the next line this time without any white space. How can i prevent it from going to the next line. I want to place object besides (at the right) of the form.
0
 
TNameCommented:
To get rid of the line breaks, you could float the form, but remember that other elements, e.g. a div before or after the form, might also cause a linebreak, so you might have to float them too.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>

<div style="width:200px; background-color:#ccc; float:left;">aaa</div>

<form style="width:200px; border:1px solid #f00; margin:0; padding:0; float:left;">xxx</form>

<div style="width:200px; background-color:#ccc; float:left;">bbb</div>

</body>
</html>




0
 
oheilCommented:
Same problem here but another solution using style="display:inline;" :


<form style="margin:0;padding:0;display:inline;" action="some_action.html">
<input style="margin:0;padding:0;display:inline;" type="submit" value="submit">
</form>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.