Introduction to CSS

Introduction to CSS:

CSS (Cascading Style Sheets) is a language designed to simplify the process of making web pages presentable.

• It allows you to apply styles to HTML documents by prescribing colors, fonts, spacing, and positioning.

• The main advantages are the separation of content (in HTML) and styling (in CSS) and the same CSS rules can be used across all pages and not have to be rewritten.

• HTML uses tags and CSS uses rule sets.

• CSS styles are applied to the HTML element using selectors.

Need for CSS:

• Saves Time: Write CSS once and reuse it across multiple HTML pages.

• Easy Maintenance: Change the style globally with a single modification.

• Search Engine Friendly: Clean coding technique that improves readability for search engines.

• Superior Styles: Offers a wider array of attributes compared to HTML.

• Offline Browsing: CSS can store web applications locally using offline cache, allowing offline viewing.

CSS Syntax:

CSS consists of style rules that are interpreted by the browser and applied to the corresponding elements. A style rule set includes a selector and a declaration block.

• Selector: Targets specific HTML elements to apply styles.

• Declaration: Combination of a property and its corresponding value.

Example:

// HTML Element

<h1>Hello</h2>

// CSS Style

h1 { 

color: blue; 

font-size: 12px; 

}

Where -

Selector - h1

Declaration - { color: blue; font-size: 12px; } 

• The selector points to the HTML element that 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.

Ways to Apply CSS in HTML:

1. Inline CSS:

Inline CSS allows you to apply styles directly within HTML tags using the style attribute.
Example:
<html>
<head>
</head>
<body>
<p style=”color:Red;”>This is inline CSS.</p>
</body>
</html>

2. Internal CSS:

Internal CSS involves adding CSS styles directly within the HTML file by including them inside the <style> tags.
Example:
<html>
<head>
<style>
P{
Color:Red;
}
</style>
</head>
<body>
<p>This is internal CSS.</p>
</body>
</html>

3. External CSS:

External CSS involves creating a separate CSS file with a .css extension and linking it to the HTML file using the <link> tag.
<html>
<head>
<link rel=”stylesheet” href=”style.css”/>
</head>
<body>
<p>This is external CSS.</p>
</body>
</html>

Style.css:

p{
Color:Red;
}

Comments

Popular posts from this blog

Artificial Intelligence in Education

Puran Poli – The Sweet Soul of Maharashtrian Tradition

Future of AIML Engineering