Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

How to Define and Apply a Style Class

Defining a style class is similar to defining styles rules for any html element except that a style class has a name that you use to apply it to only specific incidences of elements, for example to only some paragraph elements, or to apply it to dissimilar elements, for example to paragraphs and divs.

The name for a style class cannot begin with a number or a hyphen followed by a number. The name cannot contain spaces, and the only punctuation characters allowed are the hyphen (-) and the underscore (_).

When defining a class in a style block or in a style sheet, put a dot (.) in front of the name. An example of defining a style class named appbtn is shown below.

<style type="text/css">
.appbtn
{
width:130px;
height:60px;
padding:4px;
border-style:solid;
border-color:#009000;
background-color:#66ff66;
font-family:verdana;
font-size:14px;
box-shadow: 6px 6px 4px #a0a0a0;
}
</style>

When applying the class to an html element, add the class attribute in the element's opening tag, and set the class attribute's value to the name of the class - without the dot. An example of applying the class appbtn to an html element is shown below.

<div class="appbtn">This box was styled by a class named appbtn</div>

The result of the code in this example is shown below.

This box was styled by a class named appbtn

By the way, you may see style code that looks like a class definition except instead of a dot, it puts a pound sign (#) in front of the name. An example of this is shown below.

<style type="text/css">
#appbtn
{
width:130px;
height:60px;
padding:4px;
border-style:solid;
border-color:#009000;
background-color:#66ff66;
font-family:verdana;
font-size:14px;
box-shadow: 6px 6px 4px #a0a0a0;
}
</style>

This is not a CSS class selector, but instead it's an id selector. Think of a class like a class room of students of all ages, sexes, races, and creeds. But they are all in the same class. However the id selector (#) selects only one individual (or one specific html element), the one with that id. An example of applying the id selector appbtn to an html element is shown below.

<div id="appbtn">This box was styled by the id selector #appbtn</div>

More CSS Quick Reference:
• position:fixed
• How to Define and Apply a Style Class
• Set the Border Color
• Set the Font Boldness
• Set a Background Image
• Set the Font Slant
• Use word-wrap Property to allow Line Breaks in the Middle of Words
• Set an Element's Float
• CSS background-origin Positions Background
• Set the Background Properties

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro



Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2024 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268