LINE FEED AND CARRIAGE RETURN

Line Feed and Carriage Return Explained Line Feed and Carriage Return Explained We all know what a line feed is \n and what a carriage return character is \r . But most of us do not know why we have these two different characters to represent a new line. What does each of them really mean? To start with, these are an emulation of how line ending is handled in a traditional typewriter (hey, I actually worked on one of these :)). Line Feed is the act of moving the cursor exactly one row down, staying at the current column. In a typewriter, this is rolling the page one row up without moving the platen horizontally. Carriage Return is the act of moving the cursor to the beginning of the line, staying on the current row. In a typewriter, this is moving the platen to the right horizontally without rolling the page. The above operation, when done in succession, will make the typing head point to the beginning of the next line...

CSS

CSS Selectors 101

CSS Selectors 101

This time I want to give a glimpse of CSS (Cascading Style Sheets). Before I jump into CSS, it's better to know what comprises a web page. Basically, any moderate web page is composed of three technologies:

  • HTML – Content
  • JavaScript – Behavior
  • CSS – Presentation

CSS is simply a presentation technology used in web pages to give a really cool look and feel to the HTML elements (content).

CSS is simply a set of rules which will be combined with an HTML page to govern their appearance.

CSS can be written three different ways:

  1. Inline styles – inlined inside a tag with the style attribute. Example:
  2. <div style="color: red;">This is a red text.</div>

    This limits to a specific element.

  3. Embedded styles – the styles are written inside an HTML page using the <style> tag. This limits to a specific page.
  4. External styles – the styles are written in a separate file and linked to HTML using the <link> tag in the <head> tag. This is the most preferred way of writing styles.

Following is a sample CSS rule:

body {
    background-color: yellow;
    border: 1px solid black;
}

The above style, when applied to an HTML page, gives its body a yellow background with a solid border.

Every CSS rule comprises two things:

  • Selector
  • Declaration

In the above style, body is the selector and the inner statements are called declarations. The selector basically selects a group of HTML elements and declarations are the actual rules that are applied to the selected elements.

So the heart of CSS is its selectors. There are various ways in which we can select HTML elements:

1. Normal Selectors

This is the simplest CSS selector:

p {
    color: blue;
}

2. Selector Groupings

In this selector, we specify more than one element, each separated by a comma, to which the declared styles need to be applied:

h1, h2, h3 {
    color: green;
}

3.a. Descendant Selectors

Descendant selectors are declared similar to selector groupings but separated by a space. This means the declared styles apply to element a only when the a tag appears inside (any child of child…) the h1 tag:

h1 a {
    color: red;
}

3.b. Child Selector

Same as descendant selectors but a should be the child of h1 (this is not the case with descendant selectors):

h1 > a {
    color: red;
}

4.a. Adjacent Selector

Here, the a tag should be the adjacent sibling of the h1 tag:

h1 + a {
    color: red;
}

4.b. General Adjacent Selector

Here, the a tag should be the sibling (need not be adjacent) of the h1 tag:

h1 ~ a {
    color: red;
}

5. ID Selector

This selector selects elements whose id is myaddress:

#myaddress {
    color: red;
}

6. Class Selector

This selector selects elements whose class is myaddress:

.myaddress {
    color: red;
}

7. Attribute Selector

Attribute selectors simply select an element based on their attributes:

a[href] {
    color: red;
}

input[type="submit"] {
    background-color: green;
}

[class~="abc"] {
    color: blue;
}

[hreflang|="en"] {
    color: orange;
}

a[href^="http://"] {
    color: purple;
}

a[href$=".pdf"] {
    color: brown;
}

a[href*=".co.in"] {
    color: pink;
}

9. Pseudo-Class Selector

These selectors are applied only to some set of HTML tags. They are dependent on the behavior of the element. In the example below, when an a tag is visited (clicked), its color will be changed to red. There are some predefined pseudo-classes:

a:link {
    color: blue;
}

a:visited {
    color: red;
}

a:focus {
    color: green;
}

a:hover {
    color: orange;
}

a:active {
    color: purple;
}

9. Pseudo-Element Selector

These selectors are applied to decorate a specified tag. In the example below, a p tag will have its first letter background in blue color. There are some predefined pseudo-elements:

p::first-letter {
    background-color: blue;
}

p::first-line {
    color: red;
}

p::before {
    content: "Prefix - ";
}

p::after {
    content: " - Suffix";
}

10. Universal Selector

This selector applies to all the elements in the document:

* {
    color: black;
}

This is a brief roundup of CSS selectors.

References:

Comments

Popular posts from this blog

LINE FEED AND CARRIAGE RETURN

GIT COMMANDS