In order to apply style to an html element or elements, you have to be able to select that element or those elements, that's where CSS selectors come into play. This article shows you how to use class selectors, id selectors, descendant selectors, grouped selectors, pseudo-class selectors and attribute selectors.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

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

HTML5 Solutions: Essential Techniques for HTML5 Developers

Essential Techniques for HTML5 Developers

HTML5 brings the biggest changes to HTML in years. Web designers now have new techniques, from displaying video and audio natively in HTML, to creating realtime graphics on a web page without a plugin.

This book provides a collection of solutions to all of the most common HTML5 problems. Every solution contains sample code that is production-ready and can be applied to any project.

Click Here

Understanding CSS Selectors

A CSS style sheet consists of rules that define how html elements should be displayed on a webpage. Each rule consists of one or more selectors, one or more properties, and one or more values that each property should be set to. An example of a basic selector is shown below.

p
{
font-family: verdana;
font-weight: bold;
}

The selector above is p, which selects html paragraph elements. The properties of the selected elements are listed within curly brackets. The property names and values are separated by a colon, and property-value pairs are separated by semicolons. This rule specifically sets paragraphs font to verdana and sets the text to bold.

• If you use inline style, you don't need a selector. Shown below is an example of setting the same rule with inline style.

<p style="font-family:verdana; font-weight:bold;">Paragraph Text</p>

Using inline style defeats the purpose of CSS because it applies only to the individual element containing the style attribute. CSS was designed to make it easy to set and modify style for all the elements on an entire webpage, or even an entire web site. Inline style also defeats another purpose of CSS, which is to separate content from presentation.

• I use inline style frequently because it has several advantages. For the specific rules set, it overrides any style rules set at higher levels, and you don't need to go searching around in style code blocks for the rules.

Class Selector

In most cases, you want to set the style for all elements of a certain type, for example you might want to set the background color for all span elements. In that case you would use a class selector. An example of a class selector is shown below.

.bluebkgnd
{
background-color: blue;
}

Note that In the style rule definition, the class selector's name is prefixed with a dot. This rule sets the background color of every element with the class attribute bluebkgnd to blue. After defining the class selector, you go through your html code and apply that class to each span that belongs to the bluebkgnd class as shown below.

<span class="bluebkgnd">Span Text</span>



RSS Feed RSS Feed

Web Design Sections

CSS3: Visual QuickStart Guide (5th Edition)

With this book, readers can start with a tour of the stylesheet language, or skip ahead to any chapter of the book to look up specific tasks covering just what they need to know. This task-based, visual reference guide uses step-by-step instructions, and plenty of screenshots to teach beginning and intermediate users CSS.

Reader David Diez of Boston, MA says, "This book's strategy seems to be show an example, give a general explanation, provide a few key but brief tips, move on. The writing is clear and concise. ... I continue to be very pleased and impressed with the book. It's proving to be a helpful reference and everything in it is highly accessible. Click here for more information.


[Site User Agreement] [Advertise on This site] [Search This Site] [Contact Form]
Copyright©2001-2011 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268