CSS, How to Padding Padding and more Padding

Monday, 24. August 2009

Padding can be applied to the outside edges of the content area of any block level or inline element. Padding creates the space between the edge of the element and its content.

Like margins, padding can be applied to individual sides of a box.

p {padding: 10px}
h1 {padding-top:0px}
h2 {padding-right:5px}
h2 {padding-bottom:7px}
h3 {padding-left:10px}

Padding can alse be applied using a single shorthand property. If one padding value is specified, it applies to all sides of an element:

p {padding:5px}

If two values are specified, the top and bottom margins are set to the first value and the right margins are set to the second:

p {padding: 5px 0}

If three values are specified, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third:

p {padding: 10px 0 20px}

If four values are specified, they apply to the top, right, bottom, and left:

p {padding 5px 0px 7px 15px}

CSS, How to deal with background color and images.

Sunday, 23. August 2009

The background-color property sets the background color of an element.

The backgound-image property applies a background image to an element, which will appear on top of any background-color.

body {
background-color:#000
}

h1 {
background-image:url(header.png);
}

CSS, How to use Descendant Selectors

Wednesday, 5. August 2009

Sample HTML

<body>
<div id=”content”>
<h1> Heading Here </h1>
<p> Lorem ipsum dolor sit amet. </p>
<p>Lorem ipsum dolor <a href=”#”>sit</a> amet.</p>
<div>

<div id=”nav”>
<ul>
<li><a href=”#”>Item 1</a></li>
<li><a href=”#”>Item 2</a></li>
<li><a href=”#”>Item 3</a></li>
</ul>
</div>

<div id=”footer”>
Lorem ipsum dolor <a href=”#”>sit</a> amet.
</div>
</body>

Descendant Selectors

Descendant selectors are used to selected elements that are descendants of another element

For example, in the HTML sample shown above, three <a> elements are descendants of the <li> elements. To target these three <a> elements only, and not all other <a> elements, a descendant selector can be used. This selector targets any <a> element that is nested inside an <li> element.

li a {
color:green;
}

Descendant selectors do not have to use direct descendant elements. For example, the <a> element is a descendant of <div id=”nav”> as well as the <li> element. This means that #nav a can be used as a selector as well.

#nav a {
color: red;
}

Descendant selectors also can include multiple levels of descendants to be more specific.

#nav ul li a {
color: green;
}

How to use CSS Rules

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.

Tags: , , , , , .