Css Syntax in Html

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.

Css Syntax in Html


<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>

___________________________________________

The value is the feature of the selector you wish to change, such as colour, font, height, width, and so forth.

In the following CSS code example, the property (colour) 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>

__________________________________

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>

You may also use the selector without the tag name to set a style that will be applied to all HTML elements with a specific class. All HTML components with the class="center" will be center-aligned in the example below:

.center {text-align: center}


Both the h1 and p elements in the code below have the class="center" attribute. This indicates that both items will adhere to the ".center" selector's rules:

<h1 class="center">
This heading will be center-aligned
</h1>
<p class="center">
This paragraph will also be center-aligned.
</p>
_____________________________________________

Do NOT start a class name with a number! In Firefox/Mozilla, it will not work.

CSS Comment


You can add comments to your CSS code in the same way that you may to HTML code. The comment will be disregarded by the web browser, exactly as it is in HTML. As the following example, a CSS comment starts with "/*" and ends with "*/."

/* This is a comment */
p
{
font-size: 120%;
/* This is another comment */
color: black;
}

Post a Comment

0 Comments