Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Modernizr to Detect Max-Width on Inline Elements
    primarykey
    data
    text
    <p><strong>The Reason (sorry, I'm wordy, I know)</strong></p> <p>This might be a tricky, or unusual request but on the website I manage I have a lot of pages containing images stored inside a table. Users put an image there for captions or to just make sure the layout is what they expect. Most of my users are not savvy enough to use DIV's so my tables are never going to go away.</p> <p>I'm working on making my site responsive but one of the issues I've encountered with these images is that browsers behave differently when an image is in a table and the viewport is resized. Firefox, for example, will not scale an image using max width 100% if it is nested in a table. <a href="https://stackoverflow.com/questions/2923710/why-do-firefox-and-opera-ignore-max-width-inside-of-display-table-cell">According to this previous question</a>, this is partly because there is no specification about how to handle an image when nested in an inline element. </p> <p>The only way I've found to fix this problem is to pull out the image's width/height from the img tag and set the width to be 100% in my CSS. With this in place Firefox consistently scales down images even if they are in table cells. <a href="http://jsfiddle.net/cloudkiller/HvSuY/10/" rel="nofollow noreferrer">Here's an example of the type of thing I'm trying to fix</a>. Drupal/CKEditor like to put an image's width in a style tag and I need my CSS/JS stuff to fix it.</p> <p><strong>The Question</strong></p> <p>I only want my CSS/JS fix to apply to browsers that don't support max width within inline elements. Is there a way to test for this in Modernizr? In the current iteration of my site's JS, I'm simply doing a browser check with Modernizr to see if a user is using firefox and then applying the fix if detected. For those curious, this is how I'm doing it (<a href="https://stackoverflow.com/questions/11318389/modernizr-checks-to-detect-firefox">source for the firefox check</a>).</p> <pre><code>Modernizr.addTest('firefox', function () { return !!navigator.userAgent.match(/firefox/i); }); jQuery('.firefox #zone-content img').each(function(){ jQuery(this).removeAttr('width'); jQuery(this).css('width', ''); }); </code></pre> <p>I'm hoping there is a simple way to rewrite this so I don't have to use browser detection for this but my understanding of the modernizr addTest API is limited. Hopefully someone else has created something similar and can share their knowledge.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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