Home > Web Front-end > CSS Tutorial > Why Does `max-width` Ignore Images Inside `display: table-cell` in Firefox and Opera?

Why Does `max-width` Ignore Images Inside `display: table-cell` in Firefox and Opera?

Linda Hamilton
Release: 2024-10-27 14:24:29
Original
845 people have browsed it

Why Does `max-width` Ignore Images Inside `display: table-cell` in Firefox and Opera?

Browser Inconsistencies with max-width Inside display: table-cell

In certain circumstances, the max-width style property is ignored within display: table-cell elements in Firefox and Opera, even if it displays correctly in Chrome and IE. This inconsistency raises questions about its cause and the most appropriate solution.

Cause

According to the W3C specification, max-width does not apply to inline elements. However, images within display: table-cell are considered block-like in most browsers, while Firefox and Opera treat them as inline. This difference in interpretation results in the inconsistent behavior.

Workaround

One workaround is to place the display: table-cell wrapper div inside another div with display: table and table-layout: fixed. This forces Firefox and Opera to respect the max-width rule.

Example

<code class="html"><div style="display: table">
  <div style="display: table-cell; padding: 15px; width: 200px">
    <img src="image.jpg" style="max-width: 100%" />
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. ...
    </p>
  </div>
</div></code>
Copy after login

Recommendation

The most standards-compliant approach is to avoid using max-width on inline elements, including images within display: table-cell. Instead, use alternative methods for controlling the width of such elements.

The above is the detailed content of Why Does `max-width` Ignore Images Inside `display: table-cell` in Firefox and Opera?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template