代码之家  ›  专栏  ›  技术社区  ›  Martin Plante

是否有办法将样式强制到已具有style=”“属性的div元素

  •  24
  • Martin Plante  · 技术社区  · 16 年前

    div 用一个 style="overflow: auto" 属性
    div 使用 overflow: hidden; ?

    6 回复  |  直到 8 年前
        1
  •  85
  •   thanksd thibaut noah    9 年前

    你可以加上 !important 直到你的风格结束,如下所示:

    element {
        overflow: hidden !important;
    }
    

        2
  •  12
  •   thanksd thibaut noah    9 年前

    你试过设置吗 !important 在CSS文件中?比如:

    #mydiv { overflow: hidden !important; }
    
        3
  •  4
  •   JSW189    11 年前

    overflow .

    overflow:hidden !important
    

        4
  •  2
  •   BrewinBombers    16 年前

        5
  •  2
  •   TheZenker    16 年前

    如下面粘贴的W3C规范所述,Magnar是正确的。似乎是这样!添加了重要关键字以允许用户覆盖元素级别的“烘焙”样式设置。由于您无法控制html,因此这可能是您的最佳选择,尽管这不是一种正常的设计模式。

    W3C CSS Specs

    摘录:

    6.4.2 !重要规则 被单。默认情况下,在 作者的样式表将覆盖中的样式表 3).

    However, for balance, an "!important" declaration (the keywords
    

    “!”和“重要”遵循 声明)优先于 用户样式表可能包含 “!重要”声明和用户 “!重要”规则覆盖作者 为用户提供特殊要求 (大字体、颜色组合、,

    Note. This is a semantic change since CSS1. In CSS1, author
    

    “!重要”规则优先 超过用户“!重要”规则。

    Declaring a shorthand property (e.g., 'background') to be
    

    将其所有子属性声明为

    Example(s):
    
    The first rule in the user's style sheet in the following example
    

    包含一个“!重要”声明, 它将覆盖相应的 床单第二项宣言将: 也因为被标记而获胜 “!重要”,因此将失败 第二条规则 在速记属性上的样式)。而且 第二作者规则 规则是“重要的”。这表明 在作者风格中也起作用 被单。

    /* From the user's style sheet */
    P { text-indent: 1em ! important }
    P { font-style: italic ! important }
    P { font-size: 18pt }
    
    /* From the author's style sheet */
    P { text-indent: 1.5em !important }
    P { font: 12pt sans-serif !important }
    P { font-size: 24pt }
    
        6
  •  0
  •   17 of 26    16 年前