在样式属性中使用导入 [英] Using import within a style attribute

查看:75
本文介绍了在样式属性中使用导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,让我说清楚一点.我说的是在html style=''属性中导入css文件.您可以假设使用Internet Explorer 9.

First let me be perfectly clear. I am talking about importing a css file within a html style='' attribute. You can assume Internet Explorer 9.

我不关心<link>标记或其他导入CSS的方法.

I DON'T CARE ABOUT <link> TAGS or other methods of importing css.

让我们说我有一个简单的.css文件:

Lets say I have a simple .css file:

#inputArea{
width: width:72px;
}

为什么此导入无效?

<input type=text id='inputArea' style="@import url(simple.css);">

此导入何时起作用?

<style>
    @import url(simple.css);
</style>

style=""属性何时导入?为什么这个不起作用?

When does a style="" attribute import work? Why isn't this one working?

推荐答案

style属性采用

The style attribute takes a list of declarations, and applies properties from that list specifically to the owner element.

@import不是声明,并且不适用于特定元素.它只能与构成@-constructs一起出现在样式表的顶层. "rel =" noreferrer>声明.

@import is not a declaration and does not apply to a particular element. It can only appear in the top level of a style sheet along with the selectors and other @-constructs that comprise the statements.

将包含选择其他元素的规则的样式表导入元素的内联样式没有任何意义.就像在说:

It doesn't make any sense to import a stylesheet, that contains rules selecting other elements, into an element's inline style. It's like saying:

<input type=text id='inputArea' style="body { margin: 0 }">

这毫无意义.

这篇关于在样式属性中使用导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆