Tuesday, 11. August 2009
Header styles also can be used to style the <p> element. The CSS rules can be placed in the head of the document using the style element. Like inline styles, header styles, header styles should be avoided where possible because the styles are added to the HTML markup rather than in external CSS files.
There are cases where header styles might be the preferred option in specific instances, such as a CSS rule that is specific to one page within a large website. Rather than add this rule to an overall CSS file, a header style may be used.
The type=”text/css” attribute must be specified within the style element in order for browsers to recognize the file type.
<title>CSS Tutorial</title>
<style type=”test/css” media=”screen”>
p {
font-family: arial, helvetica, sans-serif;
margin: 1em;
padding: 1em;
background-color: gray;
width: 10em;
}
</style>
</head>
Posted in CSS Applying Styles by frenchsquared -
Friday, 31. July 2009
In this “CSS How To Tutorial”, you will learn the syntax and rules of the Cascading Style Sheet (CSS) language. You will learn the components of CSS rules, including selectors, declarations, properties, and values. You will learn how to style a series of simple HTML elements. You will also learn how to use shorthand properties.
Setting Up the HTML Code
The HTML code for this How To Tutorial will have three main elements the <h1>, <h2> and <p> tags.
<h1> CSS Headings One</h1>
<h2> CSS Heading Two</h2>
<p> Some text about your css tutorial would go here</p>
Creating a Rule Set
A css rule or css rule set, is a statement that tells a browser how to render the elements on an HTML page. A css rule set consists of a selector followed by a declaration block. Inside the declaration block, there can be one or more declarations. Each declaration contains a property and a value.
| selector |
Declaration block |
|
|
|
declaration |
|
declaration |
|
|
Property |
Value |
Property |
Value |
| .body |
{color: |
Red; |
padding: |
5px;} |
The first step in creating a rule set is to decide on a css selector. The selector “selects” the elements on an HTML page that are affected by the css rule set. The selector consists of everything up to the first left curly bracket.
The selectors for this CSS How To Tutorial or H1, H2, and P
The declaration block is the container that consists of everything between (including) the curly brackets. Inside the declaration block, there are one or more declarations. Declarations tell a browser how to draw any element on a page that is selected. A declaration consists of a property and one or more values, separated by a colon. The end of each declaration is indicated with a semicolon.
Setting Up the CSS Code
<style type=”text/css”>
<!–
h1 {text-align: center; }
h2 {font-style: italic; }
p {color: maroon;}
–>
</style>
The property is an aspect of the element that you are choosing to style. There can be only one property within each declaration unless a shorthand property is used.
The value is the exact style you want to set for the property. Values can include length, percentage, color, url, keyword, and shape.
The first rule set will target the <h1> element and align it to the center of the browser window.
The second rule set will target the <h2> element and render it in italics.
The third selector will target the <p> element color all the text found inside the element maroon.
Posted in Understanding CSS by frenchsquared -