Answer to Question #243462 in HTML/JavaScript Web Application for Gopi

Question #243462
Write a short note on 10
a. The three different ways of applying CSS to a web page
b. State two benefits of using id and class selectors for a developer.
With an example program
1
Expert's answer
2021-09-28T17:13:17-0400

You can apply CSS styles to a web page using 3 ways:


Inline CSS - You can apply CSS style inside the HTML tags(elements) that are called inline CSS.

<!doctype html> 
<html> 
  <head> 
    <meta charset="utf-8"> 
    <title>Inline CSS</title> 
  </head> 
  <body> 
    <p style="color:#E80A0E;font-size:14px;">This is Inline CSS Example.</p> 
  </body> 
</html> 

Internal Style Sheet : You can apply CSS styles Inside <head> section in HTML using <style></style>.

<!doctype html> 
<html> 
  <head> 
    <meta charset="utf-8"> 
    <title>Internal CSS</title> 
    <style type="text/css"> 
        p { 
          color:#E80A0E; 
          font-size:14px; 
        } 
      </style> 
  </head> 
  <body> 
    <p>This is Internal Style Sheet Example.</p> 
  </body> 
</html> 

External Style Sheet: Create another file save it with .css extension and then link this css file using <link>.

<!-- example.html -->
<!doctype html> 
<html> 
  <head> 
    <meta charset="utf-8"> 
    <title>External CSS</title> 
    <link href="style.css" rel="stylesheet" type="text/css"> 
  </head> 
  <body> 
    <p>This is External Style Sheet Example.</p> 
  </body> 
</html>


// styles
p { 
  color:#E80A0E; 
  font-size:14px; 
} 



The main benefit of setting class or ID is that you can present the same HTML element differently, depending on its class or ID


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS