0

I am new to CSS and I have just read the topic regarding the hierarchy of the various types of applying a style. More specifically I read that the embedded method overrides the external always but when I run some tests this wasn't always the case.

The declaration of an embedded style and an external is done in the head element of the web page and what I found was that the embedded style overrides the external only if is written after the external.

for example let's say that we have the following code snippet

  <head>
<title>Testing CSS Hierarchy</title>

<style type="text/css">p {color:#fff;}</style>

<link rel="stylesheet" media="screen" type="text/css" href="css/screen/external.css"/>

</head>

in the above example the external rule overrides the embedded!!!!

Did I understand something wrong or this is normal?

Thnak you in advance.

2
  • You haven't provide enough of an example. The hierarchy is usually, external --> head -- > inline. Commented May 20, 2014 at 16:06
  • This is what I read that the hierarchy is usually external (which is declared in the head element) head (embedded or internal) and inline. However if you have external and embedded in "head" the effective style is the last. Commented May 21, 2014 at 7:40

2 Answers 2

1

Try it with the embedded styles after the link to the external file:

<head>
    <link rel="stylesheet" media="screen" type="text/css" href="css/screen/external.css"/>
    <style type="text/css">p {color:#fff;}</style>
</head>

The css that comes after overrides the css that comes before.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your answer I assumed this was the case but I wanted to be sure!!
1

The rule is simple in this case the last is the one that is used. Try doing the reverse:

<head>
   <title>Testing CSS Hierarchy</title>
   <link rel="stylesheet" media="screen" type="text/css" href="css/screen/external.css"/>
   <style type="text/css">p {color:#fff;}</style>
</head>

1 Comment

In reverse it works, it applies the embedded! Thanks it was not clear in the book!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.