开发者

html: what effects does 'form' have on the layout of a page

开发者 https://www.devze.com 2022-12-08 20:58 出处:网络
I thought that an html form has no effect on the layout of a page, and that it is just a way to group fields to send their values to the server in a single request.开发者_运维问答

I thought that an html form has no effect on the layout of a page, and that it is just a way to group fields to send their values to the server in a single request.开发者_运维问答

However, I notices that when I remove the form tag, the layout changes.

Where can I find an explanation of visual effects of the <form> tag?


<form> is a block-level element, so at the very least, it will appear on its own line. It probably also has some basic margin and padding attributes as a default. I would recommend using Firebug to inspect the form element and see what it's layout properties are.

You can easily adjust the appearance of <form> through either an external css file, css in your document HEAD, or inline styles on the form, like this:

<form style="margin: 0; padding: 0; background-color: #cc5500;">
...
</form>


Most browsers have DOM inspector tools that will show you the styles applied to a given element. Firebug is a good example.

In short, a form is an element that has display: block and may have margins / padding. (Plus whatever styles get applied from any author or user stylesheets)


The form element is a block-level element, so the element in itself will have layout properties.

Different browsers have different default styles (margin, padding, etc.) to form controls. One way to get around this is to use CSS resets, such as Eric Meyer's classic reset.css or a more styled CSS framework such as Tripoli.

Note that form controls are perfectly valid outside the form tag, for example in use as interface controls.

While the W3C documentation isn't always easy to read, it is the definitive text on HTML. See Forms in HTML documents.


If you want to make sure you have a consistent layout with and without forms, use the following CSS:

form{
    margin:0;
    padding:0;
    display:block;
    }


Form is a html block element. It acts like every html block. It can have some default style applied by default browser style, so it can be various depending on browser.

0

精彩评论

暂无评论...
验证码 换一张
取 消