Using Stylesheets

Using Stylesheets

Introduction to Stylesheets

  • A stylesheet is a file or a form of code that is used to describe the layout and look of a document written in markup language.
  • Cascading Style Sheets (CSS) is the most commonly-used stylesheet language in web development.
  • CSS is used in conjunction with HTML and JavaScript to build web pages.

Importance of CSS Stylesheets

  • CSS allows web developers to control the presentation of multiple pages all at once.
  • With CSS, you can adjust the layout, colours, fonts, and animations on a website.
  • It can also enable a site to adapt its visual presentation to different devices, such as mobile phones, tablets, or computers.

Implementation of Stylesheets

  • CSS can be included internally in the head of an HTML document or externally as a separate file linked to the HTML document.
  • External stylesheets are more efficient as they can control multiple HTML elements across several pages at once.
  • Internal stylesheets can be used for single, standalone HTML pages.

CSS Syntax

  • CSS syntax consists of a set of rules.
  • These rules have two main parts: a selector, and one or more declarations.
  • The selector is usually the HTML element you want to style.
  • Each declaration includes a CSS property name and a value, separated by a colon.

For example:

body {
   background-color: lightblue;
}

In this CSS code, “body” is the selector and “background-color: lightblue;” is the declaration.

Understanding Selectors

  • CSS selectors are used to select the HTML elements you want to style.
  • Different types of selectors: Element selectors, Id selectors, Class selectors.
  • Element selectors select elements based on the element name.
  • Id selectors select elements based on their id attribute.
  • Class selectors select elements based on their class attribute.

Remember: Proper understanding and usage of CSS stylesheets will allow you to effectively control the visual presentation of your website across multiple platforms.