Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why the same styling gives different results

Here I use an inline styling:

<!DOCTYPE html>
<html>
  <body>
    <p style="background-color: tomato; padding: 5px;">Seme text<p>
  </body>
</html>

Here I use internal styling:

<!DOCTYPE html>
<html>
    <head>
        <style>
            p
            {
                background-color: tomato; 
                padding: 5px;
            }
        </style>
    </head>
    <body>
        <p>Seme text<p>
    </body>
</html>

The results below in picture:
illustracion about the problem
Can someone explain why I get those two different results?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am expecting the two style be the same

>Solution :

In both cases, you are not closing the p tag like </p>

so you have 2 p tags in your HTML

inline style only styles one ( the first one, on which it is applied ).

The internal style applies to both and that is why you see 2 rectangles.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading