Style and script tag sequence

Typically an HTML page contains the following tags

<script>
<link>
<style>

I found the number of times changing the sequence of these tags, corrupted by the layout of the page.

So what will be the reason and what are the points to avoid this situation?

EDIT

After looking at @Anurag's answer, I actually assume that we have no case where we have two definitions of the same css class, in different style or link tags.

My main concern is the css and script sequence. Do we have to have the whole css class before writing any kind of JavaScript or it doesn't matter at all (which I don't think).

For example jqtouch floaty extension . In this case, if I define the class .floatybefore the tag JavaScript, then it does not work. I hope you understand my point.

+3
3

<link> <style>.

<link> , . <style> , .

, , , - . <link> <style>. ( ) . .

. . , <link>. ? , .

+4

, HTML. , , HTML. , , - , .

, , , .

+1

.

<script> are executed sequentially if the async or defer attributes are not used, therefore the script tag that appears later on the page can override previously declared functions / variables /.

Similarly, style sheets are applied and have specificity rules regarding conflict handling, etc. For example, a style attribute takes precedence over everything, and if a style appears later, it overrides the previous style. For instance,

<style>
    .page {
        background-color: #CCC;
    }
</style>

<style>
    .page {
        background-color: #222;
    }
</style>

The color of the page will be #222.

0
source

Source: https://habr.com/ru/post/1769688/


All Articles