Today I come up with another topic how to use Css Syntax in Html. The CSS syntax is divided into three parts: property: value selector. Typically, the selector is an HTML tag or element, such as p>, table>, or h1>. An internal style sheet is shown in the CSS code below. The selector (in this case, the p> tag) is bolded.
<html>
<head>
<style type="text/css">
p
{
color: red
}
</style>
</head>
<body>
<p>
The text in this CSS example will be red.
</p>
</body>
</html>
_______________________________________
To see what the code creates, go to CSS Example.
Try it out for yourself. In the textbox below, type the HTML code to make a new link.
<html>
<head>
<style type="text/css">
p
{
color: red
}
</style>
</head>
<body>
<p>
The text in this CSS example will be red.
</p>
</body>
</html>
<head>
<style type="text/css">
p
{
color: red
}
</style>
</head>
<body>
<p>
The text in this CSS example will be red.
</p>
</body>
</html>
__________________________________
Multiple Property Specification
You must use a semi-colon to separate each property if you want to specify more than one (;).
This is demonstrated in the CSS code example below.
<html>
<head>
<style type="text/css">
p
{
color: red;
font-family: arial;
font-size: 100%;
}
</style>
</head>
<body>
<p>
The text in this CSS example will be red.
</p>
</body>
</html>
_________________________________________
Choosing Values
The attribute is given a value, such as determining the font's colour, font style, or size.
The values in the following CSS code example are made bold.
<html>
<head>
<style type="text/css">
p
{
color: red;
font-family: arial;
font-size: 100%
}
</style>
</head>
<body>
<p>
The text in this CSS example will be red.
</p>
</body>
</html>
______________________________________________
The Class Picker
Different styles for the same type of HTML tag/element can be defined using class selectors. For example, the class selector enables you to have 2 sorts of paragraphs on your web page where one is aligned to the left and another that is center aligned.
The CSS code below is an example of how this can be done.
<style type="text/css">
p.left
{
text-align: left
}
p.center
{
text-align: center
}
</style >
<body>
<p class="left">
This paragraph has a class selector "left".
</p>
<p class="center">
This paragraph has a class seceltor "center".
</p>
</body>
________________________________________________
Selectors for Grouping
Selectors can be grouped if they have the same declarations. A comma must be used to separate each selector.
The CSS code in the following example groups the header components and makes the text in red.
<style type="text/css">
h1,h2,h3
{
color: red
}
</style >
<body>
<h1>
The text in this heading will be red.
</h1>
<h2>
The text in this heading will be red.
</h2>
<h3>
The text in this heading will be red.
</h3>
</body>
__________________________________
A Few Remarks
Per HTML tag/element, you can only specify one attribute. The CSS code in the following example is incorrect.
<p class="right" class="right">
This is a paragraph.
</p>
.center {text-align: center}
This heading will be center-aligned
</h1>
<p class="center">
This paragraph will also be center-aligned.
</p>
CSS Comment
p
{
font-size: 120%;
/* This is another comment */
color: black;
}
0 Comments