文章类:加载顺序是否重要? [英] article class: does load order matter?

查看:94
本文介绍了文章类:加载顺序是否重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找网络,试图找到我的问题的答案,但似乎找不到直接的答案。我在我的工作中使用了很多文章类,但是并不需要知道它们是否按顺序加载,即页面上的第一个内容。



strong>

 < div id =examplearticle class =example1 example2 example3> 
这是div。
< / div>

另外我想问一下,如果我在示例1中设置背景并在示例中设置背景二,示例1的背景会在示例二下面。我想我是问,如果它会像堆叠divs在另一个之上。



我问的原因是因为我有一个文章类的背景为ajax装载机。不过,我需要直接在ajax加载器的顶部加载图像。我的想法是制作预算预加载器,而不需要所有的脚本捣乱。

再次感谢! 解决方案

你问的是应用CSS规则的优先顺序。简化:


  1. code> class =foo bar baz)。

    你可以在CSS文件中编写CSS声明。

      foo {...} 
    bar {.. 。}
    baz {...}

    后面的规则将覆盖先前的规则。


  2. 您正在将这些CSS规则中指定的属性应用于元素。元素只能有一个这样的属性,它们不会堆叠。如果两个CSS规则指定了相同的属性,则后面的规则会覆盖该元素上的该属性。

  3. >

     < div class =baz bar foo> 



    .foo {
    颜色:蓝色;
    border:1px纯绿色;
    }

    .bar {
    颜色:黑色;
    border-color:orange;
    }

    .baz {
    颜色:红色;
    保证金:10em;
    }

    同样,类中的类顺序=...属性无关紧要。所有三个类都应用于元素。首先, .foo ,然后 .bar ,然后 .baz 。该元素将具有以下属性,这是合并上述规则的结果:

      color:red; #from .baz 
    border-color:orange; #from .bar
    border-style:solid; #from .foo
    border-width:1px; #from .foo
    保证金:10em; #.baz

    (请注意,规则优先级实际上比这更复杂一些,实际上取决于选择器的特殊性,但以上内容适用于同样具体的选择器。)


    I have been searching the web to try and find an answer to my question but cant seem to find a direct answer. I use article classes a lot in my work, however never really needed to know whether they load in order i.e what comes first on the page.

    Example

      <div id="example" article class="example1 example2 example3">
       Here's the div.
      </div>
    

    Additionally I would like to ask, if I set a background in example 1 and set a background in example two, would the background of example 1 be there underneath example two. I guess I am asking if it would be like stacking divs on top of one another.

    The reason I ask is because I have an article class with a background of an ajax loader. However I need to load an image directly ontop of the ajax loader. Its my idea of making a budget preloader without all the scripting hastle.

    Thanks again!

    解决方案

    What you're asking about is the order of precedence of applying CSS rules. Simplified:

    1. It does not matter in which order you specify the classes on an element (class="foo bar baz").

    2. It does matter in which order you write the CSS declarations in your CSS file.

      foo { ... }
      bar { ... }
      baz { ... }
      

      Later rules override earlier rules.

    3. You are applying properties specified in these CSS rules to an element. An element can only have one such property, they do not "stack". If two CSS rules specify the same property, later rules overwrite that property on the element.

    Example:

    <div class="baz bar foo">
    

    .foo {
        color: blue;
        border: 1px solid green;
    }
    
    .bar {
        color: black;
        border-color: orange;
    }
    
    .baz {
        color: red;
        margin: 10em;
    }
    

    Again, the order of the classes in the class="..." attribute is irrelevant. All three classes are applied to the element. First, .foo, then .bar, then .baz. The element will have the following properties, which are the result of merging the above rules:

    color:        red;    # from .baz
    border-color: orange; # from .bar
    border-style: solid;  # from .foo
    border-width: 1px;    # from .foo
    margin:       10em;   # from .baz
    

    (Note that rule precedence is actually a little more complex than that and actually depends on the specificity of the selector, but the above goes for equally specific selectors.)

    这篇关于文章类:加载顺序是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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