Computer Science PDF

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Computer science

 CSS, which stands for Cascading Style Sheets, is a stylesheet language


used to describe the presentation of a document written in HTML or
XML. CSS defines how elements should be displayed on the screen, on
paper, in speech, or on other media. It enables the separation of
content (HTML or XML) from design, allowing for more flexible and
maintainable web pages.

 There are three main types of CSS: inline, internal (or embedded), and
external. Each type has its use cases and advantages:

 1. Inline CSS:
 - **Definition**: Inline CSS involves applying styles directly to HTML
elements using the `style` attribute.
 - **Example**: `<p style="color: blue; font-size: 14px;">This is a
paragraph.</p>`
 - **Advantages**:
 - Quick to apply and useful for single-use styles.
 - Does not require an additional file or section in the HTML
document.
 - **Disadvantages**:
 - Hard to maintain and scale, as styles are mixed with content.
 - Leads to repetitive code if the same style is needed on multiple
elements.

 2. **Internal CSS**:
 - **Definition**: Internal CSS is defined within the `<style>` tag inside
the `<head>` section of an HTML document.
 - **Example**:
 ```html
 <head>
 <style>
 p{
 color: blue;
 font-size: 14px;
 }
 </style>
 </head>
 <body>
 <p>This is a paragraph.</p>
 </body>
 ```
 - **Advantages**:
 - Styles are centralized in one section of the document, making it
easier to manage compared to inline CSS.
 - Useful for styling a single document.
 - **Disadvantages**:
 - Styles are still confined to a single HTML document, making it less
reusable across multiple pages.

 3. **External CSS**:

2
 - **Definition**: External CSS involves linking to an external CSS file
using the `<link>` tag within the `<head>` section of the HTML
document.
 - **Example**:
 ```html
 <head>
 <link rel="stylesheet" type="text/css" href="styles.css">
 </head>
 <body>
 <p>This is a paragraph.</p>
 </body>
 ```
 With `styles.css` containing:
 ```css
 p{
 color: blue;
 font-size: 14px;
 }
 ```
 - **Advantages**:
 - Allows for separation of content and presentation.
 - CSS can be reused across multiple HTML documents, promoting
consistency and easier maintenance.
 - Reduces page load time once the CSS file is cached by the browser.
 - **Disadvantages**:

3
 - Requires an additional HTTP request to fetch the CSS file, which can
slightly impact initial page load time.
 - Changes in the CSS file will affect all linked documents, which may
require careful testing.

Using CSS effectively often involves combining these types based on the
needs of the project. For instance, external CSS is commonly used for
general styling, internal CSS might be used for page-specific overrides, and
inline CSS could be applied for unique or one-off styles.

You might also like