There are three main components of CSS: selectors, properties, and values.
-
Selectors: CSS selectors are used to select HTML elements to apply styles to. They specify which elements on a webpage the styles should be applied to. There are many types of selectors, including element selectors, class selectors, ID selectors, attribute selectors, and more.
-
Properties: CSS properties define the style or behavior of an HTML element selected by a CSS selector. They specify what should be changed about the appearance or behavior of the selected element. Some common CSS properties include font-size, color, background-color, border, padding, margin, and more.
-
Values: CSS values are used to define the specific settings for a CSS property. They determine the exact appearance or behavior of the selected element. For example, a value for the color property might be "red," "#FF0000," or "rgb(255, 0, 0)".
In summary, CSS selectors are used to target specific HTML elements, CSS properties define the style or behavior of those elements, and CSS values determine the specific settings for those properties. By using selectors, properties, and values together, you can create custom styles for HTML elements that help to make your web pages more visually appealing and user-friendly.
<font color="red">Red Heading with Html Only</font>
This is an old school way of applying styles to text within an HTML document. The <font>
tag was commonly used in earlier versions of HTML to specify the font, color, and size of text on a webpage.
In this example, the text "Red Heading with Html Only" is wrapped in a <font>
tag with the attribute color="red"
. This sets the color of the text within the <font>
tag to red.
However, the use of the <font>
tag is now deprecated in favor of CSS styles, which provide more advanced and flexible ways to style HTML elements. Instead of using the <font>
tag, it is recommended to use CSS styles within a <style>
tag or an external CSS file to style text and other elements on a webpage.
So, while this old school HTML code still works in modern web browsers, it is no longer considered a best practice and should be replaced with CSS styles for better maintainability and flexibility.
h1 {
background: yellow;
color: black;
}
p {
background: green;
color: white;
}
-
h1
is the selector, which targets all<h1>
elements in the HTML document. The curly braces{}
that follow the selector enclose the CSS declarations for that selector. -
background
is the property, which sets the background color of the selected elements. The valueyellow
is the value assigned to that property, meaning the background color of all<h1>
elements will be yellow. -
color
is another property, which sets the text color of the selected elements. The valueblack
is the value assigned to that property, meaning the text color of all<h1>
elements will be black.
The second block of code is very similar:
-
p
is the selector, which targets all<p>
elements in the HTML document. -
background
is the property, which sets the background color of the selected elements. The valuegreen
is the value assigned to that property, meaning the background color of all<p>
elements will be green. -
color
is another property, which sets the text color of the selected elements. The valuewhite
is the value assigned to that property, meaning the text color of all<p>
elements will be white.
In summary, these CSS styles will make all <h1>
elements have a yellow background and black text, and all <p>
elements have a green background and white text.
No comments:
Post a Comment