CH04: Cascading Style Sheets (CSS) || Website Devlopment || Computer - 10th || By Pratap Sanjay Sir

Cascading Style Sheets (CSS)

Websites and CSS

 


Website: -

A website is a collection of web pages & related content that is identified by a common domain name & published on at least one web server.

Types of Websites

⟹Types of website: -
a. Static Website
b. Dynamic Website

  • Static Website:
    • Content: Static websites contain fixed, unchanging content that is manually created and stored in HTML or other markup languages.
    • Interactivity: They are primarily informational and offer limited interactivity with users.
    • Design: The design is consistent and doesn't change unless manually edited. Updates require knowledge of HTML/CSS.
    • Examples: Brochure websites, personal blogs, simple landing pages, and small business websites.

  • Dynamic Website:
    • Content: Dynamic websites generate content on the fly, often pulling information from a database. Content is not fixed but is generated dynamically when a user visits the site.
    • Interactivity: They offer extensive interactivity, including user logins, personalized content, and forms for user input.
    • Design: Content, layout, and design can change based on user interactions or database updates.
    • Examples: Social media platforms, e-commerce sites, content management systems (CMS) like WordPress, and web applications.

DHTML (Dynamic Hypertext Markup Language)

DHTML: DHTML (Dynamic Hypertext Markup Language) is an older technology that was commonly used to create interactive and dynamic web pages.
It is no longer widely used, as modern web development has shifted towards technologies like HTML5, CSS3, and JavaScript.

The key components of DHTML included:

  • HTML (Hypertext Markup Language)
  • CSS (Cascading Style Sheets)
  • JavaScript
  • DOM (Document Object Model)
  • Event Handling
  • AJAX (Asynchronous JavaScript and XML)

Role of each component in DHTML:

  • HTML: Forms the structure and content of a web page. Provides the foundational structure for interactivity.
  • CSS: Controls the presentation and styling of HTML elements. Defines visual appearance, including fonts, colors, spacing, and positioning.
  • JavaScript: Adds interactivity to web pages. Manipulates the DOM dynamically and responds to user actions.
  • DOM: Hierarchical representation of the web page's structure and content, accessible via JavaScript.
  • Event Handling: Enables response to user interactions and events like clicks, mouse movements, and keyboard inputs.
  • AJAX: Fetches data from a server and updates parts of a web page without a full page reload.

Sample Webpage's Code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sample Webpage</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <header>
        <h1>Welcome to My Sample Webpage</h1>
    </header>
    <nav>
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
    <main>
        <section>
            <h2>About Us</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        </section>
        <section>
            <h2>Our Services</h2>
            <ul>
                <li>Service 1</li>
                <li>Service 2</li>
                <li>Service 3</li>
            </ul>
        </section>
    </main>
    <footer>
        <p>&copy; 2023 My Sample Webpage</p>
    </footer>
    <script src="script.js"></script>
</body>
</html>
        

What is CSS (Cascading Style Sheets)

CSS (Cascading Style Sheets) is a style sheet language used for describing the presentation (layout, colors, fonts, etc.) of web documents written in HTML and XML.

Separation of Concerns: CSS separates the presentation layer from the content layer in web development. It allows you to define how your HTML content should look without altering the content itself.

Benefits of CSS:

  • Consistency: CSS provides a consistent way to style multiple web pages within a site, ensuring that they have a uniform appearance.
  • Flexibility: It allows for easy and quick changes to the visual style of a website, making redesigns or updates more efficient.
  • Improved Accessibility: CSS enables you to create accessible designs that can be easily read and navigated by assistive technologies, improving the user experience for all.
  • Faster Page Loading: External CSS files can be cached by browsers, reducing page load times for returning visitors.
  • Responsive Design: CSS facilitates the creation of responsive layouts that adapt to different screen sizes, making websites mobile-friendly.

Adding Stylesheets to a Webpage:

  • External Stylesheets: Link an external CSS file to your HTML document using the <link> element in the <head> section. Example: <link rel="stylesheet" href="styles.css">.
  • Internal Stylesheets: Include CSS styles directly within an HTML document using the <style> element within the <head> section.
  • Inline Styles: Apply CSS styles directly to individual HTML elements using the style attribute.

Class Attribute

Class Attribute Definition: The class attribute is an HTML attribute used to assign one or more class names to an HTML element. It allows you to associate elements with one or more CSS classes defined in a stylesheet or embedded in the HTML document.


Syntax
 <element.....class ="Name-of-Class-Here">
        

Eg: -
To Specify Some classes of above example

 <a href="Gandhi.html" class="festival">Mahatma Gandhi</a>
 <a href="Mandela.html" class="leader">Nelson Mandela</a>
 <a href="Einstein.html" class="scientist">Albert Einstein</a>
        

Class Attribute Declaration: The declaration of a class attribute involves specifying the class name(s) for an HTML element. It is done directly within the HTML element's opening tag using the class attribute.


Syntax
Element-Class-Name-Here {property:value;}

To create a basic HTML file (respo.html) that links to an external CSS file, An example code:

HTML File (respo.html):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Responsive Webpage cbseonline.tech</title>
   <!-- Link to your external CSS file -->
    <link rel="stylesheet" href="styles.css">
</head>

<body>
    <div class="container">
        </h1>Welcome to My Responsive Webpage!</h1>
        <p>This is a sample content.</p>
    </div>
</body>
</html>


CSS File (styles.css): css Copy code:


.container { width: 80%;
  			 margin: 0 auto;
   			 padding: 20px;
    		 background-color: #f0f0f0;
   			 text-align: center;
           }

@media (max-width: 768px) {
        .container {
        width: 90%;
        font-size: 18px;
   	 }
}

@media (max-width: 480px) {
     .container {
        width: 95%;
        font-size: 16px;
	 }
}

Identification and Grouping of Elements: -

  • Universal Selector
  • Colors and Background
  • Properties Related to fonts
  • Poperties Related to text
  • Poperties Related to Margins and Padding
  • Poperties Related to Boarders
    • Color and Background

      ⟹Here are some CSS properties related to color and background:

  1. Color
  2. Background-Color
  3. Background-Image
  4. Background-Repeat

Color:

CSS allows you to specify text color using the color property. You can use named colors, hexadecimal color codes, RGB values, or HSL values.
Example:

css code
p {color: red; Set text color to red}

Background-Color:

CSS background-color property sets the background color of an element. It can be applied to various HTML elements. Example:

css code
div {background-color: #f0f0f0; Set background color to light gray}

Background-Image:

background-image property allows you to set an image as the background of an element. You can specify the path to the image using url(). Example:

css code
body {background-image: url('background-image.jpg');Set background image 
    background-size: cover; Scale image to cover the entire element}

Background-Repeat:

background-repeat property controls how the background image is repeated. Common values are repeat, repeat-x, repeat-y, and no-repeat. Example:

css code
section {background-image: url('pattern.png');
    background-repeat: repeat-x; Repeat horizontally}

Properties Related to Fonts

  1. Font-Family
  2. Font-Size
  3. Font-Weight
  4. Font-Style
  5. Font-variant
  6. Font-Height
  7. Font-Align
  8. Font-Decoration
  9. Font-Family

    Specifies the typeface or font family for text.
    You can specify multiple font families as a fallback in case the preferred font is not available. Example:
    css code
    p {font-family: Arial, Helvetica, sans-serif;}
    

    Font-Size

    Sets the size of the font.
    You can use various units like pixels (px), ems (em), percentages (%), or keywords (small, medium, large, etc.). Example:
    css code
    h1 { font-size: 24px;}
    

    Font-Weight

    Controls the thickness or boldness of the font.
    Values can be numeric (100 to 900) or keywords (normal, bold, bolder, lighter). Example:
    css code
    strong { font-weight: bold;}
    

    Font-Style

    Sets the style of the font, such as italic or normal.
    Values can be normal, italic, or oblique. Example:
    css code
    em {font-style: italic;}
    

    Font-Variant

    Controls text transformation, like making text lowercase or small caps.
    Values can be normal or small-caps. Example:
    css code
    p {font-variant: small-caps;}
    

    Font-Height

    Specifies the height of each line of text.
    You can use unit values or keywords. Example:
    css code
    p {line-height: 1.5;  150% of the font size}
    

    Font-Align

    Aligns the text within its containing element.
    Values can be left, right, center, or justify. Example:
    css code
    div { text-align: center;}
    

    Font-Decoration

    Adds decorations to text, such as underlines, overlines, or strikethroughs. Values can be none, underline, overline, line-through, or a combination. Example:
    css code
    a {text-decoration: underline;}
    

    Word-Spacing

    The word-spacing property in CSS is used to control the amount of space between words within a block of text.
    css code
    p {word-spacing: 4px;  Add 4 pixels of space between words}
    

    Latter-Spacing

    The letter-spacing property in CSS is used to control the amount of space between individual characters (letters) within a block of text.
    css code
    p {letter-spacing: 2px; Add 2 pixels of space between letters}
    h1 {letter-spacing: 7px; Add 7 pixels of space between letters}
    

    Text- Transform

    The text-transform property in CSS is used to control the capitalization and transformation of text in an element.
    It allows you to change the appearance of text by converting it to uppercase, lowercase, or capitalize the first letter of each word.
    css code
    p {text-transform: none; This is the default value of the text.}
    h1 {text-transform: uppercase;   Converts all the text to uppercase.}
    a {text-transform: lowercase; Converts all the text to lowercase.}
    .title {text-transform: capitalize;  Capitalizes the first letter of each word.}
    

    Properties Related to Margins and Padding

    1. Margins
    2. Padding

    Margins: -

    1. Margin Property: Margin Property: You can use the margin property to set margins for all sides of an element simultaneously.
      For example:
    2. div {
          margin: 10px; Applies a 10px margin to all sides of the div}
    3. Margin-Top, Margin-Right, Margin-Bottom, Margin-Left:You can set margins for individual sides using margin-top, margin-right, margin-bottom, and margin-left.
      For example:
    4. div {
          margin-top: 10px;
          margin-right: 20px;
          margin-bottom: 10px;
          margin-left: 20px;
      }
    5. Margin Values:You can specify margins using different units such as pixels (px), ems (em), percentages (%), or other length units.
    6. div {
          margin: 10px 20px 10px 20px;  Top, Right, Bottom, Left margins 
      }

    Padding: -

    Padding in CSS is the space between the content of an element and its border.
    It creates space inside an element and separates the content from the border.

    Padding-Top, Padding-Right, Padding-Bottom, Padding-Left: You can set padding for individual sides using padding-top, padding-right, padding-bottom, and padding-left.
    For example:

    div {
        padding: 10px; Applies a 10px padding to all sides of the div
    }
    div {
        padding-top: 10px;
        padding-right: 20px;
        padding-bottom: 10px;
        padding-left: 20px;
    }
    div {
        padding: 10px 20px 10px 20px; Top, Right, Bottom, Left padding 
    }
    

    Properties Related to Borders-

    Borders in CSS can be customized using several properties to control their appearance, style, and width.

    1. border:border: This property combines the border-width, border-style, and border-color properties into one declaration.
    2. div {
          border: 2px solid #333;  Width, style, and color of the border
      }
    3. border-width:Specifies the width of the border.
    4. div {
          border-width: 3px;  Sets the width of the border to 3px
      }
    5. border-style:Defines the style of the border, such as solid, dashed, dotted, etc.
    6. div {
          border-style: dashed;  Sets a dashed border style
      }
    7. border-color:Sets the color of the border.
    8. div {
          border-color: #FF0000; Sets the border color to red 
      }
    9. border-radius:Creates rounded corners for an element's border.
    10. div {
          border-radius: 10px;  Rounds the corners with a 10px radius 
      }
    11. border-top, border-right, border-bottom, border-left:These properties allow you to define border styles, widths, and colors for individual sides of an element.
    12. div {
          border-top: 2px dotted #333; /* Top border with custom style and color */
          border-right: 1px solid #555; /* Right border with custom style and color */
          border-bottom: 3px double #777; /* Bottom border with custom style and color */
          border-left: 2px dashed #999; /* Left border with custom style and color */
      }
    13. border-image:This property allows you to use an image as a border.
    14. div {
          border-image: url(border-image.png) 30 30 round; /* Border image with specific properties */
      }

      The End
      Thank You SO Much