views:

429

answers:

1

So if I have a HTML heading like this

<h2>A Heading</h2>

and I run Edit -> Format Document it ends up looking like this

<h2>
    A Heading</h2>

why is this? It doesn't do it to other block elements, but it does do it to other inline elements (eg <label>).

Update: To clarify, I mean why is this the default, not where are the settings to change this

+2  A: 

It does it because that what its default settings are. To change it, go to:

Tools > Options > Text Editor > HTML > Format > Tag Specific Options...

Under "Default Settings", change the "Line Breaks" option to "Before and After" for both the Client and the Server "tag supports contents" options.

From Scott Guthrie's blog:

If you format a selection of markup and see that a close tag hasn’t been moved to a separate line – it is because there is no space between the end of the preceding markup and the terminating tag, and as such VS is being careful not to change it to avoid changing the rendering semantics.

Cory Larson
Yeah I never understood the default html formatting settings. The majority of them are quite heinous, IMO.
Chris
Sorry, I didn't mean literally why does it do it, I mean why possible reason is there for that being the default? I can't imagine ever wanting this layout
Glenn Slaven
Sometimes it's just better not to question why Microsoft does things the way they do =/. Perhaps somebody thought that it would be easier to scan along the left side of the document for the opening tag, thinking that there's really no point in being able to easily identify the closing tag. I don't know, I guess that kind makes sense, otherwise I don't have an answer for you.
Cory Larson