CSS101: A Beginners Guide To Beauty Style Of Webpage

CSS101: A Beginners Guide To Beauty Style Of Webpage

CSS Introduction

Cascading Style Sheets, fondly referred to as CSS, is a simply designed language intended to simplify the process of making web pages presentable. CSS allows you to apply styles to web pages. More importantly, CSS enables you to do this independent of the HTML that makes up each web page.

WHY CSS?

  • CSS saves time: You can write CSS once and reuse the same sheet in multiple HTML pages.
  • Easy Maintenance: To make a global change simply change the style, and all elements in all the webpages will be updated automatically.
  • Search Engines: CSS is considered a clean coding technique, which means search engines won’t have to struggle to “read” its content.
  • Superior styles to HTML: CSS has a much wider array of attributes than HTML, so you can give a far better look to your HTML page in comparison to HTML attributes.
  • Offline Browsing: CSS can store web applications locally with the help of an offline cache. Using this we can view offline websites.

CSS Syntax:

A CSS comprises style rules that are interpreted by the browser and then applied to the corresponding elements in your document.

A style rule set consists of a selector and declaration block.

Selector -- h1Declaration -- {color:blue;font size:12px;} 
  • The selector points to the HTML element you want to style.
  • The declaration block contains one or more declarations separated by semicolons.
  • Each declaration includes a CSS property name and a value, separated by a colon.
  • For Example:
  • –; color is property and blue is value.
  • –; font-size is property and 12px is value.
  • A CSS declaration always ends with a semicolon, and declaration blocks are surrounded by curly braces.

READ ALSO » JS101: A Beginners Guide To Javascript

Example :

In the following example all p elements will be center-aligned, with a blue text color:

p { color: blue; text-align: center; }

CSS Selectors

CSS selectors are used to “find” (or select) HTML elements based on their element name, id, class, attribute, and more.

1.THE UNIVERSAL SELECTORS: Rather than selecting elements of a specific type, the universal selector quite simply matches the name of any element type

* { color: pink; }

2.THE ELEMENT SELECTOR: The element selector selects elements based on the element name. You can select all p elements on a page like this (in this case, all p elements will be center-aligned, with a red text color) :

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

3. THE DESCENDANT SELECTOR: Suppose you want to apply a style rule to a particular element only when it lies inside a particular element. As given in the following example, the style rule will apply to the em element only when it lies inside the ul tag.

ul em { color: #000000; }

READ ALSO » HTML101: A Beginners Guide To Code

4. THE ID SELECTOR :

  • The id selector uses the id attribute of an HTML element to select a specific element.
  • The id of an element should be unique within a page, so the id selector is used to select one unique element!
  • To select an element with a specific id, write a hash (#) character, followed by the id of the element.
  • The style rule below will be applied to the HTML element with id=”para1?:
#p { text-align: center; color: red; }

5. THE CLASS SELECTORS :

  • The class selector selects elements with a specific class attribute.
  • To select elements with a specific class, write a period (.) character, followed by the name of the class.
  • In the example below, all HTML elements with class=”center” will be red and center-aligned:
.p { text-align: center; color: red; }

6. GROUPING SELECTORS

If you have elements with the same style definitions, like this:

h1 { text-align: center; color: blue; } h2 { text-align: center; color: blue; } p { text-align: center; color: blue; }

Play with the code on our editor, if you have any question don't hesitant to contact us, it's you boy optimist..