CSS Classes and selector

You may be wondering if it is possible to give an HTML element multiple looks with CSS. Say for example that sometimes you want the font to be large and white, while other times you would prefer the font to be small and black. CSS would not be very useful if it did not allow you to have many different types of formats for a single HTML tag. Well, you are in luck! CSS allows you to do just that with the use of classes.
The Format of Classes
Using classes is simple. You just need to add an extension to the typical CSS code and make sure you specify this extension in your HTML. Let’s try this with an example of making two paragraphs that behave differently. First, we begin with the CSS code, note the red text.
CSS Code:

p.first{ color: blue; }
p.second{ color: red; }

HTML Code:

<html>
<body>
<p>This is a normal paragraph.</p>
<p class="first">This is a paragraph that uses the p.first CSS code!</p>
<p class="second">This is a paragraph that uses the p.second CSS code!</p>
</body>
</html>

You can use CSS classes with any HTML element! However, what happens if we had already defined a value for the default

tag, would this cause any problems for classes of the paragraph tag?
It may be easier to imagine that the CSS for a generic HTML element is the starting point and the only way to change that look is to overwrite the attributes using CSS classes. Please see the example below for a visual of this tricky topic.
CSS Code:

p{ color: red; font-size: 20px; } 
p.test1{ color: blue; } 
p.test2{ font-size: 12px; }

HTML Code:

<html>
<body>
<p>This is a normal paragraph.</p>
<p class="test1">This is a paragraph that uses the p.test1 CSS code!</p>
<p class="test2">This is a paragraph that uses the p.test2 CSS code!</p>
</body>
</html>

CSS Selectors
CSS selectors allow you to select and manipulate HTML element(s).
CSS selectors are used to “find” (or select) HTML elements based on their id, classes, types, attributes, values of attributes and much more
The element Selector
The element selector selects elements based on the element name.

<!DOCTYPE html>
<html>
<head>
<style>
p {
    text-align: center;
    color: red;
} 
</style>
</head>
<body>
<p>All paragraph will be affected by the style.</p>
<p id="para1"> Welcome Me too!</p>
<p> Welcome And me!</p>
</body>
</html>

The id Selector
The id selector uses the id attribute of an HTML tag to find the specific element.
An id should be unique within a page, so you should use the id selector when you want to find a single, unique element.
To find an element with a specific id, write a hash character, followed by the id of the element.
The style rule below will be applied to the HTML element with id=”para21″:

<!DOCTYPE html>
<html>
<head>
<style>
#para21 {
    text-align: center;
    color: red;
}
</style>
</head>
<body>
<p id="para21">Hello and Welcome</p>
<p>This paragraph is not affected by the style.</p>
</body>
</html>

milf porn

Admin has written 171 articles