简体   繁体   English

禁用 CSS 高度的行为:自动和宽度:特定 class 的自动

[英]Disabling the behaviour of CSS Height:auto and Width:auto for a specific class

I'm utilising TinyMCEv4 for a solution which has the built in image toolbar plugin.将 TinyMCEv4用于具有内置图像工具栏插件的解决方案。

When a user resizes an image within the WYSWYG editor, the HTML for the image is updated accordingly via the image width/height attributes on the image element:当用户在 WYSWYG 编辑器中调整图像大小时,图像的 HTML 通过图像元素上的图像宽度/高度属性进行相应更新:

<img src="img.jpg" alt="Image" width="300" height="200">

If the user were to resize the image by doubling the size of it within the WYSYWG editor of TinyMce, the html would is updated to:如果用户要通过在 TinyMce 的所见即所得编辑器中将图像的大小加倍来调整图像大小,则 html 将更新为:

<img src="img.jpg" alt="Image" width="600" height="400">

The problem is - I've got some CSS which prevents the width and height attributes from working.问题是 - 我有一些 CSS 阻止宽度和高度属性工作。 The following CSS is applied to all images sitewide, for responsive purposes:出于响应目的,以下 CSS 应用于全站所有图像:

img {
    width: 100%;
    height: auto;
}

Is there a way to reverse these CSS rules so that the width/height attributes work for images within a specific class?有没有办法逆转这些 CSS 规则,以便宽度/高度属性适用于特定 class 内的图像?

This is an answer for the not-too-distant future.这是不久的将来的答案。

Cascade Layers are coming.级联层来了。 Because the presentational hints that are obtained from the HTML attributes are considered as belonging to a cascade precedence below author layers, we can use revert-layer to undo the assigned setting here.因为从 HTML 属性中获得的 presentational hints 被认为属于作者层以下的级联优先级,所以我们可以使用revert-layer撤消此处的分配设置。

You can already do this in Firefox. Chromium and Safari should have implementations shortly, if not already.您已经可以在 Firefox 中执行此操作。Chromium 和 Safari 应该很快就会实现,如果还没有的话。

 img { width: 100%; height: auto; } img[height] { height: revert-layer; } img[width] { width: revert-layer; }
 <img src="https://via.placeholder.com/100" alt="Image" width="300" height="200">

In general, you would use revert-layer in the same layer as the settings you needed to revert.通常,您会在与需要恢复的设置相同的层中使用revert-layer Here, all our CSS is in the "unlayered" layer.在这里,我们所有的 CSS 都在“未分层”层中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM