prevent line break after form

D

Dirk Jagdmann

Hello,

the following simple html code always places "test text" on a new line
below the form.

<html><body><form>Input:<input/></form>test text</body></html>

How can I prevent this behaviour? Does some css magic do the trick?
 
J

Jukka K. Korpela

Dirk Jagdmann said:
the following simple html code always places "test text" on a new line
below the form.

<html><body><form>Input:<input/></form>test text</body></html>

That's to be expected, since a form element is a block element.

Usually people complain about the "empty line" between the form and the
subsequent text. The "empty line" is really just a default bottom margin for
a form, which is a less natural behaviour, but very common in browsers.
How can I prevent this behaviour? Does some css magic do the trick?

To prevent just the "empty line", you could use
form { margin: 0; }

To prevent both the "empty line" and the line break, you could use
form { display: inline; }

However, it is generally best to put a form on a line of its own, and even
put each input field (together with its label) on a line of its own,
for ease of use and for accessibility. In fact, the default line break and
"empty line" are _insufficient_ for distinguishing a form from other content
on a page. Consider using something like
form { background: #ffe;
color: #efe;
padding: 0.1em 0.3em;
border: solid thin #ccd; }
Then you can suppress the margin if you like, since the margin is just a very
awkward attempt at achieving some visual separation.
 
D

Dirk Jagdmann

Hello Jukka,

thank you for the exhaustive explanation of the solution. I choose the
"display: inline" way, as my goal was to have a single input search
form. I usually format multiple entry forms with tables, so the css
setting doesn't do any harm.
 
B

Beauregard T. Shagnasty

Dirk said:
thank you for the exhaustive explanation of the solution. I choose the
"display: inline" way, as my goal was to have a single input search
form. I usually format multiple entry forms with tables, so the css
setting doesn't do any harm.

Rather than trying to display a form inline, which is contrary to its
nature, try this (using your little sample):

<html><body><form>Input:<input/> <span style="padding-left: 5em;">test
text</span></form></body></html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top