Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I center text on top of an image in both dimensions?
    primarykey
    data
    text
    <p>Thank you all for your prompt feedback, it has been very helpful. One issue remains: Neither <code>line-height</code>, nor <code>padding</code> seem to be able to center <b>both</b> text that is long enough to wrap around <i>and</i> text that fits neatly on one line in the middle of the picture when applied in a table cell. </p> <p>Oddly enough, the padding solution provided below by SwDevMan81 works flawlessly when applied to a div, but not a table cell...</p> <p>I apologize in advance for my naivety; this is my first foray into HTML and CSS.</p> <p>The code for the table is as follows:</p> <pre><code>&lt;table border="1"&gt; &lt;tr&gt; &lt;td class="imgcontainer"&gt; &lt;a href="#"&gt; &lt;img src="http://www.bigjimsburgers.com/burger.jpg" alt="" /&gt; &lt;span class="desc"&gt; Very long text that wraps around and is centered properly &lt;/span&gt; &lt;/a&gt; &lt;/td&gt; &lt;td class ="imgcontainer"&gt; &lt;a href="#"&gt; &lt;img src="http://www.bigjimsburgers.com/burger.jpg" alt="" /&gt; &lt;span class="desc"&gt; misaligned text &lt;/span&gt; &lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="imgcontainer"&gt; &lt;a href="#"&gt; &lt;img src="http://www.bigjimsburgers.com/burger.jpg" alt="" /&gt; &lt;span class="desc"&gt; misaligned text &lt;/span&gt; &lt;/a&gt; &lt;/td&gt; &lt;td class ="imgcontainer"&gt; &lt;a href="#"&gt; &lt;img src="http://www.bigjimsburgers.com/burger.jpg" alt="" /&gt; &lt;span class="desc"&gt; Very long text that wraps around and is centered properly &lt;/span&gt; &lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;style type="text/css"&gt; .imgcontainer { overflow: hidden; text-align: center; } .imgcontainer img { float: left; background: #fff; width: 200px; height: 200px; } .imgcontainer a .desc { display: none; font-size: 1.0em; } .imgcontainer a:hover { cursor: pointer; text-decoration: none; } .imgcontainer a:hover .desc { display: -webkit-box; display: -moz-box; display: box; -webkit-box-align: center; -moz-box-align: center; box-align: center; background: #DDD; filter: alpha(opacity=75); opacity: .75; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=75)"; position: absolute; width: 200px; height: 200px; } &lt;/style&gt; </code></pre>
    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