Note that there are some explanatory texts on larger screens.

plurals
  1. POMysterious Padding / Margin Around Images
    primarykey
    data
    text
    <p>Please see the following jsFiddle: <a href="http://jsfiddle.net/Leng/kQvNH/" rel="nofollow">http://jsfiddle.net/Leng/kQvNH/</a></p> <p>Can anyone explain why there appears to be a substantial amount of padding (approx. 15px above and 4px below) around every line of horizontal dots? The images are only 2px tall. Where is the padding coming from?</p> <p><strong>PLEASE NOTE:</strong></p> <p>For me, this mysterious padding around images is <strong>only happening</strong> when I begin my documents with the HTML5 heading:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; </code></pre> <p>Images <strong>display normally</strong> (no padding) when I use -<em>any other</em>- header, such as HTML4 or this XHTML heading for a webpage:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; </code></pre> <p>So this appears to be an HTML5 inconsistency. I would like to switch to the standard HTML5 headings, but this little annoyance is preventing me from doing so.</p> <p>Thank you for any guidance.</p> <p><strong>THE SOLUTION:</strong></p> <p>Here is the jsFiddle with the solution: <a href="http://jsfiddle.net/Leng/Sn2PC/" rel="nofollow">http://jsfiddle.net/Leng/Sn2PC/</a></p> <pre><code>img { display:block; margin:0 auto; } </code></pre> <p>This is based on Chris's answer below.</p> <p><em>Please note that setting font-size:0 or line-height:0 is <strong>not</strong> a solution, because that messes (obviously) with the font size and line height.</em></p> <p>And again, setting the display to block and establishing an auto-margin was not necessary to accomplish normal, centered, un-padded images in HTML4 or XHTML.</p> <p>HTML5 has created this "feature", where images are inline and will have padding based on line-height or font-size.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload