New Contrast Pro UI Kit and template with 5 admin dashboards, 23 pages and 10000+ components for $49 ($50 off)🎉
postImage

CSS Syntax and Selector

blogImage

By Emmanuel Chinonso

Web Developer

CSS Syntax and Selector

There are some rules that guild writing code for CSS style. These rules help the browser to interpret the code and apply it to the appropriate HTML element. The CSS rule is made of three parts which include

Contrast Bootstrap UI Kit

Selector: a selector shows the HTML element you wish to style. This could be any tag like <p> or even a class name.

Property: this is like a HTML attribute. It simply that all HTML attributes are converted to CSS properties. Example color, border, height, weight etc.

Value: these are assigned to the properties example color: blue

CSS Code:

p {
color: blue;
height: 12px
}

The p is the selector in CSS. It is followed by curly braces. In side the curly braces are known as the declaration box which contains CSS property, in this case is the color and height and their values which in this case is blue and 12px.

CSS Selector

A CSS selector selects the HTML element(s) you want to style. These selectors are divided into five categories Simple selectors (select elements based on name, id, class) Combinator selectors (select elements based on a specific relationship between them) Pseudo-class selector (select elements based on a certain state) Pseudo-elements selectors (select and style a part of an element) Attribute selector (select elements based on an attribute value)

Element selector

These selects elements based on the element name. when an element is selected and a style is given to it all the content of that element takes the style on the webpage.

CSS Code:

p {
background-color: red;
text-align: center
}

CSS ID Selector

An id is unique in itself. The id selector is used to select this id within the webpage. No two elements can have the same id. To select a specific id, write the harsh tag character(#), followed by the id of the element.

CSS Code:

#wrapper {
text-align: center:
color: grey;
}

CSS Class Selector

The CSS class selector works in the same way as the id selector but with slight difference. An ID is unique to the element whereas a class can be common to multiple elements. To select a element with specific class, write a period character(.), followed by the class name.

CSS Code:

.center {
margin: 0px
padding:2px;
}

CSS Universal selector

The universal selector is just as it is called. It selects all the element in the webpage. It has the star sign (*) as its symbol

CSS Code:

*{
margin: 0px;
padding: 0px;
}

CSS Grouping selector

It is usually used when the same CSS styling is applied to different elements. It helps to increase efficiency and save time.

CSS Code:

p, h3, div {
color: green;
}

Contrast Bootstrap UI Kit

Create Stunning websites and web apps

Building different custom components in react for your web apps or websites can get very stressful. Thats why we decided to build contrast. We have put together a UI kit with over 10000+ components, 5 admin dashboards and 23 additional different pages template for building almost any type of web app or webpage into a single product called Contrast Pro.Try contrast pro

ad-banner

Contrast React Bootstrap PRO is a Multipurpose pro template, UI kit to build your next landing, admin, SAAS, prelaunch, etc project with a clean, well documented, well crafted template and UI components.Learn more about Contrast Pro

Share Post:

Comments

...