3 ways to set style properties with CSS

Posted: 2024-03-15 15:36:09 Author: Danny_hi I want to comment
style attribute can be used in most of the tags in HTML, this article mainly introduces the CSS set style attribute of 3 methods, the article through the example code is introduced in very detail, the need for friends below with small series to learn to learn it

You can write css styles into the style attribute of an element:

1. Write the style directly into the style attribute. This style is called inline style. Inline style only works for the content in the current element.

eg:

<p style="color:blue; font-size: 50px;" > When is the moon, the wine asked the sky! </p>

2. You can also write CSS styles into the style TAB in the head, called internal styles. Write the style sheet into the style tag, and then select the specified element through the CSS selector

<head> <style type="text/css"> p{ color:green; font-size:40px; } </style> </head> <body> <p> When is the moon, the wine ask the sky! </p> </body>

3. You can also write a style sheet into an external CSS file, and then introduce the external CSS file into the current page through the link tag. The href sets the relative path of the external css file, so that the structure and presentation are completely separated.

<link rel="stylesheet" href="css/style.css" />

Other: In CSS, the style of the ancestor element is also inherited by its descendants; With inheritance, you can set some basic styles to ancestor elements so that all descendant elements will automatically inherit these styles. However, not all styles are inherited by the quilt element. For example, background related styles are not inherited.

eg:

<! DOCTYPE html> <html> <head> <style type="text/css"> body{ font-size: 25px; } </style> </head> <body> <p> When is the moon? </p> <p class="p1"> When is the moon? </p> <p> When is the moon? </p> <p> When is the moon? </p> </body> </html>

To this article about the 3 methods of CSS setting style property is introduced to this, more related CSS setting style property content please search the script home previous articles or continue to browse the following related articles, I hope you will support the script home in the future!

  • Tag: css Style attribute

Related article

Latest comments