html - Stange PRE tag (or lack thereof) behavior -


given html

<pre> <div class="px_xml">&lt;addfiledialogplaces id="<b>rvt_2016 places</b>" delete_prior="true"&gt;    <div class="px_ind">&lt;place id="favorites"&gt;c:\users\[px~user]\links&lt;/place&gt;    &lt;place id="datasets"&gt;c:\programdata\datasets&lt;/place&gt;       <div class="px_ind">&lt;place id="families"&gt;c:\programdata\assets\revit\2016\libraries&lt;/place&gt;</div>    &lt;place id="desktop"&gt;desktop&lt;/place&gt;    &lt;place id="my computer">::{20d04fe0-3aea-1069-a2d8-08002b30309d}&lt;/place&gt;    &lt;place id="my network places"&gt;::{208d2c60-3aea-1069-a2d7-08002b30309d}&lt;/place&gt;    &lt;place id="documents"&gt;personal&lt;/place&gt;    &lt;delete&gt;revit server network view&lt;/delete&gt;</div> &lt;/addfiledialogplaces&gt;</div> </pre> 

and in custom css

.px_xml {        font-family: monospace;        font-size: .7em;        color: #0000cc;        margin-bottom:0;        display: block; }  .px_ind {        margin-left: 2em;        display: inline-block; } 

everything works expected. however, if remove pre tags, seem extraneous since setting monospace font css, color override applies through second div.

now know keep pre , skip .px_ind styling, prefer not 2 reasons. one, forces me indents right hard way, , 2 leaves me no easy way revise amount of indent later. rather keep spaces in xml me understand while editing, while allowing styling drive final expression, requires no pre. , seems odd thing pre tag do, or lack of do, want understand it.

edit: image show behavior. enter image description here

and html in situ enter image description here

pre meant hold phrasing content, div not 1 of content allowed. browsers deal can syntaxe errors.

https://www.w3.org/tr/html5/grouping-content.html#the-pre-element

you may use browser interprets error if missimbricate div , pre , forgot close 1 or both them. .pix_ind after .px_xml , not inside it, css not inherited anymore.


what can remove pre tag , use css white-space:pre; instead.

.px_xml {    white-space: pre;    /* here pre tag no longer needed */    font-family: monospace;    font-size: .7em;    color: #0000cc;    margin-bottom: 0;    display: block;  }  .px_ind {    margin-left: 2em;    display: inline-block;  }
<div class="px_xml">&lt;addfiledialogplaces id="<b>rvt_2016 places</b>" delete_prior="true"&gt;     <div class="px_ind">&lt;place id="favorites"&gt;c:\users\[px~user]\links&lt;/place&gt;     &lt;place id="datasets"&gt;c:\programdata\datasets&lt;/place&gt;        <div class="px_ind">&lt;place id="families"&gt;c:\programdata\assets\revit\2016\libraries&lt;/place&gt;</div>     &lt;place id="desktop"&gt;desktop&lt;/place&gt;     &lt;place id="my computer">::{20d04fe0-3aea-1069-a2d8-08002b30309d}&lt;/place&gt;     &lt;place id="my network places"&gt;::{208d2c60-3aea-1069-a2d7-08002b30309d}&lt;/place&gt;     &lt;place id="documents"&gt;personal&lt;/place&gt;     &lt;delete&gt;revit server network view&lt;/delete&gt;</div>  &lt;/addfiledialogplaces&gt;</div>


typical example show browser fixes somehow html: when build table, if tbody missing, browser add , can used selector in style sheet.

tbody td {    border: solid;    padding:1em;  }
<table>    <tr>      <td>is <code>tbody</code> missing ?</td>    </tr>  </table>


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -