AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

CSS class selector


<< Previous Page
CSS tutorial
Next Page >>
CSS tutorial

CSS Tutorial » CSS class selector

What is a CSS class?

A CSS .class is an attribute used to define a group of HTML elements to apply a unique style and formatting to those CSS elements.

The .class CSS selector selects elements with a specific class attribute.

To select items with a specific class, type a period (.), Followed by the class name.

Internal CSS and HTML Syntax:

<style>
.class_name {
property: value;
}
</style>
Note: use external CSS instead.

In this chapter we learn:
What is a CSS class?
Why do we use class in CSS?
What is CSS class and ID?

Browser Support CSS class selector

Element chrome browser
 Chrome
ie browser
 IE
firefox browser
 Firefox
opera browser
 Opera
safari browser
 Safari
Browser Support option Yes Yes Yes Yes Yes

 

CSS class selector

Use a class when you want to constantly style multiple items across the webpage. Classes are useful when you have more than one item that shares the same style.

Example (this is HTML - PHP editor, change text, values on this window)

<!DOCTYPE html>
<html>
<head>
<style>
p.paragraph {
text-align: right;
color: green;
}

p.large_paragraph {
font-size: 250%;
}
</style>
</head>
<body>

<h1>Example of the .class selector</h1>

<h1 class="paragraph">This h1 title not affected</h1>
<p class="paragraph">This paragraph will be green and right aligned.</p>
<p class="paragraph large_paragraph">This paragraph will be green,<br />
right aligned, <br />
and with large font-size 250%.</p>

</body>
</html>

Related subjects:
difference between class and id CSS table border

Tags: css class selector, vs id, inside class, starts with, inheritance, and id, hover, name convention, contains, inherit from another class

 

How can I use one class inside another class in CSS?

To nestle classes or any other selector in CSS, very simple just separate the selector with spaces as: .parent .child { /* CSS Properties */ }

Example (this is HTML - PHP editor, change text on this window)

<!DOCTYPE html>
<html>
<head>
<style>
.green-text {
color: green;
font-weight: bold;
}

.green-text span {
color: red;
}
</style>
</head>
<body>

<h1 class="green-text">
This is my nice title <span>for the next paragraph</span> header.
</h1>

</body>
</html>

TAGS: What is a CSS class?, Why do we use class in CSS?, What is CSS class and ID?

 

How to Use a CSS Class

The examples below will help you understand in a fairly simple way how to use css class inside class.

Example (this is HTML - PHP editor, change text on this window)

<!DOCTYPE html>
<html>
<head>
<style>
.red-text {
color: #F00;
}
.font-28{
font-size: 28px;
}
</style>
</head>
<body>

<p class="red-text font-28">This is an example of a sentence with font-size: 28px</p>
<p class="red-text">This is an example of a sentence with normal font size</p>

</body>
</html>

 



css class selector, vs id, inside class, starts with, inheritance, and id, hover, name convention, contains, inherit from another class
CSS class selector - css tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


CSS Scrollbar Horizontal
CSS Scrollbar in Div
CSS Scrollbar Firefox
CSS Style Scrollbar
CSS Style Text
CSS background color
CSS Div Id Class
CSS Text Wrap
CSS text-align
CSS Text Decoration
CSS Text Shadow
CSS Text Color
CSS Text Bold
CSS Text Size
CSS background image full
CSS background opacity
CSS border radius
CSS rounded corners
CSS font color
CSS Class & ID
CSS align image center
CSS align content
CSS link color
CSS Text Style
CSS Text Font Size
CSS max width &height
CSS width and height
CSS Margin
CSS Padding
CSS Border Style
CSS background
CSS in HTML
Basic Syntax of CSS
CSS Introduction
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Upload Image, display, edit and delete i...
Login Form with Image background...
How to Create an Image with Transparent ...
Portfolio Gallery Website with filtering...
Simple pagination script PHP MySQLi...
Center Image in div...
Image Hover Overlay Fade...
Sticky image / element / div on scroll...
Responsive images...
Create rounded image in HTML CSS...
Add border around image...
Position Text Over an Image HTML CSS res...
Create a Slideshow Images Gallery...
Create a Sticky Sidebar...
Search bar using CSS HTML...
Shrink Navigation Menu on Scroll...
How to Create Accordion HTML Templates...
Dropdown menu in the navigation bar...
Responsive Top Navigation Bar with mobil...
Split horizontal navigation bar...