on air

Group CSS Selectors & Declarations.

back home » Web Tutorials » CSS » Group CSS Selectors & Declarations.


Scenario.

Now you'll learn how to group CSS Selectors and Declarations, for simplicity and effective and results.

Grouping Selectors.

Learn how to define declaration in stylesheet for multiple selectors and vice versa, simply by grouping them.

CSS allows grouping of selectors or declarations. This makes it possible to define formats for different HTML Elements at a time. For Example, you'd like to define solid black borders for TABLEs, THs, and TDs in a document. All you'll need to do is, simply separating the Selectors you'll use with commas, and then define a declaration to take effect on them all.

See the illustration below.

The Rule.

Selector1, Selector2, Selector3 {Declaration;}

The Short Method.

This method is recommended because it's very simple to read, easy to troubleshoot, less capacity, will load faster, and will produce the same result as the long method.

table, th, td {
border:#000 solid 1px;
}

The Long Method.

This method will produce the same result as the short method, but will affect the loading time of your content if used for a large website. It will also be difficult to troubleshoot, because you'll then need to edit Declarations one by one if there should be any trouble, which will be again, time consuming.

table{
border:#000 solid 1px;
}
th{
border:#000 solid 1px;
}
td{
border:#000 solid 1px;
}

Grouping Of Declaration.

CSS allows also grouping of declarations. This makes it again possible to create for a single, or a group of selectors, one or more declarations to format HTML Elements in a document.

To group declarations, you'll simply add another declaration after the semicolon [;] that ends a declaration, and still remaining inside the opening and closing curly braces. You may add a line break after every semicolon. This procedure can be repeated, adding more declarations as desired.

See Ilustration below.

The Rule.

Selector {
Declaration1; 
Declaration2; 
Declaration3;
}

Multiple Declarations Single Selector.

Taking a keen look at the illustration below. You could see that, the Selector [h1] will be formatted with all the three declarations.

This means if [h1] is used in an HTML document pointing to this stylesheet. That document's [h1] content will be formatted with all three declaration.

h1 {
font-family:Verdana, Arial;
color : #ededed;
text-align: center;
}

Multiple Selectors, Multiple Declarations.

This time in the illustration below the Declarations specified here will format all HTML headings from [h1-h6]

However, let's say, you've decided to make only the h3 have a different color and still inherit the rest formats above. You'll simply re-create a new declaration for h3 and give its property a new value. watch illustration below.

h1, h2, h3, h4, h5, h6{
font-family:Verdana, Arial;
color : #ededed;
text-align: center;
}

/*Just re-create h3 as follows*/
h3{
color : #FFD700;
}

How To Override A CSS Declaration Using Class Or ID.

You may already have a declaration specified, for example, using the Selector [p] in your stylesheet, which is suppose to format every <p> element in your HTML document.

To override the existing declaration that rules <p> tags in your document at a portion, you'll need to use the class or id attribute.

Using The class Attribute To Override An Existing Declaration.

You'll simply need to add the attribute class to the <p> tag you want to override its current format in your HTML document like so; <p class="anyname">content</p>.

Afterwards, you'll need to create a CSS class for the Selector [p] in your existing stylesheet.

See illustration below.

p.anyname {font-size:14px; color:#EDEDED;}

Now, whenever the defined class "anyname" is used for any <p> tag in your HTML document, it will then override the existing format for that <p> tag.

Notice that this will affect only the <p> tag that will use the defined class, and the rest will still maintain the original format.

Using The id Attribute To Override An Existing Declaration.

You can also use the attribute id to achieve the same effect. However, the id attribute can be used in a document only once.

So, it will be advisable to use id only if you want to override an HTML element's format completely in a document. For example, to override the background color in a document, you'll just need to add the id attribute into the <body> tag like so;

<body id="anyname">content</body>.

Afterwards, you'll define an id using the Selector [#anyname] inside your existing stylesheet.

See illustration below.

#anyname {background-color: #000;}

CSS Selectors Tutorial Video.

Clicks4UrMind

Man will give you worldly powers, and make you feel on top of all, note this is temporally and could be redrawn at anytime sending you back to the ground floor of life. However, the Lord Almighty, the one and the only rightful ruler of the Universe, blesses everlastingly.

Brain

Knowledge is Power, but Power is not Knowledge. Wisdom is the truthful Power that identifies the Knowledge within the man. And only, I repeat 3x. Only the almighty God has the power to bless the man with his Wisdom forever.

To achieve the Lord's blessings, cease not praying daily, asking for his Wisdom, and you'll be blessed abundantly...

 

SPYERA PHONE

Spyera Phone

Spyera Phone version is software that you install on a smart phone to monitor everything happening on the phone. After installation, SPYERA secretly records events (sms, call history, phone book, location, emails, What's App messages, IM, Facebook Chat, Skype, See photos taken and many more...) that happen on the phone and delivers these information to a web account, where you can view these reports 24/7 from any Internet enabled computer or mobile phone. SPYERA also allows you to listen to the surroundings of the target mobile , listen to the phone conversation and to know the location of the device.


Please, Kindly Donate What You Can, Enabling Us Pay Hosting And Domain Costing, And Do More.

Please Donate