start learning
Image 1
2988

CSS Scalable stylesheets

CSS Scalable Stylesheets (CSSS) is an approach that allows for the creation of responsive and scalable stylesheets. It provides a way to define styles that adapt to different screen sizes, making it easier to build responsive web designs.

The main idea behind CSSS is to use relative units, such as percentages or ems, instead of fixed units like pixels, to define the size and positioning of elements. This allows the styles to scale and adapt based on the viewport or container size.

Here's examples of using CSSS in HTML and CSS to create a responsive layout :


Fluid Layout


/* Define styles for the tutorial container */
.tutorialcontainer {
  width: 80%; /* Set the width to 80% of the parent container */
  margin: 0 auto; /* Center the container horizontally */
}

/* Define styles for the tutorial box */
.tutorialbox {
  width: 50%; /* Set the width to 50% of the parent container */
  height: 200px; /* Set the height to 200 pixels */
  background-color: red; /* Set the background color to red */
}

<div class="tutorialcontainer">
  <div class="tutorialbox"></div>
</div>

In this example, the .tutorialcontainer class sets the width to 80% of its parent container and centers it using margin: 0 auto;. The .box class has a width of 50% relative to the .container, creating a fluid layout that adjusts dynamically based on the container's width.

Preview:

Responsive Typography


/* Define styles for the tutorial heading */
.tutorialheading {
  font-size: 3em; /* Set the font size to 3em */
  line-height: 1.2; /* Set the line height to 1.2 */
}

<p class="tutorialheading">Welcome</p>

Here, the .tutorialheading class sets the font size to 3em, which is relative to the parent element's font size. This allows the heading to scale proportionally based on the font size of the parent or viewport.

Preview :

Welcome


Media Queries


/* Define styles for the tutorial container */
.tutorialcontainer {
  width: 80%; /* Set the width to 80% of the parent container */
  margin: 0 auto; /* Center the container horizontally */
}

/* Define styles for the tutorial title */
.tutorialtitle {
  font-size: 2em; /* Set the font size to 2em */
  text-align: center; /* Center-align the text */
}

/* Define styles for the tutorial box */
.tutorialbox {
  width: 50%; /* Set the width to 50% of the parent container */
  height: 200px; /* Set the height to 200 pixels */
  background-color: red; /* Set the background color to red */
}

/* Media query for screens with a maximum width of 768px */
@media (max-width: 768px) {
  .tutorialbox {
    width: 100%; /* Set the width to 100% on screens with a maximum width of 768px */
  }
}

<div class="tutorialcontainer">
  <p class="tutorialtitle">Responsive Box</p>
  <div class="tutorialbox"></div>
</div>

In this example, the .box class has a width of 50% by default. However, using a media query with (max-width: 768px), the width is changed to 100% when the viewport width is 768 pixels or less. This allows the box to occupy the full width on smaller screens.

Preview:

Responsive Box


Responsive Navigation Bar optimazed for mobile


/* Define styles for the tutorial navigation bar */
.tutorialnavbar {
  background-color: #333; /* Set the background color to #333 */
}

/* Define styles for the navigation list */
.tutorialnav-list {
  display: flex; /* Use flex display to arrange items */
  justify-content: space-around; /* Space items evenly along the main axis */
  padding: 0; /* Remove padding */
  margin: 0; /* Remove margin */
}

/* Define styles for list items */
.tutorialnav-list li {
  list-style: none; /* Remove list-style bullets */
}

/* Define styles for navigation links */
.tutorialnav-list li a {
  color: white; /* Set the text color to white */
  padding: 10px; /* Add padding of 10px to the links */
  text-decoration: none; /* Remove text decoration */
}

/* Media query for screens with a maximum width of 768px */
@media (max-width: 768px){
  .tutorialnav-list {
    flex-direction: column; /* Change the flex direction to column */
    align-items: center; /* Center-align items along the main axis */
  }
  .tutorialnav-list li {
    margin-bottom: 10px; /* Add margin to separate list items */
  }
}

<nav class="tutorialnavbar">
  <ul class="tutorialnav-list">
    <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>

In this example, the navigation bar has a fluid layout by using relative units for padding and margins. The .nav-list is displayed as a flex container with evenly spaced navigation items. When the viewport width is 768 pixels or less, a media query adjusts the layout to a vertical list using flex-direction: column and centers the items using align-items: center.

Preview:


Scalable Grid System


/* Define styles for the tutorial grid container */
.tutorialgrid-container {
  display: grid; /* Use grid display */
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* Create grid columns with a minimum of 200px and maximum 1fr */
  gap: 20px; /* Add a gap of 20px between grid items */
}

/* Define styles for grid items */
.tutorialgrid-item {
  background-color: #f0f0f0; /* Set background color to #f0f0f0 */
  padding: 20px; /* Add padding of 20px to grid items */
}

<div class="tutorialgrid-container">
  <div class="tutorialgrid-item">Item 1</div>
  <div class="tutorialgrid-item">Item 2</div>
  <div class="tutorialgrid-item">Item 3</div>
  <div class="tutorialgrid-item">Item 4</div>
</div>

In this example, a grid layout is created using the CSS Grid module. The .grid-container class uses grid-template-columns with repeat(auto-fit, minmax(200px, 1fr)) to create a grid that automatically adjusts the number of columns based on the available space, with a minimum column width of 200 pixels. The gap property adds spacing between the grid items. The .grid-item class represents individual items within the grid and has a light gray background color.

Preview:
Item 1
Item 2
Item 3
Item 4

These examples demonstrate how CSS can be used to create responsive navigation bars and scalable grid systems that adapt to different screen sizes. By utilizing relative units, media queries, and flexible layout techniques, you can build web designs that are responsive and adapt to various devices.


Resources for Further Learning

Explore the possibilities and create unique effects on your web pages by using the interactive code editor

HTML

Write and customize HTML code

CSS

Add style and design to your web pages with CSS

JavaScript

Enhance interactivity with JavaScript code

Go to Code Editor