p:first-child
doesn't apply for first paragraph if there is a <script>
in the top of <body>
in HTML-file.
If you move <script>
to the bottom of <body>
- it works.
And it doesn't matter where CSS-style is (it's among tags or it's a file)).
For example
p:first-child {
font-weight: bold;
}
it doesn't apply for first(or any) paragraph until I moved script to the bottom
:first-child
will select any element that is the first child of its parent element. p
will select any paragraph element. p:first-child
will select any paragraph element that is the first child of its parent element. If your paragraph is a direct descendant of the body element, having any other elements in the body before the paragraph will cause it to not be the first child of the body element. You could add a div around all your paragraphs and leave the script at the beginning of the body; the first child of the div would then be styled by p:first-child
if it is a paragraph element.